Simple arrow (vector/quiver) icon for folium#
This package provides simple arrow (vector/quiver) icon for the folium package.
The arrow (vector/quiver) icon is independent of zoom level, its size does not change as zoom level changes. It is useful for displaying vector field.
You can install folium-arrow-icon from PyPI:
pip install folium-arrow-icon
This packages is released under MIT licence.
See Sample Code for example.
Module contents#
Simple arrow (vector/quiver) icon for folium.
- class folium_arrow_icon.ArrowIcon(length: int | float, angle: int | float, head: ArrowIconHead = ArrowIconHead(width=8, length=10), body: ArrowIconBody = ArrowIconBody(width=2), color: str = 'black', border_width: int | float = 0, border_color: str | None = None, anchor: Literal['tail', 'mid', 'head'] = 'tail', popup_anchor: tuple[int, int] | None = None, class_name: str = 'empty')#
Bases:
DivIconSimple arrow (vector/quiver) Icon.
- Parameters:
length – the length of the vector which satisfies 0 <=.
angle – the angle of the vector in radian, it starts from the positive latidude axis and goes clockwise (Left-Handed System).
head – the head metric, defraulting
ArrowIconHead(width=8, length=10).body – the body metric, defraulting
ArrowIconBody(width=2).color – the color of the vector, supporting any CSS color propery.
border_width – the border width.
border_color – the border color.
anchor – the anchor of the vector.
popup_anchor – it passes to the
folium.DivIconconstructor.class_name – it passes to the
folium.DivIconconstructor.
Examples
A marker with a vector icon of which length is 100px and directing positive longitude.
>>> folium.Marker( ... (40.78322, -73.96551), ... icon=ArrowIcon(100, math.pi / 2), ... )
More customized example;
>>> folium.Marker( ... (40.78322, -73.96551), ... icon=ArrowIcon( ... 100, math.pi ... head=ArrowIconHead(width=10, length=20), ... body=ArrowIconBody(width=5), ... color="hsl(30deg, 100%, 50%)", ... border_width=1, ... border_color="red", ... anchor="mid" ... ) ... )
- classmethod from_comp(components: Sequence[int | float], head: ArrowIconHead = ArrowIconHead(width=8, length=10), body: ArrowIconBody = ArrowIconBody(width=2), color: str = 'black', border_width: int | float = 0, border_color: str | None = None, anchor: Literal['tail', 'mid', 'head'] = 'tail', popup_anchor: tuple[int, int] | None = None, class_name: str = 'empty')#
Makes a
ArrowIconfrom components of latitude and longitude direction.- Parameters:
components – the components vector, latitude and longitude direction.
head – the head metric, defraulting
ArrowIconHead(width=8, length=10).body – the body metric, defraulting
ArrowIconBody(width=2).color – the color of the vector, supporting any CSS color propery.
border_width – the border width.
border_color – the border color.
anchor – the anchor of the vector.
popup_anchor – it passes to the
folium.DivIconconstructor.class_name – it passes to the
folium.DivIconconstructor.
- Returns:
a
ArrowIconobj
Examples
A marker with a vector icon of which latitude compnent is 100 px and longitude is 50px.
>>> folium.Marker( ... (40.78322, -73.96551), ... icon=ArrowIcon.from_comp((100, 50)), ... )
More customized example;
>>> folium.Marker( ... (40.78322, -73.96551), ... icon=ArrowIcon.from_comp( ... (100, 50) ... head=ArrowIconHead(width=10, length=20), ... body=ArrowrIconBody(width=5), ... color="hsl(30deg, 100%, 50%)", ... border_width=1, ... border_color="red", ... anchor="mid" ... ), ... )
Sample Code#
import math
import folium
from folium_arrow_icon import ArrowIcon
By length and angle#
m = folium.Map(
location=[40.78322, -73.96551],
zoom_start=14,
tiles='Cartodb Positron'
)
folium.Marker(
[40.78322, -73.96551],
icon=ArrowIcon(100, 0)
).add_to(m)
folium.Marker(
[40.78322, -73.96551],
icon=ArrowIcon(100, math.pi / 2, color="red")
).add_to(m)
m
By components of latitude and longitude direction#
m = folium.Map(
location=[40.78322, -73.96551],
zoom_start=14,
tiles='Cartodb Positron'
)
folium.Marker(
[40.78322, -73.96551],
icon=ArrowIcon.from_comp((100, 50))
).add_to(m)
folium.Marker(
[40.78322, -73.96551],
icon=ArrowIcon.from_comp((-50, 100), color="red")
).add_to(m)
m
Variation of anchor#
from folium_arrow_icon import ArrowIconHead, ArrowIconBody
def marker(i: int, anchor: str, delta: float) -> folium.Marker:
lat, lng = 40.78322, -73.96551
return folium.Marker(
# shif by (0.001 * i, delta) from (40.78322, -73.96551)
[lat + 0.001 * i, lng + delta],
icon=ArrowIcon(
# wavy visualization
150 + 50 * math.sin(i * math.pi / 20),
math.pi / 2,
# rainbowing by css property "hsl"
color=f"hsl({i * 10}deg, 100%, 50%)",
# show border of vector
border_color="black",
border_width=1,
# big head
head=ArrowIconHead(
width=12,
length=20
),
# thin body relative to head
body=ArrowIconBody(
width=3
),
# anchor is variable
anchor=anchor
)
)
m = folium.Map(
location=[40.78322 + 0.015, -73.96551 + 0.035],
zoom_start=14,
tiles='Cartodb Positron'
)
for i in range(36):
# The left is anchor at 'tail' (default)
marker(i, anchor="tail", delta=0.0).add_to(m)
# The left is anchor at 'haed'
marker(i, anchor="head", delta=0.04).add_to(m)
# The left is anchor at 'mid'
marker(i, anchor="mid", delta=0.06).add_to(m)
m