Skip to content

Commit

Permalink
feat: style improve
Browse files Browse the repository at this point in the history
1. allow opacity in tile layers
2. allow define line width while call display function.
  • Loading branch information
LaoshuBaby committed Mar 7, 2024
1 parent 0cfe13a commit 5c52f19
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
27 changes: 20 additions & 7 deletions src/yuheng/plugin/viz_folium/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,22 @@ def display(self, **kwargs) -> None:
"default_tiles": "",
"default_attribution": "",
"colour_original": False,
"default_style_line_width": 0,
"default_style_line_width_uncoloured": 0,
"default_style_line_width_coloured": 0,
}
for k, v in preserve_argument.items():
if (
kwargs.get(k, None) != None
and isinstance(kwargs.get(k), type(v)) != True
):
logger.error(
f"You use preverse argument {k}, please check your usage!"
)
return None
if k != "default_tiles" and isinstance(
kwargs.get(k), type(folium.TileLayer)
):
logger.error(
f"You use preverse argument {k}, please check your usage!"
)
return None

if (len(kwargs)) > 0:
logger.info(f"There are {len(kwargs)} object need to append")
Expand Down Expand Up @@ -251,7 +257,9 @@ def get_colour(
for i in range(len(position_list))
],
colormap=[colour, colour],
weight=4,
weight=kwargs.get(
"default_style_line_width_coloured", 2
),
).add_to(m)
logger.debug(
[
Expand All @@ -271,15 +279,20 @@ def get_colour(
for i in range(len(position_list))
],
colormap=["black", "black"],
weight=2,
weight=kwargs.get(
"default_style_line_width_uncoloured",
2,
),
).add_to(m)
count_way_uncoloured += 1
else:
folium.PolyLine(
self.transform(
self, obj, reference_carto=element
),
weight=2,
weight=kwargs.get(
"default_style_line_width", 2
),
).add_to(m)
time_this_way_end = time.time()

Expand Down
17 changes: 15 additions & 2 deletions tests/cases/plugin_viz_folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import sys
import unittest

from folium import TileLayer

current_dir = os.path.dirname(os.path.realpath(__file__))
src_dir = os.path.join(current_dir, "../../src")
sys.path.append(src_dir)
Expand Down Expand Up @@ -133,6 +135,11 @@ def test_plugin_viz_folium_complex(self):
default_center_lon=116.3974,
default_zoom=9,
colour_original=True,
# OpenStreetMap
# default_tiles=TileLayer(
# tiles="OpenStreetMap",
# attr='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
# ),
# # cartodb
# default_tiles="https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png",
# default_attribution=" ".join(
Expand All @@ -142,8 +149,14 @@ def test_plugin_viz_folium_complex(self):
# ]
# ),
# # ogf
default_tiles="https://tiles04.rent-a-planet.com/ogf-carto/{z}/{x}/{y}.png",
default_attribution=f'&copy; <a href="https://opengeofiction.net">OpenGeofiction</a> creators',
# default_tiles=TileLayer(
# tiles="https://tiles04.rent-a-planet.com/ogf-carto/{z}/{x}/{y}.png",
# attr='&copy; <a href="https://opengeofiction.net">OpenGeofiction</a> creators',
# opacity=0.5,
# ),
default_style_line_width=3,
default_style_line_width_uncoloured=2,
default_style_line_width_coloured=5,
)
viz.meow()

Expand Down

0 comments on commit 5c52f19

Please sign in to comment.