leaflet-layer-tree-plugin icon indicating copy to clipboard operation
leaflet-layer-tree-plugin copied to clipboard

Folium Map with leaflet-layer-tree-plugin

Open rcs529 opened this issue 4 years ago • 3 comments

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.

rcs529 avatar Sep 24 '20 18:09 rcs529

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)

bambrikii avatar Sep 28 '20 01:09 bambrikii

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 .

rcs529 avatar Sep 28 '20 18:09 rcs529

Any solution?

gonzalohdominguez avatar Apr 29 '21 20:04 gonzalohdominguez