Tooltip#
Example#
from ipyleaflet import Map, Tooltip, Marker, Polygon, Circle
m = Map(center=(51.505,-0.09), zoom=13)
standalone_tooltip = Tooltip(
location=[51.5, -0.09],
content="Hello world!<br />This is a nice tooltip.",
offset=[-30,50], # Offset in pixels
permanent=False, # The default is False, in which case you can remove the tooltip by clicking anywhere on the map.
direction='bottom', # Default is 'auto'
)
marker_tooltip = Tooltip(
content="I'm a marker tooltip! π<br>Appears on hover.",
)
marker = Marker(
location=[51.5, -0.09],
draggable=False,
tooltip=marker_tooltip,
)
polygon = Polygon(
locations= [
[51.509, -0.08],
[51.503, -0.06],
[51.51, -0.047]
])
polygon_tooltip = Tooltip(
content = "Polygon's Permanent Tooltip πΊοΈ",
permanent = True,
direction = 'center', # Centers the tooltip on the polygon
)
polygon.tooltip = polygon_tooltip
circle = Circle(
location = [51.515, -0.1],
radius = 500,
color = 'green',
fillColor = '#0f3',
fillOpacity = 0.5,
tooltip = Tooltip(
content = "Sticky Tooltip here! π<br>Stays with the mouse.",
sticky = True,
)
)
m.add(standalone_tooltip)
m.add(marker)
m.add(polygon)
m.add(circle)
m
Attributes and methods#
- class ipyleaflet.leaflet.Tooltip(*args: t.Any, **kwargs: t.Any)[source]#
Tooltip class.
Used to display small texts on top of map layers.
- location#
Optional tuple containing the latitude/longitude of the stand-alone tooltip.
- Type:
tuple, default None
- content#
The text to show inside the tooltip
- Type:
str, default ββ
- offset#
Optional offset of the tooltip position (in pixels).
- Type:
tuple, default (0, 0)
- direction#
Direction where to open the tooltip. Possible values are: right, left, top, bottom, center, auto. auto will dynamically switch between right and left according to the tooltip position on the map.
- Type:
str, default βautoβ
- permanent#
Whether to open the tooltip permanently or only on mouseover.
- Type:
bool, default False
- sticky#
If true, the tooltip will follow the mouse instead of being fixed at the feature center. This option only applies when binding the tooltip to a Layer, not as stand-alone.
- Type:
bool, default False