2
votes

I have an OpenLayers + Bing mapping application that shows hazardous waste sites. A user can click a link to toggle a site's subsites on the map.

When I toggle the subsites off (which are points on a Vector layer) by calling destroyFeatures() on the layer, they disappear as expected. However, if I zoom in or out on the map, certain of the subsites reappear. This doesn't happen when moving the map, just zooming.

The ones that mysteriously reappear are coincident sites, i.e. two sites with exact same coordinates. Both get destroyed, and both reappear.

Why would these get destroyed from the layer, then reappear when zooming?

(OpenLayers version is 2.11)

3
This happens to me too. Have you found a solution?Yun

3 Answers

1
votes

Try this, it worked for me

layer.removeAllFeatures();
layer.destroyFeatures();//optional
layer.addFeatures([]);
0
votes

Keep in mind that destroyFeatures() changes index of objects in vector. If you use indexes in your code, this may cause problems.

0
votes

Are you sure you send ALL features as a parameter to destroyFeatures() method? An easier way to remove everything is just to call removeAllFeatures() method. If you want to hide and show features when user toggles subsite then it's even better to use show() and hide() methods on vector layer.