我有多个使用勾选框加载到我的 Google Map API V3 中的 kml 图层。When two or more layers are selected the infowindows on one layer don't automatically collapse when markers are clicked on other layers. 我希望信息窗口自动关闭,即使它们位于不同的 KML 图层上 - 任何指向正确方向的指针都会有所帮助。
谢谢
达伦·威尔逊
我有多个使用勾选框加载到我的 Google Map API V3 中的 kml 图层。When two or more layers are selected the infowindows on one layer don't automatically collapse when markers are clicked on other layers. 我希望信息窗口自动关闭,即使它们位于不同的 KML 图层上 - 任何指向正确方向的指针都会有所帮助。
谢谢
达伦·威尔逊
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);