Change style (specific icon and title) on features from GeoJSON parser
Maybe is something is already answered, but how I can change the style of features from GeoJSON parser based on properties from any single feature?
I have the following:
let path = Bundle.main.path(forResource: "GeoJSON_sample", ofType: "json")
let url = URL(fileURLWithPath: path!)
geoJsonParser = GMUGeoJSONParser(url: url)
geoJsonParser.parse()
// MARK: Here try to iterate features and change style, but there's no way no get properties from feature,
// Also, create a new GMUStyle and set iconUrl and title and nothing changes,
// I set iconUrl using asset key name filename from Assets
renderer = GMUGeometryRenderer(map: mapView, geometries: geoJsonParser.features)
renderer.render()
Any help appreciated!
Regards
I am also facing the same issue with this as I want to changes style
You should be available to use this:
let features = geoJsonParse.features as? [GMUFeature]
for features in features {
feature.properties // Return properties
}
The only problem its that doesn't work :(
I can confirm that it still doesn't work and "properties" is not available for use.
Here is a sample to iterate rendering all features with customized style. Try it :)
let strokeColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1)
for feature in geoJsonParser.features {
feature.style = GMUStyle(styleID: "12345", stroke: strokeColor, fill: UIColor.clear, width: 2.0, scale: 1.0, heading: 0.0, anchor: CGPoint(x: 0, y: 0), iconUrl: "url", title: "title", hasFill: false, hasStroke: true)
}
Hi guys, Is there any way to access properties ? i want to change style for each feature with some specific condition
This issue has been automatically marked as stale because it has not had recent activity. Please comment here if it is still valid so that we can reprioritize. Thank you!
@juvs you should be able to access the properties of a feature, it requires some type checking though since geoJsonParser.features is of type [GMUGeometryContainer] and not [GMUFeature].
i.e.
for obj in geoJsonParser.features {
if let feature = obj as? GMUFeature {
let properties = feature.properties
// Do something with properties here
}
}
Closing. Please reopen if this does not resolve your issue.
@juvs you should be able to access the properties of a feature, it requires some type checking though since
geoJsonParser.featuresis of type[GMUGeometryContainer]and not[GMUFeature].i.e.
for obj in geoJsonParser.features { if let feature = obj as? GMUFeature { let properties = feature.properties // Do something with properties here } }
Hi arriolac, I tried the above you provided. But it throws an error "Use of undeclared type 'GMUFeature' ". Could you suggest some other way to access properties?
@mallikarjuna0308 can you share a code snippet? The code I shared above runs just fine assuming the right import statements are in place.
Thank you @arriolac for your response. I did not import anything, when I'm trying to import Google-Maps-iOS-Utils, it is throwing an error. Since I did not import any thing, I might be facing error while using your code. Could you please let me know what and where to import the library? If I still face the issue, I would share the code with you. Note: I have used cocoapods to integrate Google-Maps-iOS-Utils library in my project.
You need to do the following at the top of your .swift files:
import GoogleMapsUtils
or at the top of your .m files for Obj-C:
@import GoogleMapsUtils;
You can refer to our samples directory to see how it's used: https://github.com/googlemaps/google-maps-ios-utils/tree/master/samples
Hi @arriolac, sorry for the late reply. I tried to import GoogleMapsUtils as you mentioned above, but it's throwing an error " No such module 'GoogleMapsUtils' ". I have gone through the link you provided above too but still the error still persists. Could you please help me in this regard?
Hi @arriolac, my problem got resolved. I used cocoapods to integrate this library and also added in library in Bridging-Header.h file as suggested in this link: https://developers.google.com/maps/documentation/ios-sdk/utility/kml-geojson After commenting in header file, everything started working fine. Thanks a lot for your support @arriolac.
@mallikarjuna0308 glad you were able to get that working. Curious what version of this library are you using?
@arriolac I'm using 'Google-Maps-iOS-Utils', '~> 3.0.2'
@juvs you should be able to access the properties of a feature, it requires some type checking though since
geoJsonParser.featuresis of type[GMUGeometryContainer]and not[GMUFeature].i.e.
for obj in geoJsonParser.features { if let feature = obj as? GMUFeature { let properties = feature.properties // Do something with properties here } }
hi, i came across this thread because i do not know how to access feature.properties once it is rendered by GMUGeometryRenderer.render()
i thought at first that geoJsonParser.features link hand in hand with renderer.mapOverlays() but the overlays count too many compared to the features array of geoJsonParser.
i was looking at populating the userData property but there does not seem to be a way to do so?
There are other key values in the properties property that i need to access once rendered to screen. since there is no way to set click listeners for the GMUFeature unlike in android, how can this be possibly done through swiftui?