Skip to content

Commit

Permalink
feat: success in display custom svg as icon on metromap
Browse files Browse the repository at this point in the history
  • Loading branch information
LaoshuBaby committed Mar 9, 2024
1 parent 2f865ef commit 1b3acb9
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions src/yuheng/plugin/viz_folium/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ def display(self, **kwargs) -> None:
if obj.tags.get("network", None) == "subway":
logger.success("found a subway network")
# node
import base64

def svg_to_data_url(svg_path):
with open(svg_path, "r") as svg_file:
svg_data = svg_file.read()
# 对SVG数据进行Base64编码
encoded = base64.b64encode(
svg_data.encode("utf-8")
).decode("utf-8")
return f"data:image/svg+xml;base64,{encoded}"

time_node_start = time.time()
work_burden_node_count = 0
for id, obj in element.node_dict.items():
Expand All @@ -184,15 +195,35 @@ def display(self, **kwargs) -> None:
if obj.tags.get("station", None) == "subway":
if obj.tags.get("subway", None) == "yes":
logger.success(f"n{id} is a subway station")
pass
icon = folium.CustomIcon(
svg_to_data_url(
os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"..",
"assets",
"绘图-1.svg",
)
),
icon_size=(30, 30),
) # 调整适当的大小
folium.Marker(
location=[obj.lat, obj.lon],
tooltip=obj.tags.get("name", ""),
popup=f'<a href="https://opengeofiction.net/node/{obj.tags.get("name", "")}<br/>{id}">Node {id}</a>',
icon=icon,
).add_to(m)

## normal
folium.ColorLine(
positions=[(obj.lat, obj.lon), (obj.lat, obj.lon)],
colors=[0.114514, 0.1919810],
colormap=["black", "black"],
weight=4,
).add_to(m)
else:
folium.ColorLine(
positions=[(obj.lat, obj.lon), (obj.lat, obj.lon)],
colors=[0.114514, 0.1919810],
colormap=["black", "black"],
weight=4,
).add_to(m)
if (
work_burden > work_burden_report_node_interval
and work_burden_node_count
Expand Down

0 comments on commit 1b3acb9

Please sign in to comment.