[英]Refreshing Bing Maps API Content
我正在使用Bing Maps API版本7.我在地圖上繪制了4個EntityCollections:1表示一組圖釘,1表示與這些圖釘關聯的一組信息框,1表示一組折線,1表示與這些折線相關聯的一組信息框。 我使用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。
在Bing文檔中調用map.entities.clear(); 它將清除map.entities數組中的所有實體。 它看起來不像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/en-us/library/gg427616.aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.