Reputation: 1686
I was wondering if it is possible to limit the number of features you an draw on a vectorylayer. If I already have a polygon drawn, and go to draw another it will delete the first feature.
If not is it possible to add a listener to the vector layer, so that I can erase all features when clicking to draw?
Thanks!!!
Upvotes: 0
Views: 2391
Reputation: 89
you can make a button and when you click on it, it will remove all the features in your vector layer :
map.layers[1].removeAllFeatures();
Here 1 is the id of my layer (my vector layer is the second one after an OSM layer)
Good Luck !
Upvotes: 0
Reputation: 3856
You can't set max number of features on Vector Layer, but it has a whole lot of events where you can inject your own logic. Here are available events:
"beforefeatureadded", "beforefeaturesadded",
"featureadded", "featuresadded", "beforefeatureremoved",
"beforefeaturesremoved", "featureremoved", "featuresremoved",
"beforefeatureselected", "featureselected", "featureunselected",
"beforefeaturemodified", "featuremodified", "afterfeaturemodified",
"vertexmodified", "vertexremoved", "sketchstarted",
"sketchmodified", "sketchcomplete", "refresh"
You can use "beforefeatureadded" for instance:
your_vectror_layer.events.on({'beforefeatureadded': function(){
//Remove first feature or whatever you want to do
}});
Upvotes: 1