I am trying to dynamically add features to a vector layer, and use cluster strategy to group those features accordingly.

I am able to do this for the first set of data that gets loaded on the map.

It looks like below code works only the first time - vectorLayer.addFeatures(vectordArray);

when i try to call the same addFeatures again with a new set of vectors, I dont see the new vectors. There are no errors either.

Anyone faced a situation like this? I am looking to dynamically add vectors and use CluseterStrategy.

  • 1
    is this about openlayers? i think so. pls specify this at least your tags...
    – urcm
    Commented Sep 13, 2012 at 13:44
  • added openlayers tag.
    – Mapperz
    Commented Sep 13, 2012 at 13:57

2 Answers 2


did you try to update your vector layer after this vectorLayer.addFeatures(vectordArray) as shown at following code:


if this not work try to get all features from map into an array and then merge them with your new array then add them to map as if you are adding first time into map...


beside this checking out this example here may be helpful for you... it is working on the same principle as your will.

i hope it helps you...

  • Aragon, thanks for you response, Appreciate it. I browsed around and found a neat custom implementation here. Also, for anyone else trying this out - vectorLayer.redraw(); did not work for me. Removing the features removeFeatures and adding them again addFeatures worked, but the refresh time lag is a concern here. The custom implementation at the link is very usable for fast reCluster when adding new features. Cheers!
    – Shan
    Commented Sep 13, 2012 at 15:49

After a bunch of experiments with API I found a way that can be used to add and remove the features on layer dynamically. But I should warn that this way is not proper according to OL API and I do not recommend to use it, because it may cause a bugs with some other OL components. For example layer.onFeatureInsert() event is not being invoken while using it.

The way is:

// to add a feature
var fId = newFeature.id;

// to remove it
featureToRemove = layer.getFeatureById(fId);  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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