leaflet-layer-tree-plugin
leaflet-layer-tree-plugin copied to clipboard
Folium Map with leaflet-layer-tree-plugin
Does this work within a folium python script? If so, how would you go about implementing it? Let's say I have 3 geojson layers and I want them to all be under one (collapsible) group layer called "Boundaries" with the ability to check on the group layer and the individual sublayers. Please let me know if you have any ideas.
i have no solid experience with python and folium, unfortunately. researched a bit, it should be possible to implement a custom plugin similar to any of those available in https://github.com/python-visualization/folium/tree/master/folium/plugins
from branca.element import CssLink, Figure, JavascriptLink, MacroElement
...
_default_js = [
('Layer_Tree_Control_js', 'https://raw.githubusercontent.com/bambrikii/leaflet-layer-tree-plugin/master/src/leaflet-layer-tree-control.js'),
('Layer_Tree_Control_Zoom_js', 'https://raw.githubusercontent.com/bambrikii/leaflet-layer-tree-plugin/master/src/leaflet-layer-tree-control-wfs-zoom.js')
]
_default_css = [
('Layer_Tree_Control_css', 'https://raw.githubusercontent.com/bambrikii/leaflet-layer-tree-plugin/master/src/leaflet-layer-tree-control.css')
]
class LayerTreeControl(MacroElement):
_template = Template("""
...
def __init__(self, options, **kwargs):
super(LayerTreeControl, self).__init__()
self._name = 'LayerTreeControl'
self.layerTree = options['layerTree']
self.layerTreeBuilder = options['layerTreeBuilder']
...
def render(self, **kwargs):
...
and applying the new plugin in application code
from LayerTreeControl import LayerTreeControl
...
m = folium.Map()
...
LayerTreeControl({
'layerTree': [...],
'layerTreeBuilder': [...]
}).add_to(m)
Thanks... I tried just adding this to my current script and it doesn't work. What all do I need to add to it as constructed to get it to work?
On Sun, Sep 27, 2020 at 8:06 PM bambrikii [email protected] wrote:
i have no solid experience with python and folium, unfortunately. researched a bit, it should be possible to implement a custom plugin similar to any of those available in https://github.com/python-visualization/folium/tree/master/folium/plugins
from branca.element import CssLink, Figure, JavascriptLink, MacroElement ..._default_js = [ ('Layer_Tree_Control_js', 'https://raw.githubusercontent.com/bambrikii/leaflet-layer-tree-plugin/master/src/leaflet-layer-tree-control.js'), ('Layer_Tree_Control_Zoom_js', 'https://raw.githubusercontent.com/bambrikii/leaflet-layer-tree-plugin/master/src/leaflet-layer-tree-control-wfs-zoom.js') ]_default_css = [ ('Layer_Tree_Control_css', 'https://raw.githubusercontent.com/bambrikii/leaflet-layer-tree-plugin/master/src/leaflet-layer-tree-control.css') ] class LayerTreeControl(MacroElement):
_template = Template("""
...
def __init__(self, options, **kwargs): super(LayerTreeControl, self).__init__() self._name = 'LayerTreeControl' self.layerTree = options['layerTree'] self.layerTreeBuilder = options['layerTreeBuilder']
...
def render(self, **kwargs):
...
and applying the new plugin in application code
from LayerTreeControl import LayerTreeControl ...m = folium.Map() ...LayerTreeControl({ 'layerTree': [...], 'layerTreeBuilder': [...] }).add_to(m)
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bambrikii/leaflet-layer-tree-plugin/issues/17#issuecomment-699717886, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQNONHX7ORPPVPOIBALAIUTSH7OSPANCNFSM4RYTWYDQ .
Any solution?