diff --git a/folium/folium.py b/folium/folium.py index a9e396613..91efeb1b0 100644 --- a/folium/folium.py +++ b/folium/folium.py @@ -8,7 +8,7 @@ from typing import Any, List, Optional, Sequence, Union from branca.element import Element, Figure, MacroElement -from jinja2 import Environment, PackageLoader, Template +from jinja2 import Template from folium.elements import JSCSSMixin from folium.map import FitBounds, Layer @@ -22,9 +22,6 @@ validate_location, ) -ENV = Environment(loader=PackageLoader("folium", "templates")) - - _default_js = [ ("leaflet", "https://cdn.jsdelivr.net/npm/leaflet@1.9.3/dist/leaflet.js"), ("jquery", "https://code.jquery.com/jquery-1.12.4.min.js"), @@ -262,7 +259,6 @@ def __init__( ): super().__init__() self._name = "Map" - self._env = ENV self._png_image: Optional[bytes] = None self.png_enabled = png_enabled diff --git a/folium/raster_layers.py b/folium/raster_layers.py index 411b671f4..ebe9ac99d 100644 --- a/folium/raster_layers.py +++ b/folium/raster_layers.py @@ -122,7 +122,6 @@ def __init__( name=self.tile_name, overlay=overlay, control=control, show=show ) self._name = "TileLayer" - self._env = ENV tiles_flat = "".join(tiles.lower().strip().split()) if tiles_flat in {"cloudmade", "mapbox", "mapboxbright", "mapboxcontrolroom"}: @@ -133,14 +132,14 @@ def __init__( "argument. See the documentation of the `TileLayer` class." ) templates = list( - self._env.list_templates(filter_func=lambda x: x.startswith("tiles/")) + ENV.list_templates(filter_func=lambda x: x.startswith("tiles/")) ) tile_template = "tiles/" + tiles_flat + "/tiles.txt" attr_template = "tiles/" + tiles_flat + "/attr.txt" if tile_template in templates and attr_template in templates: - self.tiles = self._env.get_template(tile_template).render() - attr = self._env.get_template(attr_template).render() + self.tiles = ENV.get_template(tile_template).render() + attr = ENV.get_template(attr_template).render() else: self.tiles = tiles if not attr: diff --git a/tests/test_folium.py b/tests/test_folium.py index 85132e586..d320605f4 100644 --- a/tests/test_folium.py +++ b/tests/test_folium.py @@ -19,6 +19,7 @@ import folium from folium import TileLayer from folium.features import Choropleth, GeoJson +from folium.raster_layers import ENV rootpath = os.path.abspath(os.path.dirname(__file__)) @@ -120,8 +121,8 @@ def test_builtin_tile(self): tiles = "".join(tiles.lower().strip().split()) url = "tiles/{}/tiles.txt".format attr = "tiles/{}/attr.txt".format - url = m._env.get_template(url(tiles)).render() - attr = m._env.get_template(attr(tiles)).render() + url = ENV.get_template(url(tiles)).render() + attr = ENV.get_template(attr(tiles)).render() assert m._children[tiles].tiles == url assert htmlsafe_json_dumps(attr) in m._parent.render()