I have a quite complex webapp with a lot of data on a map. Except the basemap, the data of each layers are coming from AJAX queries, witch's responses are formatted as GeoJSON object -- up to this works fine. (Each of this responses -- so each GeoJSON object -- can be more than 1 Mb.)

With checkboxes I'd like to show or hide the datasets.

I prepare each layer in this way: var layer_1 = L.geoJSON(null, { style: style_1, pane: "pane_1" }).addTo(myMap);.

I can add data: layer_1.addData(data_1.responseJSON);.

If I'd like to hide this dataset, is it possible somehow to remove only this dataset from layer_1 (as "opposite" of addData()), or the only way is to myMap.removeLayer(layer_1);, and then create the layer again?


1 Answer 1


On hand of these answer https://gis.stackexchange.com/a/218948/171957 it's possible to empty the dataset with jsonLayer.clearLayers().

  • This is not correct answer to the question. Method .clearLayers() clears all the features from the layer, but question is how to hide/remove only particular subset of layers.
    – TomazicM
    Dec 12, 2020 at 20:18

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.