إضفاء نمط على مضلّع حدودي
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
اختيار النظام الأساسي:
Android
iOS
JavaScript
لتصميم التعبئة والحدود لمضلّع حدود، استخدِم إغلاق تصميم يقبل GMSPlaceFeature
ويعرض GMSFeatureStyle
لتحديد سمات التصميم. بعد ذلك، اضبط السمة style على دالة إغلاق خاصة بتحديد الأنماط، تحتوي على منطق تحديد الأنماط.
Swift
let mapView = GMSMapView(frame: .zero, mapID: GMSMapID(identifier: "YOUR_MAP_ID"), camera: GMSCameraPosition(latitude: 20.773, longitude: -156.01, zoom: 12))
let layer = mapView.featureLayer(of: .locality)
// Define a style with purple
let style = FeatureStyle(fill: .purple.withAlphaComponent(0.5), stroke: .purple, strokeWidth: 3.0)
// Apply the style to a single boundary.
layer.style = { ($0.placeID == "ChIJ0zQtYiWsVHkRk8lRoB1RNPo"/* Hana, HI */) ? style : nil }
Objective-C
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero mapID:[GMSMapID mapIDWithIdentifier:@"MAP_ID"] camera:[GMSCameraPosition cameraWithLatitude: 20.773 longitude: -156.01 zoom:12]];
GMSFeatureLayer<GMSPlaceFeature *> *layer = [mapView featureLayerOfFeatureType:GMSFeatureTypeLocality];
// Define a style with purple fill and border.
GMSFeatureStyle *style = [GMSFeatureStyle styleWithFillColor:[[UIColor purpleColor] colorWithAlphaComponent:0.5] strokeColor:[UIColor purpleColor] strokeWidth:3.0];
// Apply the style to a single boundary.
layer.style = ^(GMSPlaceFeature *feature) {
return [feature.placeID isEqual:@"ChIJ0zQtYiWsVHkRk8lRoB1RNPo"/* Hana, HI */] ? style : nil;
};
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThis documentation explains how to style the fill and stroke of boundary polygons using a styling closure that takes a \u003ccode\u003eGMSPlaceFeature\u003c/code\u003e and returns a \u003ccode\u003eGMSFeatureStyle\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe styling closure defines the style attributes for the polygon, such as fill color, stroke color, and stroke width.\u003c/p\u003e\n"],["\u003cp\u003eStyling Places data might require integrating the Places SDK for iOS, although it's not always mandatory.\u003c/p\u003e\n"],["\u003cp\u003eCode examples in Swift and Objective-C demonstrate how to apply a purple style to a specific boundary polygon using its place ID.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/maps/documentation/android-sdk/dds-boundaries/style-polygon \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/dds-boundaries/style-polygon \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/dds-boundaries/style-polygon \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nTo style the fill and stroke for a boundary polygon, use a styling closure that\naccepts a [`GMSPlaceFeature`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSPlaceFeature) and returns a\n[`GMSFeatureStyle`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSFeatureStyle) to define style attributes. Then set the\nstyle property to a styling closure, which contains styling logic.\n\n**Important:** While not required for all capabilities, styling of Places data may require integration with the [Places SDK for iOS](/maps/documentation/places/ios-sdk). \n\nSwift \n\n```swift\nlet mapView = GMSMapView(frame: .zero, mapID: GMSMapID(identifier: \"YOUR_MAP_ID\"), camera: GMSCameraPosition(latitude: 20.773, longitude: -156.01, zoom: 12))\n\nlet layer = mapView.featureLayer(of: .locality)\n\n// Define a style with purple\nlet style = FeatureStyle(fill: .purple.withAlphaComponent(0.5), stroke: .purple, strokeWidth: 3.0)\n\n// Apply the style to a single boundary.\nlayer.style = { ($0.placeID == \"ChIJ0zQtYiWsVHkRk8lRoB1RNPo\"/* Hana, HI */) ? style : nil }\n```\n\nObjective-C \n\n```objective-c\nGMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero mapID:[GMSMapID mapIDWithIdentifier:@\"MAP_ID\"] camera:[GMSCameraPosition cameraWithLatitude: 20.773 longitude: -156.01 zoom:12]];\n\nGMSFeatureLayer\u003cGMSPlaceFeature *\u003e *layer = [mapView featureLayerOfFeatureType:GMSFeatureTypeLocality];\n\n// Define a style with purple fill and border.\nGMSFeatureStyle *style = [GMSFeatureStyle styleWithFillColor:[[UIColor purpleColor] colorWithAlphaComponent:0.5] strokeColor:[UIColor purpleColor] strokeWidth:3.0];\n\n// Apply the style to a single boundary.\nlayer.style = ^(GMSPlaceFeature *feature) {\n return [feature.placeID isEqual:@\"ChIJ0zQtYiWsVHkRk8lRoB1RNPo\"/* Hana, HI */] ? style : nil;\n};\n```"]]