martinfleis / geopandas-view

Interactive exploration of GeoPandas GeoDataFrames
BSD 3-Clause "New" or "Revised" License
29 stars 4 forks source link

DOC: document layer control #12

Closed martinfleis closed 3 years ago

martinfleis commented 3 years ago

folium.LayerControl() works only after all layers are in and is removed if a new layer is added to a map, so it is not easy to have it within view. We should optimally figure out a way how to add layer control without the necessity to call folium.LayerControl() after view() manually.

Sangarshanan commented 3 years ago

I did not get the full extent of this, Would there be support for both layer groups and layer control ? I guess that can get a little complicated

martinfleis commented 3 years ago

This bit of code generates layer control (you can turn on and off layers).

m = view(world, name='world')
view(cities, name='cities', m=m)
folium.LayerControl().add_to(m)
m

Screenshot 2021-02-14 at 10 24 20

I tried to hook it into view but it does not seem to be possible. Layer control needs to be added after all layers are in the map, which we cannot control from within view.

Not sure what layer groups are :).

Sangarshanan commented 3 years ago

Not sure what layer groups are :).

Oops though I linked it, I was referring to this plugin https://nbviewer.jupyter.org/github/python-visualization/folium/blob/master/examples/Plugins.ipynb#FeatureGroupSubGroup

I tried to hook it into view but it does not seem to be possible. Layer control needs to be added after all layers are in the map, which we cannot control from within view.

Gotcha, I just noticed there is a map arg you can pass to view 😅 so I guess you can call LayerControl inside view only when you know it's gonna be the final layer that you add, and if someone further adds a new layer then they would need to explicitly set control=False or it would just delete the whole LayerControl thing (adding onto your example)

m = view(world, name='world')
view(cities, name='cities', m=m)
folium.LayerControl().add_to(m)
folium.TileLayer('Stamen Terrain',control=False).add_to(m)
m

Does this seem like a feature that people should use directly through folium? or there could be layercontrol arg which would also have its own set of kwargs like ZIndex

martinfleis commented 3 years ago

or there could be layercontrol arg which would also have its own set of kwargs like ZIndex

I am not sure if we'll be able to do this in reality.

Does this seem like a feature that people should use directly through folium?

This may be fine, we just need to make sure to document this (we should maybe start a notebook working as a user guide).