简体   繁体   English

Bing Maps API - 删除引脚

[英]Bing Maps API - Remove Pins

I've got a select box which allows the user to toggle between various lists which populate a bing map with points. 我有一个选择框,允许用户在各种列表之间切换,这些列表用点填充bing地图。

However when they select a different location from the list I need to remove the old pins before plotting the new ones. 但是,当他们从列表中选择不同的位置时,我需要在绘制新的引脚之前删除旧的引脚。

Any ideas, the API docs don't seem to cover it? 任何想法,API文档似乎都没有涵盖它?

To remove a single pushpin (or any other kind of entity) from the map, you need to call the remove() method of the entitycollection that contains the pin: http://msdn.microsoft.com/en-us/library/gg427616.aspx . 要从地图中删除单个图钉(或任何其他类型的实体),您需要调用包含该图钉的entitycollection的remove()方法: http//msdn.microsoft.com/en-us/library/ gg427616.aspx Or, if you want to reference the entity by index, use removeAt() instead. 或者,如果要按索引引用实体,请改用removeAt()。

To clear all entities from a collection, call the clear() method instead. 要清除集合中的所有实体,请调用clear()方法。

javascript中的deleteAllShapes()将执行此操作,我现在正在处理相同的事情并且它可以正常工作,

Just to make things clear. 只是为了说清楚。 Cause it to me a while to figure it out. 因为我有一段时间想出来。

Create a push pin in JavaScipt: 在JavaScipt中创建一个推针:

var thisPin;
var location new Microsoft.Maps.Location(YourLatitude, Your.longitude);


thisPin = new Microsoft.Maps.Pushpin(location, {
    icon: 'path to image',
    anchor: new Microsoft.Maps.Point(YourOffsetX, YourOffsetY)
});
map.entities.push(thisPin);

To remove the pin, you must still have the pointer thisPin pointing to that specific pin. 要移除引脚,您仍必须将指针thisPin指向该特定引脚。

map.entities.remove(thisPin);

This method is not well documented in the samples. 该方法在样本中没有很好地记录。

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

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