I've this:

var AllProjectArray = L.geoJSON();

The using addData()


Now I've my AllProjectArray filled and working

Now I want to remove from AllProjectArray one specific feature, something like AllProjectArray.removeData(thisfeatures).

I've tried with


whit no luck. Where I'm wrong?


1 Answer 1


GeoJSON layer is in Leaflet a group layer where each feature is member layer of this group. You can iterate through all members by eachLayer group layer method.

If you want to remove particular feature/member from GeoJSON layer, you have to somehov identify it, by id or some property. Let's say we want to remove feature with particular feature id.

One possibilty is that each time we want to remove feature, we loop through all members od GeoJSON layer and remove the one with desired id. Function for removing feature could look something like this:

function removeFeature(layerGroup, featureId) {
    if (layer.feature.id == featureId) {

We would then remove feature with desired id by call

removeFeature(AllProjectArray, id);

To avoid looping through all features at each remove, we can create object which connects feature id with internal Leaflet layer id:

var AllProjectArray = L.geoJSON();

var layerID = {};
AllProjectArray.eachLayer(function(layer) {
  layerID[layer.feature.id] = AllProjectArray.getLayerId(layer);

Removing feature with desired id is then done without any iteration with simple call:

  • Thanks for elucidation
    – Taras
    Commented Nov 14, 2019 at 21:39
  • Thanks, I managed to solve my problem with your suggestion!
    – Cenere Blu
    Commented Nov 15, 2019 at 12:12

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.