Reputation: 698
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. I use setInterval to attempt to refresh the content of the polylines and their associated infoboxes periodically. 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.
Upvotes: 3
Views: 1245
Reputation: 1826
In the Bing documentation when you call map.entities.clear(); it will clear all of the entities in the map.entities array. It does not look like the clear() method excepts any perimeters parameters.
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...
Upvotes: 3