本文介绍了当选择另一个KML图层时,信息窗口保持活动状态的问题 - Google Maps API V3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用勾选框将多个kml图层加载到我的Google地图API V3中。当选择两个或多个图层时,一个图层上的信息导入不会在其他图层上单击标记时自动折叠。我希望infowindows即使在不同的KML图层上也会自动关闭 - 任何指向正确方向的指针都会有帮助。

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.

谢谢

Darren Wilson

Darren Wilson

推荐答案

您需要禁用默认的信息窗口创建并自己处理infowindow在代码中。这里有一个例子:

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

这篇关于当选择另一个KML图层时,信息窗口保持活动状态的问题 - Google Maps API V3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 03:35