I have a bunch of Point data that refreshes every few minutes. To render these points, I have created the markers as OpenLayers.Feature.Vector Objects and added them to my Vector layer. The layer gets added to the map object, and I can see the markers when the page loads.

When the data refreshes on my local server, some points from the previous dataset may have disappeared and some new points may have been added. I am just given a large list of points to render every refresh.

Because of this, I need to clear the vector layer of all current markers and then re-render the map with the new dataset.

Also, is there a way to delete specific markers given just a lat,lng? Or is there some way to reference them and delete it from the vectory layer?

How do I clear the vector layer of all markers and how do I delete specific points?

2 Answers 2


Clearing is done with removeAllFeatures:


You can remove any that you've stored with removeFeatures:

var aFeature;
//set aFeature somehow 

If you need to find them by location (lat long) I'd look into selecting the features with a spatial filter then removing them with removeFeatures.


I wrote this function that works for me:

        function clearMapV() {
            features = [];
            features.length = 0;
            drawValues(); // call function to re-create markers

Or, if you're using markers just use


Where markers is your markers array

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.