設定界線多邊形的樣式
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
如要設定界線多邊形的填滿和筆劃樣式,請使用樣式閉包,接受 GMSPlaceFeature
並傳回 GMSFeatureStyle
,藉此定義樣式屬性。然後將樣式屬性設為樣式閉包,其中包含樣式邏輯。
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;
};
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 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```"]]