Skip to content

Commit 1db8558

Browse files
committed
Second iteration of the tests
1 parent 758e848 commit 1db8558

16 files changed

+261
-23
lines changed

folium/features.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
)
3535
from branca.utilities import color_brewer
3636

37+
import folium.map
3738
from folium.elements import JSCSSMixin
3839
from folium.folium import Map
39-
from folium.map import FeatureGroup, Icon, Layer, Marker, Popup, Tooltip
4040
from folium.template import Template
4141
from folium.utilities import (
4242
JsCode,
@@ -60,7 +60,7 @@
6060
from folium.vector_layers import Circle, CircleMarker, PolyLine, path_options
6161

6262

63-
class RegularPolygonMarker(JSCSSMixin, Marker):
63+
class RegularPolygonMarker(JSCSSMixin, folium.map.Marker):
6464
"""
6565
Custom markers using the Leaflet Data Vis Framework.
6666
@@ -109,8 +109,8 @@ def __init__(
109109
number_of_sides: int = 4,
110110
rotation: int = 0,
111111
radius: int = 15,
112-
popup: Union[Popup, str, None] = None,
113-
tooltip: Union[Tooltip, str, None] = None,
112+
popup: Union[folium.map.Popup, str, None] = None,
113+
tooltip: Union[folium.map.Tooltip, str, None] = None,
114114
**kwargs: TypePathOptions,
115115
):
116116
super().__init__(location, popup=popup, tooltip=tooltip)
@@ -310,7 +310,7 @@ def __init__(
310310
def render(self, **kwargs):
311311
"""Renders the HTML representation of the element."""
312312
parent = self._parent
313-
if not isinstance(parent, (Figure, Div, Popup)):
313+
if not isinstance(parent, (Figure, Div, folium.map.Popup)):
314314
raise TypeError(
315315
"VegaLite elements can only be added to a Figure, Div, or Popup"
316316
)
@@ -480,7 +480,7 @@ def _embed_vegalite_v1(self, figure: Figure, parent: TypeContainer) -> None:
480480
)
481481

482482

483-
class GeoJson(Layer):
483+
class GeoJson(folium.map.Layer):
484484
"""
485485
Creates a GeoJson object for plotting into a Map.
486486
@@ -696,12 +696,12 @@ def __init__(
696696
control: bool = True,
697697
show: bool = True,
698698
smooth_factor: Optional[float] = None,
699-
tooltip: Union[str, Tooltip, "GeoJsonTooltip", None] = None,
699+
tooltip: Union[str, folium.map.Tooltip, "GeoJsonTooltip", None] = None,
700700
embed: bool = True,
701701
popup: Optional["GeoJsonPopup"] = None,
702702
zoom_on_click: bool = False,
703703
on_each_feature: Optional[JsCode] = None,
704-
marker: Union[Circle, CircleMarker, Marker, None] = None,
704+
marker: Union[Circle, CircleMarker, folium.map.Marker, None] = None,
705705
**kwargs: Any,
706706
):
707707
super().__init__(name=name, overlay=overlay, control=control, show=show)
@@ -715,7 +715,7 @@ def __init__(
715715
self.highlight = highlight_function is not None
716716
self.zoom_on_click = zoom_on_click
717717
if marker:
718-
if not isinstance(marker, (Circle, CircleMarker, Marker)):
718+
if not isinstance(marker, (Circle, CircleMarker, folium.map.Marker)):
719719
raise TypeError(
720720
"Only Marker, Circle, and CircleMarker are supported as GeoJson marker types."
721721
)
@@ -744,11 +744,11 @@ def __init__(
744744
self.highlight_map: dict = {}
745745
self.feature_identifier = self.find_identifier()
746746

747-
if isinstance(tooltip, (GeoJsonTooltip, Tooltip)):
747+
if isinstance(tooltip, (GeoJsonTooltip, folium.map.Tooltip)):
748748
self.add_child(tooltip)
749749
elif tooltip is not None:
750-
self.add_child(Tooltip(tooltip))
751-
if isinstance(popup, (GeoJsonPopup, Popup)):
750+
self.add_child(folium.map.Tooltip(tooltip))
751+
if isinstance(popup, (GeoJsonPopup, folium.map.Popup)):
752752
self.add_child(popup)
753753

754754
def process_data(self, data: Any) -> dict:
@@ -939,7 +939,7 @@ def _set_default_key(mapping: TypeStyleMapping) -> None:
939939
del mapping[key_longest]
940940

941941

942-
class TopoJson(JSCSSMixin, Layer):
942+
class TopoJson(JSCSSMixin, folium.map.Layer):
943943
"""
944944
Creates a TopoJson object for plotting into a Map.
945945
@@ -1034,7 +1034,7 @@ def __init__(
10341034
control: bool = True,
10351035
show: bool = True,
10361036
smooth_factor: Optional[float] = None,
1037-
tooltip: Union[str, Tooltip, None] = None,
1037+
tooltip: Union[str, folium.map.Tooltip, None] = None,
10381038
):
10391039
super().__init__(name=name, overlay=overlay, control=control, show=show)
10401040
self._name = "TopoJson"
@@ -1058,10 +1058,10 @@ def __init__(
10581058

10591059
self.smooth_factor = smooth_factor
10601060

1061-
if isinstance(tooltip, (GeoJsonTooltip, Tooltip)):
1061+
if isinstance(tooltip, (GeoJsonTooltip, folium.map.Tooltip)):
10621062
self.add_child(tooltip)
10631063
elif tooltip is not None:
1064-
self.add_child(Tooltip(tooltip))
1064+
self.add_child(folium.map.Tooltip(tooltip))
10651065

10661066
def style_data(self) -> None:
10671067
"""Applies self.style_function to each feature of self.data."""
@@ -1408,7 +1408,7 @@ def __init__(
14081408
self.popup_options = kwargs
14091409

14101410

1411-
class Choropleth(FeatureGroup):
1411+
class Choropleth(folium.map.FeatureGroup):
14121412
"""Apply a GeoJSON overlay to the map.
14131413
14141414
Plot a GeoJSON overlay on the base map. There is no requirement
@@ -1886,7 +1886,7 @@ def __init__(self, format_str: Optional[str] = None, alert: bool = True):
18861886
self.alert = alert
18871887

18881888

1889-
class CustomIcon(Icon):
1889+
class CustomIcon(folium.map.Icon):
18901890
"""
18911891
Create a custom icon, based on an image.
18921892
@@ -1939,7 +1939,7 @@ def __init__(
19391939
shadow_anchor: Optional[Tuple[int, int]] = None,
19401940
popup_anchor: Optional[Tuple[int, int]] = None,
19411941
):
1942-
super(Icon, self).__init__()
1942+
super(folium.map.Icon, self).__init__()
19431943
self._name = "CustomIcon"
19441944
self.options = remove_empty(
19451945
icon_url=image_to_url(icon_image),
@@ -1952,7 +1952,7 @@ def __init__(
19521952
)
19531953

19541954

1955-
class ColorLine(FeatureGroup):
1955+
class ColorLine(folium.map.FeatureGroup):
19561956
"""
19571957
Draw data on a map with specified colors.
19581958

folium/map.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from branca.element import Element, Figure, Html, MacroElement
1111

12+
import folium.features as features
1213
from folium.elements import ElementAddToElement, EventHandler
1314
from folium.template import Template
1415
from folium.utilities import (
@@ -439,8 +440,6 @@ def set_icon(self, icon):
439440
self.icon = icon
440441

441442
def add_child(self, child, name=None, index=None):
442-
import folium.features as features
443-
444443
if isinstance(child, (Icon, features.CustomIcon, features.DivIcon)):
445444
self.set_icon(child)
446445
else:

folium/plugins/search.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from branca.element import MacroElement
22

3+
from folium import FeatureGroup, GeoJson, TopoJson
34
from folium.elements import JSCSSMixin
4-
from folium.features import FeatureGroup, GeoJson, TopoJson
5+
6+
# from folium.map import FeatureGroup
7+
# from folium.features import GeoJson, TopoJson
58
from folium.folium import Map
69
from folium.plugins import MarkerCluster
710
from folium.template import Template

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ nbval
2525
owslib
2626
pandas >=2
2727
pillow
28+
pixelmatch
2829
pre-commit
2930
pycodestyle
3031
pydata-sphinx-theme

tests/playwright/regressions/main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import streamlit as st
2+
3+
st.logo("https://python-visualization.github.io/folium/latest/_static/folium_logo.png")
4+
st.title("Python data, leaflet.js maps")
5+
6+
st.write(
7+
"""
8+
This app is meant to store regression tests. For issues, create a
9+
test pages under pages with the format issue_d+.
10+
"""
11+
)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from streamlit_folium import st_folium
2+
3+
import folium
4+
5+
# Library of Congress coordinates (latitude, longitude)
6+
loc_coordinates = (38.8886, -77.0047)
7+
8+
# Create a Folium map centered around the Library of Congress
9+
map_lc = folium.Map(location=loc_coordinates, zoom_start=15)
10+
11+
# Define the DivIcon with the custom icon. This variable can be used in one marker successfully, but will fail if we use it in two markers.
12+
13+
14+
icon = folium.DivIcon(
15+
icon_anchor=(15, 15),
16+
html="""<div><img src="/app/static/book-open-variant-outline.png" height="35" width="35"/></div>""",
17+
)
18+
19+
20+
folium.Marker(
21+
location=(38.886970844230866, -77.00471380332),
22+
popup="Library of Congress: James Madison Building",
23+
icon=icon,
24+
).add_to(map_lc)
25+
26+
folium.Marker(location=loc_coordinates, popup="Library of Congress", icon=icon).add_to(
27+
map_lc
28+
)
29+
# if we save here, everything will be fine.
30+
31+
st_folium(map_lc, width=600, height=500)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from streamlit_folium import st_folium
2+
3+
import folium
4+
5+
# Library of Congress coordinates (latitude, longitude)
6+
loc_coordinates = (38.8886, -77.0047)
7+
8+
# Create a Folium map centered around the Library of Congress
9+
map_lc = folium.Map(location=loc_coordinates, zoom_start=15)
10+
11+
# Define the DivIcon with the custom icon. This variable can be used in one marker successfully, but will fail if we use it in two markers.
12+
icon = folium.DivIcon(
13+
icon_anchor=(15, 15),
14+
html="""<div><img src="/app/static/book-open-variant-outline.png" height="35" width="35"/></div>""",
15+
)
16+
17+
18+
folium.Marker(
19+
location=(38.886970844230866, -77.00471380332),
20+
popup="Library of Congress: James Madison Building",
21+
icon=icon,
22+
).add_to(map_lc)
23+
24+
marker = folium.Marker(
25+
location=loc_coordinates,
26+
popup="Library of Congress",
27+
).add_to(map_lc)
28+
29+
marker.add_child(icon)
30+
# if we save here, everything will be fine.
31+
32+
st_folium(map_lc, width=600, height=500)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from streamlit_folium import st_folium
2+
3+
import folium
4+
5+
# Library of Congress coordinates (latitude, longitude)
6+
loc_coordinates = (38.8886, -77.0047)
7+
8+
# Create a Folium map centered around the Library of Congress
9+
map_lc = folium.Map(location=loc_coordinates, zoom_start=15)
10+
11+
# Define the DivIcon with the custom icon. This variable can be used in one marker successfully, but will fail if we use it in two markers.
12+
13+
14+
icon = folium.DivIcon(
15+
icon_anchor=(15, 15),
16+
html="""<div><img src="/app/static/book-open-variant-outline.png" height="35" width="35"/></div>""",
17+
)
18+
19+
20+
folium.Marker(
21+
location=(38.886970844230866, -77.00471380332),
22+
popup="Library of Congress: James Madison Building",
23+
icon=icon,
24+
).add_to(map_lc)
25+
26+
marker = folium.Marker(
27+
location=loc_coordinates,
28+
popup="Library of Congress",
29+
).add_to(map_lc)
30+
# if we save here, everything will be fine.
31+
32+
icon.add_to(marker)
33+
34+
st_folium(map_lc, width=600, height=500)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from streamlit_folium import st_folium
2+
3+
import folium
4+
5+
# Library of Congress coordinates (latitude, longitude)
6+
loc_coordinates = (38.8886, -77.0047)
7+
8+
# Create a Folium map centered around the Library of Congress
9+
map_lc = folium.Map(location=loc_coordinates, zoom_start=15)
10+
11+
# Define the DivIcon with the custom icon. This variable can be used in one marker successfully, but will fail if we use it in two markers.
12+
13+
14+
icon = folium.DivIcon(
15+
icon_anchor=(15, 15),
16+
html="""<div><img src="/app/static/book-open-variant-outline.png" height="35" width="35"/></div>""",
17+
)
18+
19+
20+
marker1 = folium.Marker(
21+
location=(38.886970844230866, -77.00471380332),
22+
popup="Library of Congress: James Madison Building",
23+
).add_to(map_lc)
24+
25+
marker2 = folium.Marker(
26+
location=loc_coordinates, popup="Library of Congress", icon=icon
27+
).add_to(map_lc)
28+
marker1.set_icon(icon)
29+
marker2.set_icon(icon)
30+
31+
st_folium(map_lc, width=600, height=500)
569 Bytes
Loading

0 commit comments

Comments
 (0)