Issue with infowindows remaining active when another KML layer is selected - Google Maps API V3

我的梦境 提交于 2019-12-04 04:57:03

问题


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


回答1:


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);


来源:https://stackoverflow.com/questions/10628175/issue-with-infowindows-remaining-active-when-another-kml-layer-is-selected-goo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!