google-maps-ios-utils icon indicating copy to clipboard operation
google-maps-ios-utils copied to clipboard

Change style (specific icon and title) on features from GeoJSON parser

Open juvs opened this issue 9 years ago • 17 comments

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

juvs avatar Aug 31 '17 02:08 juvs

I am also facing the same issue with this as I want to changes style

SiddharthChopra avatar Dec 06 '17 11:12 SiddharthChopra

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 :(

patcornejocl avatar Dec 08 '17 02:12 patcornejocl

I can confirm that it still doesn't work and "properties" is not available for use.

sidlauskaslukas avatar Apr 16 '18 11:04 sidlauskaslukas

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)
}

returnchung avatar Jul 11 '18 08:07 returnchung

Hi guys, Is there any way to access properties ? i want to change style for each feature with some specific condition

minhmera avatar Sep 12 '19 03:09 minhmera

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!

stale[bot] avatar Dec 11 '19 04:12 stale[bot]

@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
  }
}

arriolac avatar Jan 15 '20 21:01 arriolac

Closing. Please reopen if this does not resolve your issue.

arriolac avatar Jan 15 '20 21:01 arriolac

@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
  }
}

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 avatar Mar 05 '20 12:03 mallikarjuna0308

@mallikarjuna0308 can you share a code snippet? The code I shared above runs just fine assuming the right import statements are in place.

arriolac avatar Mar 05 '20 16:03 arriolac

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.

mallikarjuna0308 avatar Mar 06 '20 05:03 mallikarjuna0308

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

arriolac avatar Mar 06 '20 17:03 arriolac

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?

mallikarjuna0308 avatar Mar 10 '20 07:03 mallikarjuna0308

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 avatar Mar 11 '20 07:03 mallikarjuna0308

@mallikarjuna0308 glad you were able to get that working. Curious what version of this library are you using?

arriolac avatar Mar 11 '20 15:03 arriolac

@arriolac I'm using 'Google-Maps-iOS-Utils', '~> 3.0.2'

mallikarjuna0308 avatar Mar 12 '20 05:03 mallikarjuna0308

@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
  }
}

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?

chitgoks avatar Nov 09 '22 11:11 chitgoks