[GIS] Triggering event on multiple layers at same time in Google Maps

google-maps-apigoogle-maps-engine

Say if I have 3 layers with different table schemas (fields), I pushed all three layers into one array and loop through the array to add listeners to each layer so that everytime I click on the map, all three layers should be triggered the click event and I can proceed to get details of the event triggered such as featureId or InfoWindowHtml. Theoretically, problem should be solved, but it doesn't work. I assume that googlemaps api only fires the event that is bound to the top visible layer object.

Is there any way that I can trigger all three events at the same time manually on I click a place on map?

//Loop through each layer  
            for (var i = 0; i < visibleLayersNo; i++) {  

                var layer = this.options.visibleLayers[i];                 

                //Attach custom map click event to each layer,  
                 //but the event can only be fired when the object bound to it is on top and visible.  
                google.maps.event.addListener(layer, 'click', function(event){  
                    //do something  
                });                                     
            }  

Best Answer

You could fire the events yourself. It's covered in this post on Stack Overflow.

google.maps.event.trigger(layer, 'click', new google.maps.MouseEvent(...));