gpt4 book ai didi

javascript - 刷新 Bing map API 内容

转载 作者:行者123 更新时间:2023-11-29 10:37:27 25 4
gpt4 key购买 nike

我使用的是 Bing Maps API 版本 7。我在 map 上绘制了 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() 方法,除了任何 perimeters 参数。

您可以尝试其中一种方法

//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”替换为您要删除的实体类型...

if you want to look at the documentation it is herehttps://msdn.microsoft.com/en-us/library/gg427616.aspx

关于javascript - 刷新 Bing map API 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34456034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com