mapyta 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mapyta-0.2.0 → mapyta-0.3.0}/PKG-INFO +2 -1
- {mapyta-0.2.0 → mapyta-0.3.0}/README.md +1 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/.nav.yml +5 -0
- mapyta-0.3.0/docs/tutorial/animated.md +209 -0
- mapyta-0.3.0/docs/tutorial/dataframe.md +115 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/drawing.md +6 -7
- mapyta-0.3.0/docs/tutorial/faq.md +290 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/index.md +5 -0
- mapyta-0.3.0/docs/tutorial/min-zoom.md +113 -0
- mapyta-0.3.0/docs/tutorial/open-data.md +211 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/mapyta/__init__.py +4 -1
- {mapyta-0.2.0 → mapyta-0.3.0}/mapyta/config.py +14 -7
- mapyta-0.3.0/mapyta/dataframe.py +118 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/mapyta/map.py +404 -27
- {mapyta-0.2.0 → mapyta-0.3.0}/mapyta/tiles.py +24 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/pyproject.toml +5 -1
- mapyta-0.3.0/tests/test_dataframe.py +467 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/tests/test_draw.py +1 -1
- {mapyta-0.2.0 → mapyta-0.3.0}/tests/test_layers.py +277 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/tests/test_map.py +48 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/uv.lock +33 -1
- {mapyta-0.2.0 → mapyta-0.3.0}/.github/workflows/docs.yml +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/.github/workflows/lint.yml +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/.github/workflows/publish.yml +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/.github/workflows/tests.yml +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/.gitignore +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/.pre-commit-config.yaml +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/.ruff.toml +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/LICENSE +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/.nav.yml +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/_overrides/assets/images/favicon.ico +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/_overrides/assets/images/logo-dark-mode.svg +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/_overrides/assets/images/mapyta-logo-dark-mode.svg +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/_overrides/assets/images/mapyta-logo-light-mode.svg +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/_overrides/assets/javascripts/katex.js +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/_overrides/assets/stylesheets/extra.css +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/_overrides/main.html +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/_scripts/__init__.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/_scripts/generate_index.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/_scripts/generate_reference_pages.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/advanced.md +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/choropleth.md +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/clusters.md +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/configuration.md +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/coordinates.md +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/export.md +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/first-map.md +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/geodataframe.md +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/geometries.md +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/heatmaps.md +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/layers.md +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/markers.md +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/text-annotations.md +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/docs/tutorial/tooltips-popups.md +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/mapyta/coordinates.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/mapyta/export.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/mapyta/geojson.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/mapyta/markdown.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/mapyta/markers.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/mapyta/style.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/properdocs.yml +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/tests/__init__.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/tests/conftest.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/tests/test_data.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/tests/test_export.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/tests/test_geometry.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/tests/test_map_creation.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/tests/test_markers.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/tests/test_merge_and_chaining.py +0 -0
- {mapyta-0.2.0 → mapyta-0.3.0}/tests/test_utilities.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mapyta
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Mapyta, open source python package for GIS mapping and visualization.
|
|
5
5
|
License: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -56,6 +56,7 @@ but rather to provide a simple way to create interactive maps without needing to
|
|
|
56
56
|
- 📌 **Emoji & icon markers** — any text or Font Awesome icons as markers
|
|
57
57
|
- 🎨 **Choropleth & heatmaps** — color-coded maps from numeric data
|
|
58
58
|
- 📊 **GeoPandas integration** — `Map.from_geodataframe()` one-liner
|
|
59
|
+
- 🗂️ **DataFrame support** — `add_dataframe()` works with any Pandas or Polars DataFrame with a WKT geometry column
|
|
59
60
|
- 🌐 **Auto CRS detection** — RD New (EPSG:28992) coordinates transform automatically
|
|
60
61
|
- 📤 **Export anywhere** — HTML, PNG, SVG, GeoJSON, async variants, and `BytesIO` buffers
|
|
61
62
|
- 🧩 **Feature groups** — toggleable layers with a built-in layer control
|
|
@@ -32,6 +32,7 @@ but rather to provide a simple way to create interactive maps without needing to
|
|
|
32
32
|
- 📌 **Emoji & icon markers** — any text or Font Awesome icons as markers
|
|
33
33
|
- 🎨 **Choropleth & heatmaps** — color-coded maps from numeric data
|
|
34
34
|
- 📊 **GeoPandas integration** — `Map.from_geodataframe()` one-liner
|
|
35
|
+
- 🗂️ **DataFrame support** — `add_dataframe()` works with any Pandas or Polars DataFrame with a WKT geometry column
|
|
35
36
|
- 🌐 **Auto CRS detection** — RD New (EPSG:28992) coordinates transform automatically
|
|
36
37
|
- 📤 **Export anywhere** — HTML, PNG, SVG, GeoJSON, async variants, and `BytesIO` buffers
|
|
37
38
|
- 🧩 **Feature groups** — toggleable layers with a built-in layer control
|
|
@@ -8,10 +8,15 @@ nav:
|
|
|
8
8
|
- Choropleth Maps: choropleth.md
|
|
9
9
|
- Heatmaps: heatmaps.md
|
|
10
10
|
- Marker Clusters: clusters.md
|
|
11
|
+
- Dataframes: dataframe.md
|
|
11
12
|
- GeoPandas Integration: geodataframe.md
|
|
13
|
+
- Open data (CBS & PDOK): open-data.md
|
|
12
14
|
- Coordinate Detection: coordinates.md
|
|
13
15
|
- Map Configuration: configuration.md
|
|
14
16
|
- Text Annotations: text-annotations.md
|
|
15
17
|
- Export: export.md
|
|
16
18
|
- Drawing: drawing.md
|
|
19
|
+
- Animated Layers: animated.md
|
|
17
20
|
- Advanced: advanced.md
|
|
21
|
+
- Zoom-dependent Visibility: min-zoom.md
|
|
22
|
+
- FAQ: faq.md
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# Animated Layers
|
|
2
|
+
|
|
3
|
+
Three plugins turn static maps into animated ones: ant paths trace routes with marching-ants animation, heatmaps-with-time show how density shifts across time steps, and timestamped GeoJSON animates arbitrary features along a timeline.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Ant paths
|
|
8
|
+
|
|
9
|
+
An ant path is a polyline with a moving dash pattern — the gaps appear to travel forward along the route, making direction of travel immediately obvious.
|
|
10
|
+
|
|
11
|
+
```python exec="true" html="true" source="tabbed-right"
|
|
12
|
+
from shapely.geometry import LineString
|
|
13
|
+
from mapyta import Map
|
|
14
|
+
|
|
15
|
+
m = Map(title="Tram route 9 — Utrecht")
|
|
16
|
+
|
|
17
|
+
route = LineString([
|
|
18
|
+
(5.1085, 52.0893), # Centraal Station
|
|
19
|
+
(5.1130, 52.0877),
|
|
20
|
+
(5.1178, 52.0865),
|
|
21
|
+
(5.1213, 52.0851),
|
|
22
|
+
(5.1268, 52.0838), # Maliebaan
|
|
23
|
+
])
|
|
24
|
+
|
|
25
|
+
m.add_ant_path(
|
|
26
|
+
route,
|
|
27
|
+
tooltip="**Tram 9** — richting Maliebaan",
|
|
28
|
+
color="#e74c3c",
|
|
29
|
+
pulse_color="#ffffff",
|
|
30
|
+
weight=5,
|
|
31
|
+
delay=300,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
m.to_html("ant_path.html")
|
|
35
|
+
|
|
36
|
+
print(m.to_html()) # markdown-exec: hide
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Parameters
|
|
40
|
+
|
|
41
|
+
| Parameter | Default | Description |
|
|
42
|
+
|-----------|---------|-------------|
|
|
43
|
+
| `line` | — | `LineString` or `list[Point]` — the route geometry |
|
|
44
|
+
| `tooltip` | `None` | Markdown tooltip |
|
|
45
|
+
| `popup` | `None` | Markdown popup |
|
|
46
|
+
| `color` | `"#0000FF"` | Line colour |
|
|
47
|
+
| `pulse_color` | `"#FFFFFF"` | Colour of the travelling gap |
|
|
48
|
+
| `weight` | `5` | Line width in pixels |
|
|
49
|
+
| `delay` | `400` | Animation step interval in milliseconds — lower is faster |
|
|
50
|
+
| `dash_array` | `None` | `[dash, gap]` pattern in pixels; defaults to `[10, 20]` |
|
|
51
|
+
| `paused` | `False` | Start the animation paused |
|
|
52
|
+
| `reverse` | `False` | Reverse the direction of travel |
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Heatmap with time
|
|
57
|
+
|
|
58
|
+
`add_heatmap_with_time()` displays a heatmap that changes over time. A playback slider is injected into the map so users can step through or scrub between time steps.
|
|
59
|
+
|
|
60
|
+
```python exec="true" html="true" source="tabbed-right"
|
|
61
|
+
import random
|
|
62
|
+
from shapely.geometry import Point
|
|
63
|
+
from mapyta import Map
|
|
64
|
+
|
|
65
|
+
random.seed(0)
|
|
66
|
+
|
|
67
|
+
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
|
|
68
|
+
|
|
69
|
+
# Simulate a hotspot that drifts north-east over time
|
|
70
|
+
data = [
|
|
71
|
+
[Point(5.10 + i * 0.004 + random.gauss(0, 0.02), 52.07 + i * 0.003 + random.gauss(0, 0.01))
|
|
72
|
+
for _ in range(60)]
|
|
73
|
+
for i in range(len(months))
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
m = Map(title="Monthly activity — H1 2024")
|
|
77
|
+
m.add_heatmap_with_time(
|
|
78
|
+
data=data,
|
|
79
|
+
index=months,
|
|
80
|
+
radius=18,
|
|
81
|
+
max_opacity=0.7,
|
|
82
|
+
auto_play=True,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
m.to_html("heatmap_with_time.html")
|
|
86
|
+
|
|
87
|
+
print(m.to_html()) # markdown-exec: hide
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Each entry in `data` is one time step and must be the same length as `index`. Points can be Shapely `Point` objects (longitude, latitude) or raw `(lat, lon)` or `(lat, lon, intensity)` tuples.
|
|
91
|
+
|
|
92
|
+
### Parameters
|
|
93
|
+
|
|
94
|
+
| Parameter | Default | Description |
|
|
95
|
+
|-----------|---------|-------------|
|
|
96
|
+
| `data` | — | List of per-timestep point lists |
|
|
97
|
+
| `index` | — | Label for each time step shown in the slider |
|
|
98
|
+
| `radius` | `15` | Point radius in pixels |
|
|
99
|
+
| `blur` | `0.8` | Blur amount (0–1) |
|
|
100
|
+
| `max_opacity` | `0.6` | Maximum opacity (0–1) |
|
|
101
|
+
| `min_opacity` | `0.0` | Minimum opacity (0–1) |
|
|
102
|
+
| `gradient` | `None` | Custom colour gradient e.g. `{0.0: "blue", 0.5: "yellow", 1.0: "red"}` |
|
|
103
|
+
| `auto_play` | `False` | Start playback automatically on load |
|
|
104
|
+
| `display_index` | `True` | Show the current time step label |
|
|
105
|
+
| `position` | `"bottomleft"` | Control position on the map |
|
|
106
|
+
|
|
107
|
+
`data` and `index` must have the same length — a `ValueError` is raised otherwise.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Timestamped GeoJSON
|
|
112
|
+
|
|
113
|
+
`add_timestamped_geojson()` animates a GeoJSON `FeatureCollection` over time. Each feature must have a `times` property — an array of ISO 8601 timestamps, one per coordinate.
|
|
114
|
+
|
|
115
|
+
```python exec="true" html="true" source="tabbed-right"
|
|
116
|
+
from mapyta import Map
|
|
117
|
+
|
|
118
|
+
geojson = {
|
|
119
|
+
"type": "FeatureCollection",
|
|
120
|
+
"features": [
|
|
121
|
+
{
|
|
122
|
+
"type": "Feature",
|
|
123
|
+
"geometry": {
|
|
124
|
+
"type": "LineString",
|
|
125
|
+
"coordinates": [
|
|
126
|
+
[5.108, 52.090],
|
|
127
|
+
[5.115, 52.093],
|
|
128
|
+
[5.122, 52.096],
|
|
129
|
+
[5.130, 52.098],
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
"properties": {
|
|
133
|
+
"times": [
|
|
134
|
+
"2024-06-01T08:00:00",
|
|
135
|
+
"2024-06-01T08:15:00",
|
|
136
|
+
"2024-06-01T08:30:00",
|
|
137
|
+
"2024-06-01T08:45:00",
|
|
138
|
+
],
|
|
139
|
+
"style": {"color": "#e67e22", "weight": 4},
|
|
140
|
+
"icon": "circle",
|
|
141
|
+
"iconstyle": {
|
|
142
|
+
"fillColor": "#e67e22",
|
|
143
|
+
"fillOpacity": 1,
|
|
144
|
+
"stroke": True,
|
|
145
|
+
"radius": 6,
|
|
146
|
+
"color": "#fff",
|
|
147
|
+
"weight": 2,
|
|
148
|
+
},
|
|
149
|
+
"popup": "Morning commute",
|
|
150
|
+
},
|
|
151
|
+
}
|
|
152
|
+
],
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
m = Map(title="GPS trace replay")
|
|
156
|
+
m.add_timestamped_geojson(
|
|
157
|
+
geojson,
|
|
158
|
+
auto_play=True,
|
|
159
|
+
loop=False,
|
|
160
|
+
transition_time=500,
|
|
161
|
+
period="PT15M",
|
|
162
|
+
date_options="HH:mm",
|
|
163
|
+
)
|
|
164
|
+
m.to_html("gps_replay.html")
|
|
165
|
+
|
|
166
|
+
print(m.to_html()) # markdown-exec: hide
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Parameters
|
|
170
|
+
|
|
171
|
+
| Parameter | Default | Description |
|
|
172
|
+
|-----------|---------|-------------|
|
|
173
|
+
| `data` | — | GeoJSON `FeatureCollection` as a `dict`, JSON string, or file path |
|
|
174
|
+
| `auto_play` | `True` | Start playback when the map loads |
|
|
175
|
+
| `loop` | `True` | Loop the animation continuously |
|
|
176
|
+
| `transition_time` | `200` | Frame transition duration in milliseconds |
|
|
177
|
+
| `period` | `"P1D"` | ISO 8601 duration per slider step — `"P1D"` = 1 day, `"PT1H"` = 1 hour, `"PT1M"` = 1 minute |
|
|
178
|
+
| `date_options` | `"YYYY-MM-DD HH:mm:ss"` | [moment.js](https://momentjs.com/docs/#/displaying/) format string for the displayed timestamp |
|
|
179
|
+
| `duration` | `None` | How long each feature stays visible after its timestamp; `None` = stays visible forever |
|
|
180
|
+
|
|
181
|
+
### GeoJSON feature format
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
{
|
|
185
|
+
"type": "Feature",
|
|
186
|
+
"geometry": {
|
|
187
|
+
"type": "LineString",
|
|
188
|
+
"coordinates": [[lon, lat], [lon, lat], ...], # one pair per timestamp
|
|
189
|
+
},
|
|
190
|
+
"properties": {
|
|
191
|
+
"times": ["2024-01-01T00:00:00", "2024-01-01T01:00:00", ...],
|
|
192
|
+
"style": {"color": "#e74c3c", "weight": 3},
|
|
193
|
+
# Use "circle" to show a dot at the current animated position.
|
|
194
|
+
# Without this, a default Leaflet pin marker appears instead.
|
|
195
|
+
"icon": "circle",
|
|
196
|
+
"iconstyle": {
|
|
197
|
+
"fillColor": "#e74c3c",
|
|
198
|
+
"fillOpacity": 1,
|
|
199
|
+
"stroke": True,
|
|
200
|
+
"radius": 6,
|
|
201
|
+
"color": "#fff",
|
|
202
|
+
"weight": 2,
|
|
203
|
+
},
|
|
204
|
+
"popup": "Optional popup text",
|
|
205
|
+
},
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
The `times` array must have exactly one entry per coordinate. Supported geometry types: `LineString`, `MultiPoint`, `MultiLineString`, `Polygon`, `MultiPolygon`.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# DataFrames (Pandas & Polars)
|
|
2
|
+
|
|
3
|
+
If your data lives in a Pandas or Polars DataFrame, you can add it directly to a map with `add_dataframe()`. The DataFrame needs one column with WKT geometry strings; all other columns become properties you can show in hover tooltips.
|
|
4
|
+
|
|
5
|
+
!!! note "Geometry must be in WGS84"
|
|
6
|
+
|
|
7
|
+
The WKT strings in your geometry column must use geographic coordinates (longitude, latitude) in WGS84 (EPSG:4326). If your data is in RD New or another CRS, reproject it first.
|
|
8
|
+
|
|
9
|
+
## Minimal example
|
|
10
|
+
|
|
11
|
+
```python exec="true" html="true" source="tabbed-right"
|
|
12
|
+
import pandas as pd
|
|
13
|
+
from mapyta import Map
|
|
14
|
+
|
|
15
|
+
df = pd.DataFrame(
|
|
16
|
+
{
|
|
17
|
+
"geometry": [
|
|
18
|
+
"POINT (4.9041 52.3676)",
|
|
19
|
+
"POINT (5.1214 52.0907)",
|
|
20
|
+
"POINT (4.4777 51.9244)",
|
|
21
|
+
],
|
|
22
|
+
"city": ["Amsterdam", "Utrecht", "Rotterdam"],
|
|
23
|
+
"population": [872_680, 361_924, 651_446],
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
m = Map(title="Dutch Cities")
|
|
28
|
+
m.add_dataframe(df, hover_fields=["city", "population"])
|
|
29
|
+
m.to_html("cities.html")
|
|
30
|
+
|
|
31
|
+
print(m.to_html()) # markdown-exec: hide
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Polars works the same way
|
|
35
|
+
|
|
36
|
+
```python exec="true" html="true" source="tabbed-right"
|
|
37
|
+
import polars as pl
|
|
38
|
+
from mapyta import Map
|
|
39
|
+
|
|
40
|
+
df = pl.DataFrame(
|
|
41
|
+
{
|
|
42
|
+
"geometry": [
|
|
43
|
+
"POINT (4.9041 52.3676)",
|
|
44
|
+
"POINT (5.1214 52.0907)",
|
|
45
|
+
],
|
|
46
|
+
"city": ["Amsterdam", "Utrecht"],
|
|
47
|
+
}
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
m = Map(title="Cities")
|
|
51
|
+
m.add_dataframe(df, hover_fields=["city"])
|
|
52
|
+
m.to_html("cities.html")
|
|
53
|
+
|
|
54
|
+
print(m.to_html()) # markdown-exec: hide
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Polygons and lines
|
|
58
|
+
|
|
59
|
+
`add_dataframe()` works with any geometry type — not just points. The WKT column can contain `POLYGON`, `LINESTRING`, `MULTIPOLYGON`, or any combination.
|
|
60
|
+
|
|
61
|
+
```python exec="true" html="true" source="tabbed-right"
|
|
62
|
+
import pandas as pd
|
|
63
|
+
from mapyta import Map
|
|
64
|
+
|
|
65
|
+
df = pd.DataFrame(
|
|
66
|
+
{
|
|
67
|
+
"geometry": [
|
|
68
|
+
"POLYGON ((4.85 52.35, 4.95 52.35, 4.95 52.40, 4.85 52.40, 4.85 52.35))",
|
|
69
|
+
"LINESTRING (4.9 52.37, 5.0 52.38, 5.1 52.35)",
|
|
70
|
+
],
|
|
71
|
+
"label": ["Zone A", "Route 1"],
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
m = Map(title="Shapes")
|
|
76
|
+
m.add_dataframe(df, hover_fields=["label"])
|
|
77
|
+
m.to_html("shapes.html")
|
|
78
|
+
|
|
79
|
+
print(m.to_html()) # markdown-exec: hide
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Custom geometry column name
|
|
83
|
+
|
|
84
|
+
If your geometry column is not named `"geometry"`, pass the column name explicitly:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
m.add_dataframe(df, geometry_col="wkt_geom", hover_fields=["name"])
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Styling
|
|
91
|
+
|
|
92
|
+
Pass `style` and `highlight` dicts to control appearance — the same kwargs accepted by `add_geojson()`:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
m.add_dataframe(
|
|
96
|
+
df,
|
|
97
|
+
hover_fields=["name"],
|
|
98
|
+
style={"color": "#e74c3c", "weight": 2, "fillOpacity": 0.4},
|
|
99
|
+
highlight={"weight": 4, "fillOpacity": 0.7},
|
|
100
|
+
)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Parameters
|
|
104
|
+
|
|
105
|
+
| Parameter | Description |
|
|
106
|
+
|-----------|-------------|
|
|
107
|
+
| `df` | Pandas or Polars DataFrame |
|
|
108
|
+
| `geometry_col` | Column with WKT geometry strings (default: `"geometry"`) |
|
|
109
|
+
| `hover_fields` | Columns to show in the hover tooltip |
|
|
110
|
+
| `style` | Folium GeoJson style dict (color, weight, fillOpacity, …) |
|
|
111
|
+
| `highlight` | Style applied on mouse-over |
|
|
112
|
+
|
|
113
|
+
## When to use `from_geodataframe()` instead
|
|
114
|
+
|
|
115
|
+
Use `Map.from_geodataframe()` when you have a **GeoPandas** `GeoDataFrame` with Shapely geometry objects and want features like per-row coloring, automatic CRS reprojection, or click popups with multiple columns. `add_dataframe()` is the right choice when you have a plain Pandas or Polars DataFrame with WKT strings.
|
|
@@ -7,9 +7,9 @@ Let users draw markers, lines, and polygons on the map and submit the results.
|
|
|
7
7
|
Enable the default drawing tools (polyline, polygon, marker) with a download-on-submit fallback:
|
|
8
8
|
|
|
9
9
|
```python exec="true" html="true" source="tabbed-right"
|
|
10
|
-
from mapyta import Map
|
|
10
|
+
from mapyta import Map, MapConfig
|
|
11
11
|
|
|
12
|
-
m = Map(title="Drawing demo")
|
|
12
|
+
m = Map(title="Drawing demo", center=(52.0907, 5.1214), config=MapConfig(zoom_start=13))
|
|
13
13
|
m.enable_draw()
|
|
14
14
|
|
|
15
15
|
m.to_html("custom.html")
|
|
@@ -28,9 +28,9 @@ Use the toolbar in the **top-left corner** of the map to draw:
|
|
|
28
28
|
Pick only the tools you need:
|
|
29
29
|
|
|
30
30
|
```python exec="true" html="true" source="tabbed-right"
|
|
31
|
-
from mapyta import Map
|
|
31
|
+
from mapyta import Map, MapConfig
|
|
32
32
|
|
|
33
|
-
m = Map(title="Polygons only")
|
|
33
|
+
m = Map(title="Polygons only", center=(52.0907, 5.1214), config=MapConfig(zoom_start=13))
|
|
34
34
|
m.enable_draw(tools=["polygon", "rectangle"])
|
|
35
35
|
|
|
36
36
|
print(m.to_html()) # markdown-exec: hide
|
|
@@ -53,10 +53,9 @@ This sends a `POST` request with the GeoJSON FeatureCollection as the body.
|
|
|
53
53
|
For full control, pass a `RawJS` function expression:
|
|
54
54
|
|
|
55
55
|
```python exec="true" html="true" source="tabbed-right"
|
|
56
|
-
from mapyta import Map
|
|
57
|
-
from mapyta import RawJS
|
|
56
|
+
from mapyta import Map, MapConfig, RawJS
|
|
58
57
|
|
|
59
|
-
m = Map(title="Custom callback, check console (F12)")
|
|
58
|
+
m = Map(title="Custom callback, check console (F12)", center=(52.0907, 5.1214), config=MapConfig(zoom_start=13))
|
|
60
59
|
m.enable_draw(on_submit=RawJS("function(geojson) { console.log(geojson); }"))
|
|
61
60
|
|
|
62
61
|
print(m.to_html()) # markdown-exec: hide
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
# FAQ
|
|
2
|
+
|
|
3
|
+
Common questions and answers for mapyta.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Map creation
|
|
8
|
+
|
|
9
|
+
**How do I set the initial center and zoom level?**
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from mapyta import Map, MapConfig
|
|
13
|
+
|
|
14
|
+
m = Map(
|
|
15
|
+
center=(52.37, 4.9),
|
|
16
|
+
config=MapConfig(zoom_start=14),
|
|
17
|
+
)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
If you omit `center`, mapyta auto-fits the view to all your geometries after the first render.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
**How do I change the tile provider (background map)?**
|
|
25
|
+
|
|
26
|
+
Pass a provider key to `MapConfig`:
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from mapyta import Map, MapConfig
|
|
30
|
+
|
|
31
|
+
m = Map(config=MapConfig(tile_layer="esri_satellite"))
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Built-in keys: `openstreetmap`, `cartodb_positron`, `cartodb_dark`, `esri_satellite`, `esri_topo`, `stamen_terrain`, `stamen_toner`, `kadaster_brt`, `kadaster_luchtfoto`, `kadaster_grijs`, `cartodb_voyager`, `esri_streets`, `esri_gray`, `esri_ocean`, `opentopomap`, `stamen_watercolor`, `stadia_alidade`, `stadia_dark`.
|
|
35
|
+
|
|
36
|
+
Pass a raw XYZ URL for a provider not in the list:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
m = Map(config=MapConfig(tile_layer="https://my-tiles.example.com/{z}/{x}/{y}.png"))
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
**How do I show multiple base layers with a toggle?**
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from mapyta import Map, MapConfig
|
|
48
|
+
|
|
49
|
+
m = Map(config=MapConfig(tile_layer=["cartodb_positron", "esri_satellite"]))
|
|
50
|
+
m.add_layer_control()
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Geometries
|
|
56
|
+
|
|
57
|
+
**What geometry types are supported?**
|
|
58
|
+
|
|
59
|
+
All standard Shapely types: `Point`, `LineString`, `Polygon`, `MultiPoint`, `MultiLineString`, `MultiPolygon`. Pass any of these to the corresponding `add_*` method, or use `add_geometry()` to dispatch automatically.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
**How do I hide a layer until the user zooms in?**
|
|
64
|
+
|
|
65
|
+
Use the `min_zoom` parameter. It works on points, circles, lines, polygons, clusters, and text annotations:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from shapely.geometry import Point, LineString, Polygon
|
|
69
|
+
from mapyta import Map
|
|
70
|
+
|
|
71
|
+
m = Map()
|
|
72
|
+
m.add_point(Point(4.9, 52.37), marker="📍", min_zoom=13)
|
|
73
|
+
m.add_linestring(LineString([(4.9, 52.37), (4.91, 52.38)]), min_zoom=13)
|
|
74
|
+
m.add_polygon(Polygon([(4.9, 52.3), (5.0, 52.3), (5.0, 52.4), (4.9, 52.4)]), min_zoom=11)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The layer is hidden at zoom levels below `min_zoom` and shown at `min_zoom` and above.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
**My coordinates are in Dutch RD New (EPSG:28992). Do I need to convert them first?**
|
|
82
|
+
|
|
83
|
+
No. Mapyta auto-detects RD New coordinates and reprojects them to WGS84:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from shapely.geometry import Point
|
|
87
|
+
from mapyta import Map
|
|
88
|
+
|
|
89
|
+
m = Map()
|
|
90
|
+
m.add_point(Point(121_000, 487_000)) # RD New — converted automatically
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
To force a specific CRS, pass `source_crs`:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
m = Map(source_crs="EPSG:28992")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Styling
|
|
102
|
+
|
|
103
|
+
**How do I style a line or polygon?**
|
|
104
|
+
|
|
105
|
+
Use `StrokeStyle` for borders and lines, `FillStyle` for polygon fills:
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from shapely.geometry import Polygon
|
|
109
|
+
from mapyta import Map, StrokeStyle, FillStyle
|
|
110
|
+
|
|
111
|
+
m = Map()
|
|
112
|
+
m.add_polygon(
|
|
113
|
+
Polygon([(4.9, 52.3), (5.0, 52.3), (5.0, 52.4), (4.9, 52.4)]),
|
|
114
|
+
stroke=StrokeStyle(color="#e74c3c", weight=2),
|
|
115
|
+
fill=FillStyle(color="#e74c3c", opacity=0.15),
|
|
116
|
+
)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
You can also pass plain dicts as a shorthand:
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
m.add_polygon(poly, stroke={"color": "#e74c3c", "weight": 2})
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
**How do I change the marker icon?**
|
|
128
|
+
|
|
129
|
+
Pass an emoji or a [Font Awesome 6](https://fontawesome.com/icons) icon name to `marker`:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
m.add_point(Point(4.9, 52.37), marker="📍") # emoji
|
|
133
|
+
m.add_point(Point(4.9, 52.37), marker="location-dot") # Font Awesome
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Tooltips & popups
|
|
139
|
+
|
|
140
|
+
**How do I add a tooltip with formatted text?**
|
|
141
|
+
|
|
142
|
+
Pass a Markdown string to `tooltip`:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
m.add_point(Point(4.9, 52.37), tooltip="**Amsterdam** — population 872 680")
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
For full HTML control, wrap the string in `RawHTML`:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from mapyta import RawHTML
|
|
152
|
+
|
|
153
|
+
m.add_point(Point(4.9, 52.37), tooltip=RawHTML("<b>Amsterdam</b><br>Pop: 872 680"))
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Layers
|
|
159
|
+
|
|
160
|
+
**How do I create toggleable layers?**
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from shapely.geometry import Point, Polygon
|
|
164
|
+
from mapyta import Map
|
|
165
|
+
|
|
166
|
+
m = Map()
|
|
167
|
+
|
|
168
|
+
m.create_feature_group("Museums")
|
|
169
|
+
m.add_point(Point(4.9, 52.37), marker="🏛️", tooltip="Rijksmuseum")
|
|
170
|
+
|
|
171
|
+
m.create_feature_group("Parks")
|
|
172
|
+
m.add_polygon(Polygon([(4.88, 52.35), (4.92, 52.35), (4.92, 52.38), (4.88, 52.38)]))
|
|
173
|
+
|
|
174
|
+
m.reset_target()
|
|
175
|
+
m.add_layer_control()
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Export
|
|
181
|
+
|
|
182
|
+
**How do I save the map to an HTML file?**
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
m.to_html("map.html")
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Pass `open_in_browser=True` to open it immediately:
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
m.to_html("map.html", open_in_browser=True)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
**How do I export to PNG?**
|
|
197
|
+
|
|
198
|
+
Install the optional export dependency first:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
pip install mapyta[export]
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Then:
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
m.to_image("map.png", width=1600, height=900)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Chrome or Chromium must be installed.
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
**How do I export the map features as GeoJSON?**
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
# Return a dict
|
|
218
|
+
fc = m.to_geojson()
|
|
219
|
+
|
|
220
|
+
# Write to file
|
|
221
|
+
m.to_geojson("features.geojson")
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
**How do I use mapyta in FastAPI or another async web framework?**
|
|
227
|
+
|
|
228
|
+
Use the async variants so Selenium doesn't block the event loop:
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
png_bytes = await m.to_image_async()
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
For HTML or GeoJSON (which don't use Selenium), call the synchronous methods directly — they are non-blocking.
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## GeoPandas
|
|
239
|
+
|
|
240
|
+
**How do I build a map directly from a GeoDataFrame?**
|
|
241
|
+
|
|
242
|
+
```python
|
|
243
|
+
import geopandas as gpd
|
|
244
|
+
from mapyta import Map
|
|
245
|
+
|
|
246
|
+
gdf = gpd.read_file("municipalities.geojson")
|
|
247
|
+
m = Map.from_geodataframe(gdf, hover_columns=["name"])
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
**I get a warning about missing columns. What does it mean?**
|
|
253
|
+
|
|
254
|
+
If a column name passed to `hover_columns`, `popup_columns`, `label_column`, or `color_column` does not exist in the GeoDataFrame, mapyta emits a `UserWarning`:
|
|
255
|
+
|
|
256
|
+
```
|
|
257
|
+
UserWarning: from_geodataframe(): hover_columns contains column(s) not found
|
|
258
|
+
in the GeoDataFrame: ['nonexistent']. Available columns: ['name', 'geometry']
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Check the column names with `gdf.columns` and correct the argument.
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## Drawing tools
|
|
266
|
+
|
|
267
|
+
**How do I let users draw shapes on the map?**
|
|
268
|
+
|
|
269
|
+
```python
|
|
270
|
+
m.enable_draw(tools=["polygon", "marker"])
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Valid tools: `"marker"`, `"polyline"`, `"polygon"`, `"rectangle"`, `"circle"`.
|
|
274
|
+
|
|
275
|
+
When the user clicks Submit, the drawn shapes are downloaded as a GeoJSON file by default. Pass `on_submit` to send the data to a URL or call a JavaScript function instead.
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## Escape hatch
|
|
280
|
+
|
|
281
|
+
**How do I access the underlying Folium map object?**
|
|
282
|
+
|
|
283
|
+
```python
|
|
284
|
+
import folium
|
|
285
|
+
m = Map()
|
|
286
|
+
# ... add geometries ...
|
|
287
|
+
folium_map = m.folium_map # the underlying folium.Map instance
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
This gives you access to every Folium and Leaflet feature not exposed by mapyta.
|