How to make the infowindow appear depending upon the space it already have and not move the map

旧城冷巷雨未停 提交于 2019-12-12 06:26:14

问题


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.

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?


回答1:


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
  //...

}


来源:https://stackoverflow.com/questions/12793287/how-to-make-the-infowindow-appear-depending-upon-the-space-it-already-have-and-n

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