I've got multiple kml layers that are loaded into my Google Map API V3 using tick boxes. When two or more layers are selected the infowindows on one layer don't automatically collapse when markers are clicked on other layers. I'd like the infowindows to close automatically even though they are on different KML layers - Any pointers in the right direction will be helpful.
Thanks
Darren Wilson
You need to disable the default info window creation and handle the infowindow yourself in code. Here's an example:
var CommonInfoWindow = new google.maps.InfoWindow({"maxWidth": 500});
/** @param {...*} KmlMouseEvent */
function KmlLayerClicked(KmlMouseEvent) {
var ClickData = /** @type {google.maps.KmlMouseEvent} */(KmlMouseEvent);
CommonInfoWindow.close();
if (ClickData.featureData && ClickData.featureData.id) {
CommonInfoWindow.setOptions({ "position": ClickData.latLng,
"pixelOffset": ClickData.pixelOffset,
"content": ClickData.featureData.infoWindowHtml
});
CommonInfoWindow.open(map);
}
}
/** @type {google.maps.KmlLayer} */
var KmlOverlay = new google.maps.KmlLayer(KmlUrl, {
'preserveViewport': true,
'suppressInfoWindows': true
});
google.maps.event.addListener(KmlOverlay, "click", KmlLayerClicked);