Search code examples
google-mapsgoogle-maps-api-3geojson

Get all Google Map v3 markers loaded from GeoJSON


I load data for my Google Maps v3 with GeoJSON:

that.map = new google.maps.Map($('#map')[0], mapOptions);
that.map.data.loadGeoJson('http://localhost/geoserver/...');

Now, at some point on some user event I need to get one marker and paint it blue. I can set different color with setIcon.

My idea is to get all features, then iterate through them, find the right feature (based on UNIQUE feature data field) and find marker behind that feature and change icon. I found some approaches that store all markers in array, but don't know why I need another array. Computer resources are important and I don't want to duplicate things.

I need help with, how to get features and how to get Marker object associated with selected feature. If there is a better way to do it, please...

UPDATE

I found this:

var feature = this.map.data.getFeatureById(ID);

I just need to get feature Marker. How? Doesn't look that Feature class has method for that?


Solution

  • There is no method/property that gives you access to the shape(marker,polygon,etc.) that has been created by the API.

    To set a new icon-property for a particular feature use overrideStyle:

    map.data.overrideStyle(feature, {icon: newIconSettings});