[Python] How serve JS locally with folium JSCSSMixin class?

Discussão em 'Python' iniciado por Stack, Março 27, 2025.

  1. Stack

    Stack Membro Participativo

    I have modified ja/css of Leaflet.Measure plugin, and I want to use them in folium.

    So, I took https://github.com/python-visualization/folium/blob/main/folium/plugins/measure_control.py as an example:

    from jinja2 import Template
    from folium.elements import JSCSSMixin
    from folium.utilities import parse_options


    class Measure(JSCSSMixin):
    _template = Template(
    """
    {% macro script(this, kwargs) %}
    var {{ this.get_name() }} = new L.control.measure(
    {{ this.options|tojson }});
    {{this._parent.get_name()}}.addControl({{this.get_name()}});
    {% endmacro %}
    """
    ) # noqa

    default_js = [
    (
    "leaflet_measure_js",
    "https://cdn.jsdelivr.net/gh/banderlog/Leaflet.Measure@refs/heads/master/src/leaflet.measure.js"
    )
    ]

    default_css = [
    (
    "leaflet_measure_css",
    "https://cdn.jsdelivr.net/gh/banderlog/Leaflet.Measure@refs/heads/master/src/leaflet.measure.css"
    )
    ]

    def __init__(
    self,
    **kwargs
    ):
    super().__init__()
    self._name = "Measure"

    self.options = parse_options(
    **kwargs
    )


    It works, but I want somehow put local links and serve them locally (like file:///) because I do not want to use external providers.

    I know how to do it with flask/jinja2, but I have no idea how to do it with folium/branca

    Continue reading...

Compartilhe esta Página