刷新Bing Maps API内容

3

我正在使用Bing Maps API版本7。 我在地图上绘制了4个EntityCollections:一个用于一组推针,一个用于与这些推针关联的信息框,一个用于一组折线和一个用于与这些折线关联的信息框。 我使用setInterval定期尝试刷新折线及其关联的信息框的内容。 我通过以下方式清除折线的实体集合:

//clear polylines from map
    map.entities.clear(mapSegments);
    map.entities.clear(mapSegmentInfoboxes);

然后,在重新填充它们之前,只需重新初始化它们:

//new polyline collection
    mapSegments = new Microsoft.Maps.EntityCollection();
    mapSegmentInfoboxes = new Microsoft.Maps.EntityCollection();

这个功能是可以用的,但是在刷新完成后我的图钉信息框停止显示。

图钉和它们相关的信息框在刷新过程中保持不变,那么为什么我的图钉信息框停止显示呢?显示信息框的图钉点击事件仍然触发,但是没有显示出来。

执行单个语句map.entities.clear(mapSegments)似乎会破坏与之无关的另一个EntityCollection。

1个回答

3
在Bing文档中,当您调用map.entities.clear()时,它将清除地图实体数组中的所有实体。它似乎没有接受任何参数的clear()方法。
您可以尝试下列方法之一:
//clear polylines from map
map.entities.remove(mapSegments);
map.entities.remove(mapSegmentInfoboxes);

或者

//clear polylines from map
map.entities.removeAt(indexOfMapSegments);
map.entities.removeAt(indexOfMapSegmentInfoboxes);

或者一个更完整的例子是:
for(var i = map.entities.getLength()-1; i > = 0; i--) {
    var polyline= map.entities.get(i); 
    if (polyline instanceof Microsoft.Maps.Polyline) { 
    map.entities.removeAt(i);  
   }
} 
displayAlert('Polylines removed');

将“instanceof Microsoft.Maps.Polyline”替换为您想要删除的实体类型...

如果您想查看文档,请访问此处 https://msdn.microsoft.com/zh-cn/library/gg427616.aspx


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接