Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
is this about openlayers? i think so. pls specify this at least your tags... – Aragon Sep 13 '12 at 13:44
added openlayers tag. – Mapperz Sep 13 '12 at 13:57

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...

share|improve this answer
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 Sep 13 '12 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 =;

// to remove it
featureToRemove = layer.getFeatureById(fId);  
share|improve this answer

Your Answer


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.