Mateusz Kruk
Mateusz Kruk

Reputation: 29

Leaflet draw delete features with property

Is it possible to delete multiple features from geojson at once by checking property value?

Using for example code below or using Leaflet draw?

function deleteArea() {
var layers = featureGroup.getLayers();
for (var i = 0; i < layers.length; i++) {

        if (layers[i].feature.properties.N == 1)
{
        "DELETE?" layer[i];
        };
}
};

I have big map and some markers have property: feature.properties.N=1. I can delete them using leaflet draw clicking one by one because I changed marker to red for those layers. But it takes some time.. Is it possible to to this at once?

enter image description here

Thank you very much for your time !

Upvotes: 0

Views: 605

Answers (1)

Falke Design
Falke Design

Reputation: 11338

Sure you can simply remove the markers from the map / featuregroup with layer.removeFrom(featureGroup)

function deleteArea() {
var layers = featureGroup.getLayers();
for (var i = 0; i < layers.length; i++) {
        if (layers[i].feature.properties.N == 1){
            layer[i].removeFrom(featureGroup);
        };
}
};

PS: I prefer to use Leaflet-Geoman because it is more modern and is still being supported and gets new features

Upvotes: 1

Related Questions