GeoJSON render styles
I have implemented GeoJSON data with google-maps-ios-utils, but how could I config the rendering styles? In the documentation of Google Maps APIs, there is seems no example of "GMUStyles" configuration setting. I tried to setup as following but it's not working on styles change. (geometry features is working well)
----my codes example start here---- geoJsonParser = GMUGeoJSONParser(data: jsonData) geoJsonParser.parse() renderer = GMUGeometryRenderer(map: mapView, geometries: geoJsonParser.features, styles: [GMUStyle(styleID: "111", stroke: UIColor.red, fill: UIColor.red, width: 0.8, scale: 1.0, heading: 1.0, anchor: CGPoint(x: 0, y: 0), iconUrl: "non", title: "title", hasFill: false, hasStroke: true)]) renderer.render() ----my codes example end here----
GeoJSON does not have a concept of styles like KML so you will need to manually associate the style object to a feature. You could loop through geoJsonParser.features and assign it's .style property to the GMUStyle object.
Thank you @mountainvat, would you help explain how to associate the style object further? I found that each element in geoJsonParser.features.style is get-only property which means I cannot assign values to them. e.g. geoJsonParser.features[i].style.strokeColor = UIColor.red Whether there is a normal style format in geojson text structure so that I can retrieve each .style object directly as the GMUStyle object?
The GMUStyle object is immutable but the property GMUGeometryContainer.style is not. You can assign that property to the style object (https://github.com/googlemaps/google-maps-ios-utils/blob/master/src/Geometry/Model/GMUGeometryContainer.h#L36). GeoJSON does not support styles in its format (at least at the time of writing the library), that's why you'll have to set them manually.
Yeah, I got it finally. It's really good explanation so that I could understand the model more. Many thanks to @mountainvat.
Just in case someone else comes across this, I did the following to get it to work:
let path = Bundle.main.path(forResource: "countries", ofType: "json")
let url = URL(fileURLWithPath: path!)
let geoJsonParser = GMUGeoJSONParser(url: url)
geoJsonParser.parse()
let style = GMUStyle(styleID: "random", stroke: UIColor.blue, fill: UIColor.orange.withAlphaComponent(0.5), width: 2, scale: 1, heading: 0, anchor: CGPoint(x: 0, y: 0), iconUrl: nil, title: nil, hasFill: true, hasStroke: true)
for feature in geoJsonParser.features {
feature.style = style
}
renderer = GMUGeometryRenderer(map: gmapView, geometries: geoJsonParser.features)
renderer.render()
let style = GMUStyle(styleID: "random", stroke: .red, fill: .clear, width: 1, scale: 1, heading: 0, anchor: CGPoint(x: 0, y: 0), iconUrl: nil, title: "Test", hasFill: false, hasStroke: true)
disable fill not working? Plz help

@fukemy try setting hasFill: true and fill: .clear
hello. I fixed it by modifying GMUGeoJSONParser class, just set default for Polyline fill color. Plz help my question: I want to highlight geojson feature on click. I dont know the way to do it