لاستخدام ميزة "تحديد الأنماط المستندة إلى البيانات" للحدود، يجب إنشاء معرّف خريطة. بعد ذلك، عليك إنشاء نمط خريطة جديد واختيار طبقات الميزات الخاصة بالحدود المطلوبة وربط النمط بمعرّف الخريطة.
إنشاء رقم تعريف خريطة
mapID هو معرّف فريد يمثّل نسخة واحدة من "خرائط Google". يمكنك إنشاء معرّفات خرائط وتعديل نمط مرتبط بمعرّف خريطة في أي وقت في Google Cloud Console.
إنشاء نمط خريطة جديد
لإنشاء نمط خريطة جديد، اتّبِع التعليمات الواردة في إدارة أنماط الخرائط لإنشاء النمط. بعد الانتهاء، اربط النمط بمعرّف الخريطة الذي تم إنشاؤه حديثًا.
اختيار طبقات المعالم
في Google Cloud Console، يمكنك اختيار طبقات العناصر التي تريد عرضها. يحدّد هذا الخيار أنواع الحدود التي تظهر على الخريطة (مثل المناطق المحلية والولايات وما إلى ذلك).
انقر على القائمة المنسدلة طبقات الميزات لإضافة طبقات أو إزالتها.
انقر على حفظ لحفظ التغييرات وإتاحتها في خرائطك.
تعديل رمز تهيئة الخريطة
تتطلّب هذه الخطوة ربط رقم تعريف خريطة بنمط يتضمّن طبقة واحدة أو أكثر من طبقات الميزات المفعّلة. للتحقّق من إعداد معرّف الخريطة بشكل صحيح في Cloud Console، راجِع طريقة إعداده ضمن إدارة الخرائط.
Swift
// A map ID using a style with one or more feature layers enabledletmapID=GMSMapID(identifier:"YOUR_MAP_ID")letmapView=GMSMapView(frame:.zero,mapID:mapID,camera:GMSCameraPosition(latitude:40,longitude:-80,zoom:7))
Objective-C
// A map ID using a style with one or more feature layers enabledGMSMapID*mapID=[GMSMapIDmapIDWithIdentifier:@"MAP_ID"];GMSMapView*mapView=[GMSMapViewmapWithFrame:CGRectZeromapID:mapIDcamera:[GMSCameraPositioncameraWithLatitude:40longitude:-80zoom:7]];
إضافة طبقات معالم إلى خريطة
للحصول على مرجع إلى طبقة ميزات على خريطتك، استدعِ الدالة
mapView.featureLayer(of:)
عندما يتم تهيئة الخريطة:
تتطلّب ميزة "تحديد الأنماط المستند إلى البيانات" للحدود إمكانات يتم تفعيلها في Google Cloud Console وربطها بمعرّف خريطة. بما أنّ معرّفات الخرائط قابلة للتغيير، يمكنك طلب mapView.mapCapabilities على GMSMapView للتحقّق مما إذا كانت إمكانية معيّنة (مثل التنسيق المستند إلى البيانات) متاحة قبل طلبها.
يمكنك أيضًا رصد التغييرات في إمكانات الخريطة من خلال الاشتراك في
GMSViewDelegate. يوضّح هذا المثال كيفية استخدام البروتوكول للتحقّق من متطلبات التنسيق المستند إلى البيانات.
Swift
classSampleViewController:UIViewController{privatelazyvarmapView:GMSMapView=GMSMapView(frame:.zero,mapID:GMSMapID(identifier:"YOUR_MAP_ID"),camera:GMSCameraPosition(latitude:40,longitude:-80,zoom:7))overridefuncloadView(){self.view=mapViewmapView.delegate=self}}extensionSampleViewController:GMSMapViewDelegate{funcmapView(_mapView:GMSMapView,didChangemapCapabilities:GMSMapCapabilityFlags){if(!mapCapabilities.contains(.dataDrivenStyling)){// Data-driven styling is *not* available, add a fallback.// Existing feature layers are also unavailable.}}}
Objective-C
@interfaceSampleViewController: UIViewController<GMSMapViewDelegate>
@end@implementationSampleViewController-(void)loadView{GMSMapView*mapView=[GMSMapViewmapWithFrame:CGRectZeromapID:[GMSMapIDmapIDWithIdentifier:@"MAP_ID"]camera:[GMSCameraPositioncameraWithLatitude:40longitude:-80zoom:7]];mapView.delegete=self;self.view=mapView;}-(void)mapView:(GMSMapView*)mapViewdidChangeMapCapabilities:(GMSMapCapabilityFlags)mapCapabilities{if(!(mapCapabilities&GMSMapCapabilityFlagsDataDrivenStyling)){// Data-driven styling is *not* available, add a fallback.// Existing feature layers are also unavailable.}}@end
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eData-driven styling for boundaries requires creating a map ID and associating it with a custom map style that includes selected feature layers.\u003c/p\u003e\n"],["\u003cp\u003eYou can manage feature layers, such as localities and states, in the Google Cloud console to control which boundaries are displayed.\u003c/p\u003e\n"],["\u003cp\u003eUpdate your map initialization code to use the map ID, ensuring data-driven styling is enabled for the map.\u003c/p\u003e\n"],["\u003cp\u003eUtilize \u003ccode\u003emapView.featureLayer(of:)\u003c/code\u003e to access specific feature layers on your map for further styling or interaction.\u003c/p\u003e\n"],["\u003cp\u003eVerify map capabilities, including data-driven styling, using \u003ccode\u003emapView.mapCapabilities\u003c/code\u003e or by subscribing to \u003ccode\u003eGMSViewDelegate\u003c/code\u003e to detect changes and implement fallbacks if needed.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/maps/documentation/android-sdk/dds-boundaries/start \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/dds-boundaries/start \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/dds-boundaries/start \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nTo use data-driven styling for boundaries you must create a map ID. Next, you\nmust create a new map style, select the needed boundary feature layers, and\nassociate the style with your map ID.\n\nCreate a map ID\n\nA [mapID](/maps/documentation/get-map-id) is a unique identifier that represents\na single instance of a Google Map. You can create map IDs and update a style\nassociated with a map ID at any time in the Google Cloud console.\n\nCreate a new map style\n\nTo create a new map style, follow the instructions in [Manage map\nstyles](/maps/documentation/ios-sdk/cloud-customization/map-styles) to create\nthe style. Once complete associate the style with the newly created map ID.\n| **Experimental:** This feature can only be set for light map styles. When you link a light map style that has this feature enabled to a [map\n| ID](../map-ids/mapid-over), the enabled layers are also available for the dark map style.\n\nSelect feature layers\n\nIn the Google Cloud console you can select which feature layers to display. This\ndetermines which kinds of boundaries appear on the map (for example localities,\nstates, and so on).\n| **Important:** For optimal performance, only select the layers you need.\n\nManage feature layers\n\n1. In the Google Cloud console, [go to the Map Styles\n page](https://console.cloud.google.com/project/_/google/maps-apis/studio/styles)\n\n2. Select a project if prompted.\n\n3. Select a map style.\n\n4. Click the **Feature layers** drop-down to add or remove layers.\n\n5. Click **Save** to save your changes and make them available to your maps.\n\nUpdate your map initialization code\n\nThis step requires a map ID be associated with a style with one or more feature\nlayers enabled. To verify your map ID is set up correctly in\nCloud console, review how it is configured under [Maps\nManagement](https://console.cloud.google.com/google/maps-apis/studio/maps). \n\nSwift \n\n```swift\n// A map ID using a style with one or more feature layers enabled\n\nlet mapID = GMSMapID(identifier: \"YOUR_MAP_ID\")\nlet mapView = GMSMapView(frame: .zero, mapID: mapID, camera: GMSCameraPosition(latitude: 40, longitude: -80, zoom: 7))\n```\n\nObjective-C \n\n```objective-c\n// A map ID using a style with one or more feature layers enabled\n\nGMSMapID *mapID = [GMSMapID mapIDWithIdentifier:@\"MAP_ID\"];\nGMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero mapID:mapID camera:[GMSCameraPosition cameraWithLatitude:40 longitude:-80 zoom:7]];\n```\n| **Important:** For testing, you can skip the step of creating and configuring a [map\n| ID](/maps/documentation/get-map-id), by using mapId: [`DEMO_MAP_ID`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapID) in your app code. `DEMO_MAP_ID` is intended for testing purposes only. Don't use `DEMO_MAP_ID` in a production environment.\n\nAdd feature layers to a map\n\nTo get a reference to a feature layer on your map, call\n[`mapView.featureLayer(of:)`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView#-featurelayeroffeaturetype:)\nwhen the map initializes: \n\nSwift \n\n```swift\nlet layer = mapView.featureLayer(of: .locality)\n```\n\nObjective-C \n\n```objective-c\nGMSFeatureLayer *layer = [mapView featureLayerOfFeatureType:GMSFeatureTypeLocality];\n```\n\nCheck map capabilities\n\nData-driven styling for boundaries requires capabilities which are enabled in the\nGoogle Cloud console, and associated with a map ID. Because map IDs are subject to\nchange, you can call\n[`mapView.mapCapabilities`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView#mapcapabilities)\non a [`GMSMapView`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView) to verify whether a certain capability (for\nexample data-driven styling) is available prior to calling it.\n\nYou can also detect changes in map capabilities by subscribing to\n[`GMSViewDelegate`](/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate). This example shows how to use the\nprotocol to check for data-driven styling requirements. \n\nSwift \n\n```swift\nclass SampleViewController: UIViewController {\n\n private lazy var mapView: GMSMapView = GMSMapView(frame: .zero, mapID: GMSMapID(identifier: \"YOUR_MAP_ID\"), camera: GMSCameraPosition(latitude: 40, longitude: -80, zoom: 7))\n\n override func loadView() {\n self.view = mapView\n mapView.delegate = self\n }\n}\n\nextension SampleViewController: GMSMapViewDelegate {\n func mapView(_ mapView: GMSMapView, didChange mapCapabilities: GMSMapCapabilityFlags) {\n if (!mapCapabilities.contains(.dataDrivenStyling)) {\n // Data-driven styling is *not* available, add a fallback.\n // Existing feature layers are also unavailable.\n }\n }\n}\n```\n\nObjective-C \n\n```objective-c\n@interface SampleViewController: UIViewController \u003cGMSMapViewDelegate\u003e\n@end\n\n@implementation SampleViewController\n- (void)loadView {\n GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero mapID:[GMSMapID mapIDWithIdentifier:@\"MAP_ID\"] camera:[GMSCameraPosition cameraWithLatitude:40 longitude:-80 zoom:7]];\n mapView.delegete = self;\n self.view = mapView;\n}\n\n- (void)mapView:(GMSMapView *)mapView didChangeMapCapabilities:(GMSMapCapabilityFlags)mapCapabilities {\n if (!(mapCapabilities & GMSMapCapabilityFlagsDataDrivenStyling)) {\n // Data-driven styling is *not* available, add a fallback.\n // Existing feature layers are also unavailable.\n }\n}\n@end\n```"]]