我的网站上有Google地图
并附加到它的moveend事件处理程序

   GEvent.addListener(map, "moveend", function()
    {
            map.clearovrelays();
            GetLayerDataFromServer(); //it set the markers again on the map  according the map position
    });


我也有事件处理程序,用于单击标记

GEvent.addListener(marker, 'click', function()
    {
        marker.openInfoWindowHtml('this is the data');
    });


我的问题是

当用户按下地图上的一个标记时
它打开
相关标记的openInfoWindowHtml。

并且还将地图移动到该标记位置。
然后触发事件

map.moveend


在map.moveend事件中,我清除了地图上的所有标记
并根据地图的新位置重新加载它们。

结果是
当用户单击标记时,它将第二次打开其indoWindowHtml
然后清除地图并再次加载标记,
而不显示单击标记的indoWindowHtml。

我的问题是我应该怎么做才能显示infoWindowHtml?

最佳答案

您可以设置一个标志,该标志指示用户是否单击了标记,如果是这种情况,则不清除地图。

var marker_clicked = false;

GEvent.addListener(map, "moveend", function()
{
    if(!marker_clicked)
    {
        map.clearovrelays();
        GetLayerDataFromServer(); //it set the markers again on the map  acording the map position
    }
    marker_clicked = false;
});

GEvent.addListener(marker, 'click', function()
{
    marker_clicked = true;
    marker.openInfoWindowHtml('this is the data');
});

关于javascript - 从服务器检索信息后,在Google Map上打开openinfowindowhtml,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1444021/

10-12 12:29
查看更多