-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GeoJSON layer remove/replace data #1416
Comments
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. |
This layers-being-layer-groups thing is a bit unclear to me: is there documentation of how it's supposed to work? Basically layers = features? layer.clearLayers(); // should this be documented in the geojson layer docs, since it does something else here? |
GeoJSON layer works exactly like a group, it just adds a couple of GeoJSON-related methods and overrides constructor to accept GeoJSON object. When you call addData, it converts objects to basic Leaflet layers and adds them to itself. When you call |
Having the possibility to manipulate GeoJson data in Leaflet core would be a very useful feature. It should be a 2-way process. I already suggested this some months ago: http://leaflet.uservoice.com/forums/150880-ideas-and-suggestions-for-leaflet/suggestions/3121234-convert-vectors-layers-to-geojson |
I want to say that I too would benefit from this feature. Either being able to remove data, or being able to simply remove all the data from the geoJSON layer. For a dynamic map where you are replacing the geoJSON data, this functionality would make things better. |
If I could, +1 on this. I'm currently pulling my hair out trying to manipulate / clear geojson data on the map without hacking around core functionality leaflet. |
👍 |
|
I realize I was not on HEAD. |
yep. It's Work on GeoJSON layer for me |
+1 to be able to remove one feature at a time and not only clear all. |
I fully agree with all of the previous comments. |
Note that it is possible to remove a single feature from a GeoJSON layer. As @mourner mentions above, Add an 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. |
Thanks Per. What I'm probably missing is the understanding of the relationship between features and layers in a GeoJSON layer. Is it 1:1? If I add, say, 10 Points, to the layer with addData, do 10 layers get created in the LayerGroup? |
@andreamartelli yes, exactly. For complex geometries, like a GeometryCollection, it will in fact return a FeatureGroup, where each subfeature has its own layer. You can see how it's done in GeoJSON.js / |
@perliedman yep, the core point is that this kind of interface is doable as an abstraction layer, and the current interface is all right. I'll make a note to do it at some point. |
|
Ah, never mind. Figured out that it is working. |
Here is the code to the solution I implemented. I made a dictionary of all the layers that I could look up and remove whenever necessary.
|
I think leaflet-ajax |
The
L.geoJson
API seems to be missing an API that would make it symmetric:The text was updated successfully, but these errors were encountered: