A client has loaded some polygons onto a map using Google Maps APIv3 loadGeoJson() method. I want to be able to search through those polygons and, when one matches a submitted string, zoom/centre on it and trigger a click event, opening the infowindow of that polygon.
Some answers hint that, to reference the geoJSON feature, it's best to use getId(), then use that reference to select the polygon on the map. Comes out undefined, and not sure if it would help anyways; few other methods really seem to work (getGeometry() is broken), through getProperty() does. This makes me think maybe I'm iterating over the wrong array.
This JSBin illustrates what I'm trying to do, especially lines 85-100:
// Trying to search in the layer and trigger an event
geoJsonLayer.forEach(function(feature) {
if(searchString===feature.getProperty('letter')) {
// Match found, Zoom to this feature and pop its infobox
var foundFeatureId = feature.getId(); // Is undefined
// var foundFeatureId = feature.id; // Is undefined
// var foundFeatureGeo = feature.getGeometry().get(); // Not a function
console.log(foundFeatureId);
google.maps.event.trigger(map,'click',feature); // seems to do nothing
}
});
On search of a character ("g","o","l", for instance), the search finds a match and then tries to trigger the click event of that geoJSON polygon (ultimately, so the infowindow is opened).
This is the part that's stumping me. I've tried defining the ID, but it's undefined using getId(). Can't seem to directly trigger it either when iterating over the Data layer. Can't seem to find it when trying to look into maps.data either.
How do I properly trigger this event using the geoJSON layer only?