Bing 地图图钉点击事件处理程序只应用最后一个
Bing map pushpin click event handler applies only last one
我的应用程序生成了以下 Bing 地图 -
在红色图钉之后添加到地图的绿色图钉。每个图钉都有一个打开信息框的点击处理程序。我的问题是无论我点击什么图钉,它都只会打开绿色图钉的信息框。
这是我的代码-
var center = new Microsoft.Maps.Location(24.3636, 88.6241);
var map = new Microsoft.Maps.Map(document.getElementById('myMap'), { center:center, zoom: 7 });
var color; var description;
@foreach (var item in Model.MapData)
{
<text>
var location = new Microsoft.Maps.Location(@item.Latitude,@item.Longitude);
var pushpin = new Microsoft.Maps.Pushpin(location, { color: color });
map.entities.push(pushpin);
var infobox = new Microsoft.Maps.Infobox(location, {
title: '@item.DtwId',
description: '@item.Desc',
visible: false
});
Microsoft.Maps.Events.addHandler(pushpin, 'click', function () {
infobox.setOptions({ visible: true });
});
infobox.setMap(map);
</text>
}
我错过了什么?
var location = new Microsoft.Maps.Location(@item.Latitude,@item.Longitude);
var pushpin = new Microsoft.Maps.Pushpin(location, { color: color });
pushpin.metadata = {
title: '@item.DtwId',
description: '@item.Desc',
franchiseNumber: 1
};
Microsoft.Maps.Events.addHandler(pushpin, 'click', pushpinClicked);
map.entities.push(pushpin);
function pushpinClicked(e) {
var infobox = new Microsoft.Maps.Infobox(e.target.getLocation(), {
title: e.target.metadata.title,
description: e.target.metadata.description,
visible: true
});
infobox.setMap(map);
我的应用程序生成了以下 Bing 地图 -
在红色图钉之后添加到地图的绿色图钉。每个图钉都有一个打开信息框的点击处理程序。我的问题是无论我点击什么图钉,它都只会打开绿色图钉的信息框。
这是我的代码-
var center = new Microsoft.Maps.Location(24.3636, 88.6241);
var map = new Microsoft.Maps.Map(document.getElementById('myMap'), { center:center, zoom: 7 });
var color; var description;
@foreach (var item in Model.MapData)
{
<text>
var location = new Microsoft.Maps.Location(@item.Latitude,@item.Longitude);
var pushpin = new Microsoft.Maps.Pushpin(location, { color: color });
map.entities.push(pushpin);
var infobox = new Microsoft.Maps.Infobox(location, {
title: '@item.DtwId',
description: '@item.Desc',
visible: false
});
Microsoft.Maps.Events.addHandler(pushpin, 'click', function () {
infobox.setOptions({ visible: true });
});
infobox.setMap(map);
</text>
}
我错过了什么?
var location = new Microsoft.Maps.Location(@item.Latitude,@item.Longitude);
var pushpin = new Microsoft.Maps.Pushpin(location, { color: color });
pushpin.metadata = {
title: '@item.DtwId',
description: '@item.Desc',
franchiseNumber: 1
};
Microsoft.Maps.Events.addHandler(pushpin, 'click', pushpinClicked);
map.entities.push(pushpin);
function pushpinClicked(e) {
var infobox = new Microsoft.Maps.Infobox(e.target.getLocation(), {
title: e.target.metadata.title,
description: e.target.metadata.description,
visible: true
});
infobox.setMap(map);