google 地图中添加了样式功能
Style feature added to google map
我通过解析 GeoJSON 向 GMSMapView 添加了一项功能。然而,我在弄清楚如何设置此功能的样式方面遇到了极大的麻烦。
目前,该功能是默认的蓝色描边和半透明蓝色填充。我想改变这些颜色。我试着查看 the documentation,但毫无帮助。我在互联网上找到的所有其他问题都是关于 JavaScript API.
如何在我的 Google 地图上设置特定要素的样式——仅 GeoJSON 文件中的要素?最好是动态的,但不必如此。
这让我猜测了很多,因为据我所知,没有这方面的文档——至少 none 易于访问。
要素的 style
元素(如 GMUGeometryContainer
)是 GMUStyle
。这是它的初始值设定项:
GMUStyle(styleID:stroke:fill:width:scale:heading:anchor:iconUrl:title:hasFill:hasStroke:)
例如,我可能会解析我的 GeoJSON 并为特定功能添加样式,如下所示:
parser = GMUGeoJSONParser(url: overlayUrl)
parser.parse()
renderer = GMUGeometryRenderer(map: map, geometries: parser.features)
parser.features.first!.style = GMUStyle(styleID: "feat_1", stroke: UIColor.red, fill: UIColor(white: 1, alpha: 0.8), width: 2, scale: 1, heading: 1, anchor: CGPoint.zero, iconUrl: nil, title: nil, hasFill: true, hasStroke: true)
renderer.render()
老实说,我不知道 anchor
会发生什么变化,heading
或 scale
——这对我来说也不重要,对你来说可能也不重要。当缩放、平移、旋转或倾斜时,该功能的样式看起来符合预期,无需您进行任何额外更改。
如果有人可以在这个晦涩难懂的 class 上添加更多详细信息,那将是对这个答案的编辑或一个全新的答案。
我通过解析 GeoJSON 向 GMSMapView 添加了一项功能。然而,我在弄清楚如何设置此功能的样式方面遇到了极大的麻烦。
目前,该功能是默认的蓝色描边和半透明蓝色填充。我想改变这些颜色。我试着查看 the documentation,但毫无帮助。我在互联网上找到的所有其他问题都是关于 JavaScript API.
如何在我的 Google 地图上设置特定要素的样式——仅 GeoJSON 文件中的要素?最好是动态的,但不必如此。
这让我猜测了很多,因为据我所知,没有这方面的文档——至少 none 易于访问。
要素的 style
元素(如 GMUGeometryContainer
)是 GMUStyle
。这是它的初始值设定项:
GMUStyle(styleID:stroke:fill:width:scale:heading:anchor:iconUrl:title:hasFill:hasStroke:)
例如,我可能会解析我的 GeoJSON 并为特定功能添加样式,如下所示:
parser = GMUGeoJSONParser(url: overlayUrl)
parser.parse()
renderer = GMUGeometryRenderer(map: map, geometries: parser.features)
parser.features.first!.style = GMUStyle(styleID: "feat_1", stroke: UIColor.red, fill: UIColor(white: 1, alpha: 0.8), width: 2, scale: 1, heading: 1, anchor: CGPoint.zero, iconUrl: nil, title: nil, hasFill: true, hasStroke: true)
renderer.render()
老实说,我不知道 anchor
会发生什么变化,heading
或 scale
——这对我来说也不重要,对你来说可能也不重要。当缩放、平移、旋转或倾斜时,该功能的样式看起来符合预期,无需您进行任何额外更改。
如果有人可以在这个晦涩难懂的 class 上添加更多详细信息,那将是对这个答案的编辑或一个全新的答案。