I want to set click listeners on many different shapes on my map. Each shape has a bunch of data which I want to show when I click on it.
var newData = new google.maps.Data({
map: map,
style: map.data.getStyle()
});
for (var i = 0; i < shapes.length; i++) {
var userObject = JSON.parse(shapes[i].area);
newData.addGeoJson(userObject);
// It would be simplest to add a clicklistener here since i got access to the shapes[i] with the data to act on
google.maps.event.addListener( /* ??? */, 'click', function (event) {
alert("y");
});
}
map.data.setMap(null);
map.data = newData;
I tried setting the click listener on the returned array from addGeoJson(...) but maybe im approaching this wrong. Maybe I need to get polygons somehow and then go about it like in this official example or Im thinking I could do something hacky with different layers.
How would you do this, given that you cannot change that you get a bunch of separate geoJson chunks? Can I get my geoJson as polygons when I'm adding them?