在googlemap中自动关闭InfoWindow [英] Auto close InfoWindow in googlemap

查看:83
本文介绍了在googlemap中自动关闭InfoWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道该怎么做才能在另一个打开时自动关闭InfoWindow 。

  function bindInfoWindow(marker,map,title,race,loc,org,web,link){
var infoWindowVisible =(function(){
var currentVisible = false;
return function可见){
if(visible!== undefined){
currentlyVisible = visible;
}
return currentlyVisible;
};
}()) ;
iw = new google.maps.InfoWindow();
google.maps.event.addListener(marker,'click',function(){
if(infoWindowVisible()){
iw.close();
infoWindowVisible(false );
} else {
var html =< div style ='color:#000; background-color:#fff; padding:5px; width:250px;'>< h4> +标题+ < / H4>< p为H.种族与LT; / p为H.< H4> 中+种族+ < / H4>< p为H.位置和LT; / p为H.< H4> 中+ LOC + < / h4>< hr />< p> Organizzazione< h4>< + h +>< h4>< a href ='+ link +''>+ web +< ; a>< / div>;
iw = new google.maps.InfoWindow({content:html});
iw.open(map,marker);
infoWindowVisible(true );
}
});
google.maps.event.addListener(iw,'closeclick',function(){
infoWindowVisible(false);
});
}

我试过但我找不到我的类型案例。

$如果你只想要一个infowindow,只需要创建一个InfoWindow(在全局范围内),再次使用它并在点击标记时改变其内容,如果用户点击地图,关闭它。



类似的问题

  var iw = new google.maps.InfoWindow(); //单个全局infowindow 
google.maps.event.addListener(map,'click',function(){
iw.close();
});
函数bindInfoWindow(marker,map,title,race,loc,org,web,link){
google.maps.event.addListener(marker,'click',function(){
iw.close();
var html =< div style ='color:#000; background-color:#fff; padding:5px; width:250px;'>< h4>+ title + < / H4>< p为H.种族与LT; / p为H.< H4> 中+种族+ < / H4>< p为H.位置和LT; / p为H.< H4> 中+ LOC +< / H4> < h>< p> Organizzazione< h4>+ org +< / h4>< a href ='+ link +''>+ web +< a>< < / div>;
iw.setContent(html);
iw.open(map,marker);
});
}

工作小提琴 - 不同的代码,因为你没有提供一个完整的例子,演示了这个概念。


I do not know how to do in order to automatically close a InfoWindow when another opens.

 function bindInfoWindow(marker, map, title, race, loc, org, web, link) {
  var infoWindowVisible = (function () {
          var currentlyVisible = false;
          return function (visible) {
              if (visible !== undefined) {
                  currentlyVisible = visible;
              }
              return currentlyVisible;
           };
       }());
       iw = new google.maps.InfoWindow();
       google.maps.event.addListener(marker, 'click', function() {
           if (infoWindowVisible()) {
               iw.close();
               infoWindowVisible(false);
           } else {
               var html= "<div style='color:#000;background-color:#fff;padding:5px;width:250px;'><h4>"+title+"</h4><p>Race</p><h4>"+race+"</h4><p>Location</p><h4>"+loc+"</h4><hr /><p>Organizzazione</p><h4>"+org+"</h4><a href='"+link+"'' >"+web+"<a></div>";
               iw = new google.maps.InfoWindow({content:html});
               iw.open(map,marker);
               infoWindowVisible(true);
           }
    });
    google.maps.event.addListener(iw, 'closeclick', function () {
        infoWindowVisible(false);
    });
}

I tried but I can not find my type cases.

解决方案

If you only want one infowindow ever, only create one InfoWindow (in the global scope), reuse it and change its contents when a marker is clicked, close it if the user clicks on the map.

similar question

 var iw = new google.maps.InfoWindow(); // single global infowindow
 google.maps.event.addListener(map, 'click', function() {
   iw.close();
 });
 function bindInfoWindow(marker, map, title, race, loc, org, web, link) {
   google.maps.event.addListener(marker, 'click', function() {
     iw.close();
     var html= "<div style='color:#000;background-color:#fff;padding:5px;width:250px;'><h4>"+title+"</h4><p>Race</p><h4>"+race+"</h4><p>Location</p><h4>"+loc+"</h4><hr /><p>Organizzazione</p><h4>"+org+"</h4><a href='"+link+"'' >"+web+"<a></div>";
     iw.setContent(html);
     iw.open(map,marker);
   });
}

working fiddle - different code as you didn't provide a complete example, demonstrates the concept.

这篇关于在googlemap中自动关闭InfoWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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