question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GeoJSON layer remove/replace data

See original GitHub issue

The 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:closed
  • Created 11 years ago
  • Comments:20 (8 by maintainers)

github_iconTop GitHub Comments

11reactions
mournercommented, Feb 19, 2013

Yeah, currently such use cases are handled like this:

layer.clearLayers(); // inherited from LayerGroup
layer.addData(newData);

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.

2reactions
perliedmancommented, Mar 9, 2014

Note that it is possible to remove a single feature from a GeoJSON layer. As @mourner mentions above, L.GeoJSON inherits from L.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 use L.LayerGroup’s removeLayer 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found