我想在我的 bing 地图中添加多个信息框,这些信息框将在启动时自动加载,而不是在点击事件时加载。假设我有 3 个图钉,所以 3 个信息框会自动弹出数据,例如第一个信息框将包含 james、第二个标记、第三个等。截至目前,如果我把它放在一个循环中并尝试添加它总是采用最后一个值
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());
}