Skip to content

Commit 290252f

Browse files
authored
cleanup fit_bounds.js template (#1920)
1 parent e6c5779 commit 290252f

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

folium/templates/fit_bounds.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/test_folium.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import pandas as pd
1313
import pytest
1414
import xyzservices.providers as xyz
15-
from jinja2 import Environment, PackageLoader
15+
from jinja2 import Template
1616
from jinja2.utils import htmlsafe_json_dumps
1717

1818
import folium
@@ -69,7 +69,21 @@ def setup_method(self):
6969
font_size="1.5rem",
7070
attr=attr,
7171
)
72-
self.env = Environment(loader=PackageLoader("folium", "templates"))
72+
self.fit_bounds_template = Template(
73+
"""
74+
{% if autobounds %}
75+
var autobounds = L.featureGroup({{ features }}).getBounds()
76+
{% if not bounds %}
77+
{% set bounds = "autobounds" %}
78+
{% endif %}
79+
{% endif %}
80+
{% if bounds %}
81+
{{this._parent.get_name()}}.fitBounds({{ bounds }},
82+
{{ fit_bounds_options }}
83+
);
84+
{% endif %}
85+
"""
86+
)
7387

7488
def test_init(self):
7589
"""Test map initialization."""
@@ -385,8 +399,7 @@ def test_fit_bounds(self):
385399
][0]
386400
out = self.m._parent.render()
387401

388-
fit_bounds_tpl = self.env.get_template("fit_bounds.js")
389-
fit_bounds_rendered = fit_bounds_tpl.render(
402+
fit_bounds_rendered = self.fit_bounds_template.render(
390403
{
391404
"bounds": json.dumps(bounds),
392405
"this": fitbounds,
@@ -406,8 +419,7 @@ def test_fit_bounds_2(self):
406419
][0]
407420
out = self.m._parent.render()
408421

409-
fit_bounds_tpl = self.env.get_template("fit_bounds.js")
410-
fit_bounds_rendered = fit_bounds_tpl.render(
422+
fit_bounds_rendered = self.fit_bounds_template.render(
411423
{
412424
"bounds": json.dumps(bounds),
413425
"fit_bounds_options": json.dumps(

0 commit comments

Comments
 (0)