Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Short answer is:

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

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.

share|improve this answer
    
Great solution for the problem - thank you, it perfectly works! –  Bob Dec 11 '12 at 19:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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