简体   繁体   中英

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.

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?

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 . Or, if you want to reference the entity by index, use removeAt() instead.

To clear all entities from a collection, call the clear() method instead.

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

Just to make things clear. Cause it to me a while to figure it out.

Create a push pin in 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.

map.entities.remove(thisPin);

This method is not well documented in the samples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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