如何使infowindow显示取决于它已有的空间并且不移动地图 [英] How to make the infowindow appear depending upon the space it already have and not move the map

查看:77
本文介绍了如何使infowindow显示取决于它已有的空间并且不移动地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google地图中显示少量地点。如果用户放大/缩小或拖动地图,我会刷新这些位置。现在的问题是,如果我点击某个位置的标记,那么信息窗口打开并拖动地图,如果它没有任何显示空间的话。这种拖动导致我的位置被刷新,因此我的标记消失。

I am displaying few locations in google maps. I refresh these locations if a user zoom in/out or drags the map. Now the issue is if i click on the marker of a location then the info window opens up and drags the map if it doesn't have any space to show. This dragging causes my locations to be refreshed and hence my marker vanishes.

我试过 disableAutoPan:true 信息窗口不是只能看到。有什么方法可以让信息窗口自动调整自己。有什么方法可以对此进行排序吗?

I tried disableAutoPan: true but then the info window is not seen only. Is there any way that the info window auto adjust itself. is there any way to sort this out?

推荐答案

使用全局变量来指示何时应该忽略刷新,例如:

Use a global variable to indicate when the refresh should be ignored, for example:

// Global var
var ignoreRefresh = false;

google.maps.addListener(marker,'click', function(){
  ignoreRefresh = true;
  infoWindow.setContent('Hello');
  infoWindow.open(map,marker);
})

function refresh(){
  if (ignoreRefresh) {
    ignoreRefresh = false;
    return;
  }
  //...
  //do your normal refresh of data
  //...

}

这篇关于如何使infowindow显示取决于它已有的空间并且不移动地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆