I am using OpenLayers.Strategy.AnimatedCluster in my application in order to cluster and show points to the end-user. The example is here. All points are located in concrete vector layer. I need to remove all features from that vector layer, but when I use removeAllFeatures or destroyFeatures then it removes clusters only from the concrete zoom level and if I zoom in and then back I see all my clusters again. How can completely remove them from the map?


Short answer is:

// Assuming, that clustering strategy is first strategy in your layer
vectorLayer.strategies[0].resolution = -1;

UPDATE: changing resolution property of clustering strategy will force addFeatures() to redraw features. If you don't do it, features in screen will stay unchanged, until you zoom in or out.

When you are using Clustering strategy, each addFeatures() destroys all previous features. With this command you are destroying old ones and you don't add any new ones.

Clustering strategy holds original features in cache. When you zoom, all objects (features, that represent clusters) in vector layer are destroyed and new clusters are generated from cached features. removeAllFeatures and destroyFeatures remove only clusters, but don't affect original features in cache.

  • Great solution for the problem - thank you, it perfectly works! – Dmitri Dec 11 '12 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.