简体   繁体   English

刷新Bing Maps API内容

[英]Refreshing Bing Maps API Content

I'm using the Bing Maps API version 7. I have 4 EntityCollections that I draw on the map: 1 for a set of pushpins, 1 for a set of infoboxes associated with those pushpins, 1 for a set of polylines, and 1 for a set of infoboxes associated with those polylines. 我正在使用Bing Maps API版本7.我在地图上绘制了4个EntityCollections:1表示一组图钉,1表示与这些图钉关联的一组信息框,1表示一组折线,1表示与这些折线相关联的一组信息框。 I use setInterval to attempt to refresh the content of the polylines and their associated infoboxes periodically. 我使用setInterval尝试定期刷新折线及其相关信息框的内容。 I clear the entity collections for the polylines like this: 我清除折线的实体集合,如下所示:

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

and then just reinitialize them before populating them again: 然后在重新填充它们之前重新初始化它们:

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

This functionality works, however, my pushpin infoboxes stop displaying after the refresh is completed. 但是,此功能有效,我的图钉信息框在刷新完成后停止显示。

The pushpins and their associated infoboxes are left untouched during the refresh so why do my pushpin infoboxes stop displaying? 在刷新过程中,图钉及其相关的信息框保持不变,为什么我的图钉信息框停止显示? The click event of the pushpin that displays the infobox still fires but nothing gets displayed. 显示信息框的图钉的点击事件仍会触发,但不会显示任何内容。

Executing the single statement map.entities.clear(mapSegments) seems to mess up another EntityCollection that it's not associated with. 执行单个语句map.entities.clear(mapSegments)似乎搞乱了与之无关的另一个EntityCollection。

In the Bing documentation when you call map.entities.clear(); 在Bing文档中调用map.entities.clear(); it will clear all of the entities in the map.entities array. 它将清除map.entities数组中的所有实体。 It does not look like the clear() method excepts any perimeters parameters. 它看起来不像clear()方法除了任何 周长 参数。

You can try one of these methods 您可以尝试其中一种方法

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

or 要么

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

or a more complete example would be 或者更完整的例子

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');

Just replace the "instanceof Microsoft.Maps.Polyline" with the type of entity you want to remove... 只需将“instanceof Microsoft.Maps.Polyline”替换为您要删除的实体类型......

if you want to look at the documentation it is here https://msdn.microsoft.com/en-us/library/gg427616.aspx 如果你想查看它在这里的文档https://msdn.microsoft.com/en-us/library/gg427616.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM