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