问题
I'm trying to show/hide some GeoJSON data on an overlay layer. I've the data as an object, but not at some server.
If I use the overlay type 'geoJSON', I'm getting a Eror:
A base layer must have an url
How do I show/hide my data using the overlay show/hide?
The mixed-layers-overlays-geojson-example is not working for me because it uses remote (xyz-json) data.
Additional information: I've the data in some object that I'm intending to modify/update based on user interaction.
PS: it's probably very simple problem
Edit: I made a plunker of the situation. It shows the dynamic adding and removing of a path object and some empty functions for the geoJSON objects.
回答1:
I (my collegue) found some ugly answer: accessing the leaflet layers directly.
I forked the plunker from the description and added some functions. See my functions transformGeoObjToPath
and geoToLeafletLayer
. In our application we use layers of type 'featureGroup' for additional stuff like selecting, but this is not in the 'solution' example
But the solution is not 'beautiful', because it accesses the leaflet directly.
来源:https://stackoverflow.com/questions/32628893/showing-geojson-data-on-overlay