【发布时间】:2017-07-10 11:30:46
【问题描述】:
我的应用程序中有一个屏幕,我在其中使用 Bing 地图管理多边形和与多边形相关的信息。
我想在有人点击多边形时显示多边形详细信息。所以我在多边形上添加了一个点击事件,它工作正常。
我还希望允许用户在单击事件后查看/修改其他信息时编辑多边形。所以我计划在点击事件后从地图实体中删除多边形并将其添加到绘图管理器以进行进一步编辑。但是我无法从地图实体中删除特定的多边形。我尝试准备相同的多边形并将其传递给地图的实体删除功能,但它不起作用。以下是相同的示例代码,我的应用程序是用 Angular 开发的:
var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
credentials: 'Your Bing Maps Key'
});
var polygon1 = new Microsoft.Maps.Polygon([
new Microsoft.Maps.Location(center.latitude + 0.01, center.longitude - 0.03),
new Microsoft.Maps.Location(center.latitude + 0.01, center.longitude - 0.11),
new Microsoft.Maps.Location(center.latitude + 0.05, center.longitude - 0.07)
]);
polygon1.entity = { id: 1 };
map.entities.push(polygon1);
var polygon2 = new Microsoft.Maps.Polygon([
new Microsoft.Maps.Location(center.latitude + 0.01, center.longitude + 0.03),
new Microsoft.Maps.Location(center.latitude + 0.01, center.longitude + 0.11),
new Microsoft.Maps.Location(center.latitude + 0.05, center.longitude + 0.07)
]);
polygon2.entity = { id: 2 };
map.entities.push(polygon2);
Microsoft.Maps.Events.addHandler(polygon, 'click', function (e) {
var geoId = e.target.entity.id;
//Here I want to find the polygon with provided Id and remove it so that I can add it to drawing manager for further modification
//Code to remove the polygon
var polygonToRemove = new Microsoft.Maps.Polygon([
new Microsoft.Maps.Location(center.latitude + 0.01, center.longitude - 0.03),
new Microsoft.Maps.Location(center.latitude + 0.01, center.longitude - 0.11),
new Microsoft.Maps.Location(center.latitude + 0.05, center.longitude - 0.07)
]);
polygonToRemove.entity = { id: 1 };
map.entities.remove(polygonToRemove);
//Code to add the polygon to drawing manager
});
【问题讨论】:
标签: javascript bing-maps