Thursday 28 December 2017

How to remove features from a Leaflet GeoJSON layer?


In a Leaflet map, it is possible to add features to a GeoJSON layer using the addData method:



L.geoJSON: Creates a GeoJSON layer. Optionally accepts an object in GeoJSON format (you can alternatively add it later with addData method)


addData(data): Adds a GeoJSON object to the layer.



Is it possible to remove all features from the GeoJSON layer, without destroying the layer and recreating it?



Answer



It seems that GeoJSON extends FeatureGroup, which extends LayerGroup, which has a method clearLayers().



This means that jsonLayer.clearLayers() can be used to remove the features from a GeoJSON layer.


http://leafletjs.com/reference-1.0.2.html#layergroup


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...