Maps 在Bing地图中添加多个图钉时,infobox始终使用最后一个元素

Maps 在Bing地图中添加多个图钉时,infobox始终使用最后一个元素,maps,bing-maps,bing,pushpin,infobox,Maps,Bing Maps,Bing,Pushpin,Infobox,我想在我的bing地图中添加多个信息框,这些信息框将在启动时自动加载,而不是在单击事件时自动加载。假设我有3个图钉,所以3个信息框会自动弹出数据,比如第一个信息框会包含詹姆斯、第二个马克、第三个等等。到现在为止,如果我把它放在一个循环中,并尝试添加它,它总是取最后一个值 for (var i = 0; i < json.length; i++) { var pinInfoBox; //the pop up info box

我想在我的bing地图中添加多个信息框,这些信息框将在启动时自动加载,而不是在单击事件时自动加载。假设我有3个图钉,所以3个信息框会自动弹出数据,比如第一个信息框会包含詹姆斯、第二个马克、第三个等等。到现在为止,如果我把它放在一个循环中,并尝试添加它,它总是取最后一个值

 for (var i = 0; i < json.length; i++) {
                          var pinInfoBox;  //the pop up info box
                          var infoboxLayer = new Microsoft.Maps.EntityCollection();
                          var pinLayer = new Microsoft.Maps.EntityCollection();
                          var loc = jsonData.location[i];
                           var pushpinOptions = {icon: 'xxx.png', width: 80, height: 80, offset: new Microsoft.Maps.Point(0, 15)};
                         var infoboxOptions = {showCloseButton: true, visible:false };
                          pinInfobox = new Microsoft.Maps.Infobox(map.getCenter(), infoboxOptions );
                           pinInfobox.setHtmlContent('<div class="arrow_box"><div class="content" id="content">'+loc.name+'</div></div>'); //here the name should keep changing
                          infoboxLayer.push(pinInfobox);
                          var pin = new Microsoft.Maps.Pushpin(latLon,pushpinOptions);
                           pinLayer.push(pin); //add pushpin to pinLayer
                          Microsoft.Maps.Events.addHandler(pin, 'click', displayInfobox); //here instead of click event i want the infobox to display automatically on startup
                          map.entities.push(pinLayer);
                          map.entities.push(infoboxLayer);
           }

           function displayInfobox(e) {

        pinInfobox.setOptions({title: e.target.Title, description: e.target.Description,                  visible:true, offset: new Microsoft.Maps.Point(-50,90)});
      pinInfobox.setLocation(e.target.getLocation());
          }
for(var i=0;i
在for循环内部而不是之后设置信息框的选项和位置。然后在图钉中存储对每个信息框的引用。执行类似于
pin.infobox=pinInfobox的操作然后在displayInfobox功能中,您可以通过执行以下操作来显示infobox:

e.target.infobox.setOptions({visible: true});
也就是说,如果你有很多图钉,最好有一个信息框,并根据需要进行更新。以下是一篇博客文章,概述了这种方法: