Reputation: 839
I added a feature to my GMSMapView by parsing a GeoJSON. I have been having extreme trouble with figuring out how to style this feature, however.
Currently, the feature is the default blue stroke and translucent blue fill. I would like to change these colors. I tried looking at the documentation, but it is quite unhelpful. All of the other questions on the internet that I could find are about the JavaScript API.
How can I style a specific feature––only the ones in my GeoJSON file––on my Google Map? Preferably this would be dynamically but it does not have to be so.
Upvotes: 1
Views: 1214
Reputation: 3597
This took me a lot of guessing because as far as I could tell, there exists no documentation for this––at least none easily accessible.
The style
element of a feature (like a GMUGeometryContainer
) is a GMUStyle
. This is the initializer for it:
GMUStyle(styleID:stroke:fill:width:scale:heading:anchor:iconUrl:title:hasFill:hasStroke:)
For example, I might parse my GeoJSON and add a style to a specific feature like this:
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()
To be honest, I do not know what anchor
will change, heading
, or scale
––nor does it matter for me, or likely for you either. When one zooms, pans, rotates, or tilts, the feature's style looks as expected without any additional changes from you.
If someone could add more detail on this obscure class, that would be great as an edit to this answer or an entirely new one.
Upvotes: 10