GeoJSON layer remove/replace data
See original GitHub issueThe L.geoJson
API seems to be missing an API that would make it symmetric:
var layer = L.geoJson();
// we have this
layer.addData(foo);
// we don't have this
layer.removeData(foo);
// or this
layer.getData(foo);
layer.replaceData(foo);
// and if we had this
layer.data(foo); // set the data to foo
layer.data(); // get all data
// we could implement the rest as sugar
Issue Analytics
- State:
- Created 11 years ago
- Comments:20 (8 by maintainers)
Top Results From Across the Web
How do I remove a Leaflet GeoJSON layer when a user clicks it?
I can either do this by removing the layer from the map or clearing the layer and adding new data; it seems either...
Read more >How do I remove a Leaflet GeoJSON layer ... - Google Groups
I can either do this by removing the layer from the map or clearing the layer and adding new data; it seems either...
Read more >How to remove features from a Leaflet GeoJSON layer?
addData(data) : Adds a GeoJSON object to the layer. Is it possible to remove all features from the GeoJSON layer, without destroying the...
Read more >GeoJSONLayer | ArcGIS Maps SDK for JavaScript 4.25
The GeoJSONLayer class is used to create a layer based on GeoJSON. GeoJSON is a format for encoding a variety of geographic data...
Read more >Data Layer: Drag and Drop GeoJSON | Maps JavaScript API
Download a sample GeoJSON file to test dragging from the device. For more information about how to work with the map data layer,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, currently such use cases are handled like this:
So GeoJSON class currently acts like a one-way converter of data. But I agree that being able to remove specific objects would be useful.
Note that it is possible to remove a single feature from a GeoJSON layer. As @mourner mentions above,
L.GeoJSON
inherits fromL.LayerGroup
, which supports removing single layers.Add an
onEachFeature
handler for the GeoJSON layer to keep track of the layers associated with a feature (putting them in a map where the feature is the key and the layer is the value, for example), and then useL.LayerGroup
’sremoveLayer
to remove them.A simplistic example of this: http://jsfiddle.net/MLuc3/3/
@mourner any particular reason this issue is still open? Any plans on reworking the API? I’d vore for closing.