Interactive Maps¶
The interactive export injects hover tooltips into the SVG via embedded JavaScript. The result has no external dependencies and renders directly in Jupyter or as a standalone HTML file.
The tooltips are set with a Tooltip added to the map.
Rendering to a .html path writes the interactive export:
import mappyng as mp
m = (
mp.Map(gdf, width=800, height="auto")
+ mp.Basemap()
+ mp.Choropleth(gdf, column="population", method="Quantiles")
+ mp.Tooltip(["LIB_GEO", "population"],
aliases={"LIB_GEO": "Département"})
)
m.render("carte.html")
In Jupyter, a map holding a Tooltip displays with its tooltips.
Tooltip(columns, aliases=..., style=..., hover_opacity=...) takes the
same values as to_interactive() (plus hover_opacity,
a shorthand for style={"hover": {"opacity": value}}). to_interactive
can also be called directly; its arguments override those of the
Tooltip:
interactive = m.to_interactive(
columns=["LIB_GEO", "population"],
aliases={"LIB_GEO": "Département"},
tooltip={
"background": "rgba(30,30,30,0.92)",
"text_color": "#ffffff",
"font_size": 12,
"border_radius": 6,
"key_weight": "600",
"hover": {
"opacity": 0.8,
"scale": 1.05,
"stroke_width_boost": 1.5,
"shadow": True,
"shadow_color": "rgba(0,0,0,0.4)",
},
},
)
interactive.save("carte.html")
to_interactive parameters¶
Parameter |
Description |
|---|---|
|
List of column names to include in tooltips. All non-internal columns are shown if omitted. |
|
|
|
Appearance dict, fields of |
TooltipStyle fields¶
Field |
Default |
Description |
|---|---|---|
|
|
Tooltip background color. |
|
|
Tooltip text color. |
|
11 |
Font size in px. |
|
system sans-serif |
Font family. |
|
4 |
Tooltip corner radius in px. |
|
|
Tooltip border color. |
|
|
Font weight for key labels. |
|
|
Hover effect config: |
HoverEffect fields¶
Field |
Default |
Description |
|---|---|---|
|
|
Master switch. |
|
|
CSS transition timing string. |
|
1.0 |
Element opacity on hover (< 1 = dim). |
|
1.0 |
Scale factor on hover (1.0 = no scaling). |
|
|
Show a CSS drop-shadow on hover. |
|
|
Shadow color. |
|
0.0 / 4.0 |
Shadow offset in SVG px. |
|
8.0 |
Shadow blur radius in SVG px. |
|
1.0 |
Extra stroke-width added on hover (0 = no change). |
|
|
Override stroke color on hover ( |