mapyta 0.1.0__tar.gz → 0.2.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.1.0 → mapyta-0.2.0}/.github/workflows/lint.yml +1 -1
- {mapyta-0.1.0 → mapyta-0.2.0}/.gitignore +1 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/PKG-INFO +7 -7
- {mapyta-0.1.0 → mapyta-0.2.0}/README.md +6 -6
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/tutorial/advanced.md +6 -6
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/tutorial/choropleth.md +7 -7
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/tutorial/clusters.md +2 -2
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/tutorial/configuration.md +7 -7
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/tutorial/coordinates.md +4 -4
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/tutorial/drawing.md +0 -28
- mapyta-0.2.0/docs/tutorial/export.md +123 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/tutorial/first-map.md +8 -8
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/tutorial/geodataframe.md +3 -3
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/tutorial/geometries.md +51 -23
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/tutorial/heatmaps.md +2 -2
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/tutorial/index.md +2 -1
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/tutorial/layers.md +6 -6
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/tutorial/markers.md +9 -9
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/tutorial/text-annotations.md +12 -12
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/tutorial/tooltips-popups.md +10 -10
- {mapyta-0.1.0 → mapyta-0.2.0}/mapyta/config.py +0 -3
- {mapyta-0.1.0 → mapyta-0.2.0}/mapyta/coordinates.py +1 -1
- {mapyta-0.1.0 → mapyta-0.2.0}/mapyta/map.py +200 -164
- {mapyta-0.1.0 → mapyta-0.2.0}/pyproject.toml +1 -1
- {mapyta-0.1.0 → mapyta-0.2.0}/tests/test_data.py +171 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/tests/test_draw.py +3 -189
- {mapyta-0.1.0 → mapyta-0.2.0}/tests/test_export.py +0 -75
- {mapyta-0.1.0 → mapyta-0.2.0}/tests/test_map.py +0 -75
- mapyta-0.1.0/docs/tutorial/export.md +0 -70
- {mapyta-0.1.0 → mapyta-0.2.0}/.github/workflows/docs.yml +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/.github/workflows/publish.yml +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/.github/workflows/tests.yml +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/.pre-commit-config.yaml +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/.ruff.toml +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/LICENSE +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/.nav.yml +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/_overrides/assets/images/favicon.ico +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/_overrides/assets/images/logo-dark-mode.svg +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/_overrides/assets/images/mapyta-logo-dark-mode.svg +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/_overrides/assets/images/mapyta-logo-light-mode.svg +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/_overrides/assets/javascripts/katex.js +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/_overrides/assets/stylesheets/extra.css +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/_overrides/main.html +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/_scripts/__init__.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/_scripts/generate_index.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/_scripts/generate_reference_pages.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/docs/tutorial/.nav.yml +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/mapyta/__init__.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/mapyta/export.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/mapyta/geojson.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/mapyta/markdown.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/mapyta/markers.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/mapyta/style.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/mapyta/tiles.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/properdocs.yml +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/tests/__init__.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/tests/conftest.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/tests/test_geometry.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/tests/test_layers.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/tests/test_map_creation.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/tests/test_markers.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/tests/test_merge_and_chaining.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/tests/test_utilities.py +0 -0
- {mapyta-0.1.0 → mapyta-0.2.0}/uv.lock +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mapyta
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Mapyta, open source python package for GIS mapping and visualization.
|
|
5
5
|
License: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -57,7 +57,7 @@ but rather to provide a simple way to create interactive maps without needing to
|
|
|
57
57
|
- 🎨 **Choropleth & heatmaps** — color-coded maps from numeric data
|
|
58
58
|
- 📊 **GeoPandas integration** — `Map.from_geodataframe()` one-liner
|
|
59
59
|
- 🌐 **Auto CRS detection** — RD New (EPSG:28992) coordinates transform automatically
|
|
60
|
-
- 📤 **Export anywhere** — HTML, PNG, SVG, async variants, and `BytesIO` buffers
|
|
60
|
+
- 📤 **Export anywhere** — HTML, PNG, SVG, GeoJSON, async variants, and `BytesIO` buffers
|
|
61
61
|
- 🧩 **Feature groups** — toggleable layers with a built-in layer control
|
|
62
62
|
- 🔌 **Set of tile providers** — OpenStreetMap, CartoDB, Esri, Stamen, and Kadaster
|
|
63
63
|
|
|
@@ -152,12 +152,12 @@ Create your first map:
|
|
|
152
152
|
from shapely.geometry import Point
|
|
153
153
|
from mapyta import Map
|
|
154
154
|
|
|
155
|
-
m = Map(title="Hello
|
|
155
|
+
m = Map(title="Hello Utrecht")
|
|
156
156
|
m.add_point(
|
|
157
|
-
point=Point(
|
|
158
|
-
tooltip="**
|
|
159
|
-
popup="
|
|
160
|
-
caption="
|
|
157
|
+
point=Point(5.121311, 52.090648),
|
|
158
|
+
tooltip="**Utrecht**",
|
|
159
|
+
popup="**Utrecht**\nCity in the Netherlands\nPopulation: ~350k",
|
|
160
|
+
caption="UTR",
|
|
161
161
|
)
|
|
162
162
|
m.to_html("hello.html")
|
|
163
163
|
|
|
@@ -33,7 +33,7 @@ but rather to provide a simple way to create interactive maps without needing to
|
|
|
33
33
|
- 🎨 **Choropleth & heatmaps** — color-coded maps from numeric data
|
|
34
34
|
- 📊 **GeoPandas integration** — `Map.from_geodataframe()` one-liner
|
|
35
35
|
- 🌐 **Auto CRS detection** — RD New (EPSG:28992) coordinates transform automatically
|
|
36
|
-
- 📤 **Export anywhere** — HTML, PNG, SVG, async variants, and `BytesIO` buffers
|
|
36
|
+
- 📤 **Export anywhere** — HTML, PNG, SVG, GeoJSON, async variants, and `BytesIO` buffers
|
|
37
37
|
- 🧩 **Feature groups** — toggleable layers with a built-in layer control
|
|
38
38
|
- 🔌 **Set of tile providers** — OpenStreetMap, CartoDB, Esri, Stamen, and Kadaster
|
|
39
39
|
|
|
@@ -128,12 +128,12 @@ Create your first map:
|
|
|
128
128
|
from shapely.geometry import Point
|
|
129
129
|
from mapyta import Map
|
|
130
130
|
|
|
131
|
-
m = Map(title="Hello
|
|
131
|
+
m = Map(title="Hello Utrecht")
|
|
132
132
|
m.add_point(
|
|
133
|
-
point=Point(
|
|
134
|
-
tooltip="**
|
|
135
|
-
popup="
|
|
136
|
-
caption="
|
|
133
|
+
point=Point(5.121311, 52.090648),
|
|
134
|
+
tooltip="**Utrecht**",
|
|
135
|
+
popup="**Utrecht**\nCity in the Netherlands\nPopulation: ~350k",
|
|
136
|
+
caption="UTR",
|
|
137
137
|
)
|
|
138
138
|
m.to_html("hello.html")
|
|
139
139
|
|
|
@@ -9,12 +9,12 @@ from shapely.geometry import Point, Polygon
|
|
|
9
9
|
from mapyta import Map
|
|
10
10
|
|
|
11
11
|
museums = Map(title="Combined")
|
|
12
|
-
museums.add_point(point=Point(
|
|
12
|
+
museums.add_point(point=Point(5.1213, 52.0908), marker="🏛️", tooltip="**Dom Tower**")
|
|
13
13
|
|
|
14
14
|
parks = Map()
|
|
15
15
|
parks.add_polygon(
|
|
16
|
-
polygon=Polygon([(
|
|
17
|
-
tooltip="**
|
|
16
|
+
polygon=Polygon([(5.1215, 52.0828), (5.1282, 52.0828), (5.1282, 52.0881), (5.1215, 52.0881)]),
|
|
17
|
+
tooltip="**Wilhelminapark**",
|
|
18
18
|
)
|
|
19
19
|
|
|
20
20
|
combined = museums + parks
|
|
@@ -23,7 +23,7 @@ combined.to_html("merged.html")
|
|
|
23
23
|
print(combined.to_html())
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
You can chain as many maps together as you like
|
|
26
|
+
You can chain as many maps together as you like, `a + b + c`, and all geometries and layers combine.
|
|
27
27
|
|
|
28
28
|
## GeoJSON layers
|
|
29
29
|
|
|
@@ -40,7 +40,7 @@ geojson = {
|
|
|
40
40
|
"properties": {"name": "Zone A", "type": "residential"},
|
|
41
41
|
"geometry": {
|
|
42
42
|
"type": "Polygon",
|
|
43
|
-
"coordinates": [[[
|
|
43
|
+
"coordinates": [[[5.10, 52.08], [5.12, 52.08], [5.12, 52.09], [5.10, 52.09], [5.10, 52.08]]],
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
46
|
],
|
|
@@ -73,7 +73,7 @@ m = Map(title="Custom Folium")
|
|
|
73
73
|
folium_map = m.folium_map
|
|
74
74
|
|
|
75
75
|
# Add anything Folium supports directly
|
|
76
|
-
folium.CircleMarker([52.
|
|
76
|
+
folium.CircleMarker([52.09, 5.12], radius=50, color="red").add_to(folium_map)
|
|
77
77
|
|
|
78
78
|
m.to_html("custom.html")
|
|
79
79
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Choropleth Maps
|
|
2
2
|
|
|
3
|
-
A "choropleth" is a map where areas are shaded by a numeric value
|
|
3
|
+
A "choropleth" is a map where areas are shaded by a numeric value, think population density, liveability scores, or soil classifications. Map builds one from a GeoJSON FeatureCollection and a value column.
|
|
4
4
|
|
|
5
5
|
```python exec="true" html="true" source="tabbed-right"
|
|
6
6
|
from mapyta import Map
|
|
@@ -10,10 +10,10 @@ geojson = {
|
|
|
10
10
|
"features": [
|
|
11
11
|
{
|
|
12
12
|
"type": "Feature",
|
|
13
|
-
"properties": {"name": "
|
|
13
|
+
"properties": {"name": "Binnenstad", "score": 92},
|
|
14
14
|
"geometry": {
|
|
15
15
|
"type": "Polygon",
|
|
16
|
-
"coordinates": [[[
|
|
16
|
+
"coordinates": [[[5.10, 52.08], [5.14, 52.08], [5.14, 52.10], [5.10, 52.10], [5.10, 52.08]]],
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
19
|
{
|
|
@@ -21,7 +21,7 @@ geojson = {
|
|
|
21
21
|
"properties": {"name": "West", "score": 74},
|
|
22
22
|
"geometry": {
|
|
23
23
|
"type": "Polygon",
|
|
24
|
-
"coordinates": [[[
|
|
24
|
+
"coordinates": [[[5.06, 52.08], [5.10, 52.08], [5.10, 52.10], [5.06, 52.10], [5.06, 52.08]]],
|
|
25
25
|
},
|
|
26
26
|
},
|
|
27
27
|
{
|
|
@@ -29,7 +29,7 @@ geojson = {
|
|
|
29
29
|
"properties": {"name": "Oost", "score": 85},
|
|
30
30
|
"geometry": {
|
|
31
31
|
"type": "Polygon",
|
|
32
|
-
"coordinates": [[[
|
|
32
|
+
"coordinates": [[[5.14, 52.08], [5.18, 52.08], [5.18, 52.10], [5.14, 52.10], [5.14, 52.08]]],
|
|
33
33
|
},
|
|
34
34
|
},
|
|
35
35
|
],
|
|
@@ -56,10 +56,10 @@ print(m.to_html()) # markdown-exec: hide
|
|
|
56
56
|
|
|
57
57
|
**`key_on`** is the dot-path to the join key inside each feature (Folium convention). For properties it's always `"feature.properties.<key>"`.
|
|
58
58
|
|
|
59
|
-
If you don't pass `values` explicitly, Map reads them straight from the GeoJSON properties
|
|
59
|
+
If you don't pass `values` explicitly, Map reads them straight from the GeoJSON properties, which is usually what you want.
|
|
60
60
|
|
|
61
61
|
**`hover_fields`** turns property keys into a tooltip table on mouse-over.
|
|
62
62
|
|
|
63
63
|
!!! tip "Multiple ways to pass GeoJSON"
|
|
64
64
|
|
|
65
|
-
`geojson_data` accepts a dict, a JSON string, or a `Path` to a `.geojson` file
|
|
65
|
+
`geojson_data` accepts a dict, a JSON string, or a `Path` to a `.geojson` file, Map handles all three.
|
|
@@ -8,11 +8,11 @@ from shapely.geometry import Point
|
|
|
8
8
|
from mapyta import Map
|
|
9
9
|
|
|
10
10
|
random.seed(42)
|
|
11
|
-
cafes = [Point(
|
|
11
|
+
cafes = [Point(5.12 + random.uniform(-0.02, 0.02), 52.09 + random.uniform(-0.01, 0.01)) for _ in range(50)]
|
|
12
12
|
labels = ["☕"] * 50
|
|
13
13
|
hovers = [f"**Café #{i + 1}**" for i in range(50)]
|
|
14
14
|
|
|
15
|
-
m = Map(title="
|
|
15
|
+
m = Map(title="Utrecht Cafés")
|
|
16
16
|
m.add_marker_cluster(points=cafes, labels=labels, hovers=hovers, name="Cafés")
|
|
17
17
|
|
|
18
18
|
m.to_html("clusters.html")
|
|
@@ -16,7 +16,7 @@ config = MapConfig(
|
|
|
16
16
|
)
|
|
17
17
|
|
|
18
18
|
m = Map(title="Dark Mode", config=config)
|
|
19
|
-
m.add_point(Point(
|
|
19
|
+
m.add_point(Point(5.1213, 52.0908), marker="🌃", tooltip="**Night Utrecht**")
|
|
20
20
|
|
|
21
21
|
m.to_html("dark_mode.html")
|
|
22
22
|
|
|
@@ -47,18 +47,18 @@ print(m.to_html()) # markdown-exec: hide
|
|
|
47
47
|
| `openstreetmap` | Default OpenStreetMap |
|
|
48
48
|
| `cartodb_positron` | Light, minimal CartoDB (default) |
|
|
49
49
|
| `cartodb_dark` | Dark CartoDB |
|
|
50
|
-
| `cartodb_voyager` | CartoDB Voyager
|
|
50
|
+
| `cartodb_voyager` | CartoDB Voyager, colourful, detailed |
|
|
51
51
|
| `esri_satellite` | Esri satellite imagery |
|
|
52
52
|
| `esri_topo` | Esri topographic |
|
|
53
53
|
| `esri_streets` | Esri street map |
|
|
54
54
|
| `esri_gray` | Esri light gray canvas |
|
|
55
55
|
| `esri_ocean` | Esri ocean basemap |
|
|
56
|
-
| `opentopomap` | OpenTopoMap
|
|
56
|
+
| `opentopomap` | OpenTopoMap, topographic with contour lines |
|
|
57
57
|
| `stamen_terrain` | Stamen terrain with hillshading |
|
|
58
58
|
| `stamen_toner` | Stamen high-contrast B&W |
|
|
59
|
-
| `stamen_watercolor` | Stamen watercolor
|
|
60
|
-
| `stadia_alidade` | Stadia Alidade Smooth
|
|
61
|
-
| `stadia_dark` | Stadia Alidade Dark
|
|
59
|
+
| `stamen_watercolor` | Stamen watercolor, artistic style |
|
|
60
|
+
| `stadia_alidade` | Stadia Alidade Smooth, clean, light |
|
|
61
|
+
| `stadia_dark` | Stadia Alidade Dark, modern dark theme |
|
|
62
62
|
| `kadaster_brt` | Dutch Kadaster topographic |
|
|
63
63
|
| `kadaster_luchtfoto` | Dutch Kadaster aerial photos |
|
|
64
64
|
| `kadaster_grijs` | Dutch Kadaster greyscale |
|
|
@@ -77,7 +77,7 @@ m = Map(
|
|
|
77
77
|
tile_layer=["kartodb_positron", "cartodb_dark", "kadaster_brt"],
|
|
78
78
|
),
|
|
79
79
|
)
|
|
80
|
-
m.add_point(Point(
|
|
80
|
+
m.add_point(Point(5.1213, 52.0908), marker="📍", tooltip="**Utrecht**")
|
|
81
81
|
m.add_layer_control(collapsed=False)
|
|
82
82
|
|
|
83
83
|
print(m.to_html()) # markdown-exec: hide
|
|
@@ -9,9 +9,9 @@ from mapyta import Map
|
|
|
9
9
|
# These are RD New coordinates (x: 0–300k, y: 300k–625k)
|
|
10
10
|
m = Map(title="RD New Auto-Detection")
|
|
11
11
|
m.add_point(
|
|
12
|
-
point=Point(
|
|
12
|
+
point=Point(136_100, 455_900),
|
|
13
13
|
marker="📍",
|
|
14
|
-
tooltip="**
|
|
14
|
+
tooltip="**Utrecht** (from RD New coordinates)",
|
|
15
15
|
)
|
|
16
16
|
|
|
17
17
|
m.to_html("rd_new.html")
|
|
@@ -23,7 +23,7 @@ print(m.to_html()) # markdown-exec: hide
|
|
|
23
23
|
|
|
24
24
|
Map checks whether the x-coordinate is between 0–300,000 and y is between 300,000–625,000. If so, it assumes EPSG:28992 (RD New) and transforms to WGS84 via pyproj.
|
|
25
25
|
|
|
26
|
-
For coordinates outside that range, nothing happens
|
|
26
|
+
For coordinates outside that range, nothing happens, they're assumed to be WGS84 already.
|
|
27
27
|
|
|
28
28
|
You can also set the CRS explicitly on the constructor:
|
|
29
29
|
|
|
@@ -33,4 +33,4 @@ m = Map(title="Explicit CRS", source_crs="EPSG:28992")
|
|
|
33
33
|
|
|
34
34
|
!!! info "Mixing CRS systems"
|
|
35
35
|
|
|
36
|
-
Auto-detection runs on the first coordinate of each geometry. This means you can't mix RD New and WGS84 geometries on the same map without setting `source_crs` explicitly on the constructor
|
|
36
|
+
Auto-detection runs on the first coordinate of each geometry. This means you can't mix RD New and WGS84 geometries on the same map without setting `source_crs` explicitly on the constructor, doing so will force all geometries through the same transformation.
|
|
@@ -72,40 +72,12 @@ m.enable_draw(on_submit="myGlobalHandler")
|
|
|
72
72
|
|
|
73
73
|
This generates `window["myGlobalHandler"](geojson)`.
|
|
74
74
|
|
|
75
|
-
## VIKTOR integration (BETA)
|
|
76
|
-
|
|
77
|
-
When building apps on [VIKTOR](https://viktor.ai), use `viktor_params` to send drawn geometries back to the Python controller via `viktorSdk.sendParams()`:
|
|
78
|
-
|
|
79
|
-
```python exec="true" html="true" source="tabbed-right"
|
|
80
|
-
from mapyta import Map
|
|
81
|
-
|
|
82
|
-
m = Map(title="Draw a route")
|
|
83
|
-
m.enable_draw(
|
|
84
|
-
tools=["marker", "polyline", "polygon"],
|
|
85
|
-
viktor_params={
|
|
86
|
-
"marker": "geopoint",
|
|
87
|
-
"polyline": "geopolyline",
|
|
88
|
-
"polygon": "geopolygon",
|
|
89
|
-
},
|
|
90
|
-
submit_label="Verzenden",
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
print(m.to_html()) # markdown-exec: hide
|
|
94
|
-
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
Each key in `viktor_params` must match a tool in `tools`. The values are the VIKTOR parameter field names. Coordinates are automatically converted from GeoJSON `[lon, lat]` to VIKTOR's `{lat, lon}` format.
|
|
98
|
-
|
|
99
|
-
!!! note
|
|
100
|
-
The `"circle"` tool is not supported with `viktor_params` because VIKTOR has no matching geometry type.
|
|
101
|
-
|
|
102
75
|
## DrawConfig reference
|
|
103
76
|
|
|
104
77
|
| Field | Default | Description |
|
|
105
78
|
|-------|---------|-------------|
|
|
106
79
|
| `tools` | `["polyline", "polygon", "marker"]` | Active drawing tools |
|
|
107
80
|
| `on_submit` | `None` (download) | Callback: `None`, URL, function name, or `RawJS` |
|
|
108
|
-
| `viktor_params` | `None` | VIKTOR field mapping (overrides `on_submit`) |
|
|
109
81
|
| `position` | `"topleft"` | Toolbar position |
|
|
110
82
|
| `submit_label` | `"Submit"` | Submit button text |
|
|
111
83
|
| `draw_style` | `None` | `shapeOptions` override |
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Export
|
|
2
|
+
|
|
3
|
+
## HTML (always works)
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
# Write to file
|
|
7
|
+
m.to_html("map.html")
|
|
8
|
+
|
|
9
|
+
# Get HTML as a string
|
|
10
|
+
html_string = m.to_html()
|
|
11
|
+
|
|
12
|
+
# Write and open immediately in the browser
|
|
13
|
+
m.to_html("map.html", open_in_browser=True)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Writes a standalone HTML file. No server needed, just open in any browser. Useful for sharing with clients or embedding in reports.
|
|
17
|
+
|
|
18
|
+
## PNG image
|
|
19
|
+
|
|
20
|
+
!!! warning "Requires the `export` optional dependency"
|
|
21
|
+
|
|
22
|
+
PNG and SVG export use Selenium with headless Chrome. Install the extra:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install mapyta[export]
|
|
26
|
+
# or
|
|
27
|
+
uv add mapyta[export]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Chrome or Chromium must also be installed. `chromedriver-autoinstaller` will attempt to install `chromedriver` automatically if it's not found on your PATH.
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
# Save to file
|
|
34
|
+
m.to_image("map.png", width=1600, height=1000, delay=3.0)
|
|
35
|
+
|
|
36
|
+
# Get raw PNG bytes
|
|
37
|
+
png_bytes = m.to_image()
|
|
38
|
+
|
|
39
|
+
# Get a BytesIO buffer (useful for Django/Flask/FastAPI responses)
|
|
40
|
+
buf = m.to_bytesio(width=1200, height=800)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The `delay` parameter (seconds) controls how long Map waits for tiles to load before taking the screenshot. Increase it on slow connections.
|
|
44
|
+
|
|
45
|
+
## GeoJSON
|
|
46
|
+
|
|
47
|
+
Export all features added to the map as a GeoJSON `FeatureCollection`:
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
# Return a dict
|
|
51
|
+
fc = m.to_geojson()
|
|
52
|
+
|
|
53
|
+
# Write to file
|
|
54
|
+
m.to_geojson("map.geojson")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Each feature in the collection carries the geometry (in WGS84) and the properties passed when it was added, tooltip text, popup text, marker name, style values, and so on:
|
|
58
|
+
|
|
59
|
+
```python exec="true" html="true" source="tabbed-right" result="ansi"
|
|
60
|
+
from shapely.geometry import Point, LineString
|
|
61
|
+
from mapyta import Map, StrokeStyle
|
|
62
|
+
|
|
63
|
+
m = (
|
|
64
|
+
Map()
|
|
65
|
+
.add_point(Point(5.121, 52.091), marker="📍", tooltip="Dom Tower")
|
|
66
|
+
.add_linestring(
|
|
67
|
+
LineString([(5.109, 52.089), (5.121, 52.091)]),
|
|
68
|
+
tooltip="Route",
|
|
69
|
+
stroke=StrokeStyle(color="#e74c3c", weight=3),
|
|
70
|
+
)
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
fc = m.to_geojson()
|
|
74
|
+
|
|
75
|
+
print(fc) # markdown-exec: hide
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The output is standard [RFC 7946](https://datatracker.ietf.org/doc/html/rfc7946) GeoJSON, compatible with QGIS, ArcGIS, Mapbox, and any other GIS tool. GitHub and GitLab automatically render `.geojson` files as interactive maps.
|
|
80
|
+
|
|
81
|
+
## Download button
|
|
82
|
+
|
|
83
|
+
`add_export_button()` adds a button to the map UI that lets users download the current features as a GeoJSON file, no back-end required:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
m.add_export_button()
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The button embeds the GeoJSON data directly in the HTML and triggers a browser download on click. The default label is `Download GeoJSON` and the file is saved as `export.geojson`.
|
|
90
|
+
|
|
91
|
+
Customise via keyword arguments:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
m.add_export_button(
|
|
95
|
+
label="Download GeoJSON",
|
|
96
|
+
filename="my_map.geojson",
|
|
97
|
+
position="bottomleft", # topleft | topright | bottomleft | bottomright
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Like all `add_*` and configuration methods, `add_export_button()` is chainable:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
m = (
|
|
105
|
+
Map()
|
|
106
|
+
.add_point(Point(5.121, 52.091), marker="📍")
|
|
107
|
+
.add_export_button()
|
|
108
|
+
)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
!!! note "Snapshot at render time"
|
|
112
|
+
|
|
113
|
+
The GeoJSON embedded in the button is captured when the map is first rendered (on the first call to `to_html()` or `open()`). Features added *after* rendering are not included. Call `to_geojson()` directly if you need the data on the Python side.
|
|
114
|
+
|
|
115
|
+
## Async variants
|
|
116
|
+
|
|
117
|
+
For web frameworks (FastAPI, Starlette, etc.) that run an async event loop:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
png_bytes = await m.to_image_async()
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
This runs the Selenium capture in a thread executor so it doesn't block the event loop.
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# Your First Map
|
|
2
2
|
|
|
3
|
-
Let's start with the absolute minimum
|
|
3
|
+
Let's start with the absolute minimum, a single point on a map, exported to HTML.
|
|
4
4
|
|
|
5
5
|
```python exec="true" html="true" source="tabbed-right"
|
|
6
6
|
from shapely.geometry import Point
|
|
7
7
|
from mapyta import Map
|
|
8
8
|
|
|
9
|
-
m = Map(title="Hello
|
|
9
|
+
m = Map(title="Hello Utrecht")
|
|
10
10
|
m.add_point(
|
|
11
|
-
point=Point(
|
|
12
|
-
tooltip="**
|
|
13
|
-
popup="**
|
|
14
|
-
caption="
|
|
11
|
+
point=Point(5.121311, 52.090648),
|
|
12
|
+
tooltip="**Utrecht**",
|
|
13
|
+
popup="**Utrecht**\n THe most beatiful Dutch city :-)\nPopulation: ~350k",
|
|
14
|
+
caption="UTR",
|
|
15
15
|
)
|
|
16
16
|
|
|
17
17
|
m.to_html("hello.html")
|
|
@@ -23,13 +23,13 @@ Open `hello.html` and you'll see an interactive OpenStreetMap centered on Amster
|
|
|
23
23
|
|
|
24
24
|
## How it works
|
|
25
25
|
|
|
26
|
-
**`Map(title="Hello Amsterdam")`** creates a new map. The `title` shows as a floating label at the top. You didn't pass a `center
|
|
26
|
+
**`Map(title="Hello Amsterdam")`** creates a new map. The `title` shows as a floating label at the top. You didn't pass a `center`, that's fine. Map auto-fits the viewport to whatever geometries you add.
|
|
27
27
|
|
|
28
28
|
**`add_point()`** takes a Shapely `Point(longitude, latitude)`. The `tooltip` parameter accepts Markdown, so `**Amsterdam**` renders as bold text.
|
|
29
29
|
|
|
30
30
|
**`caption`** places a small text label just below the marker.
|
|
31
31
|
|
|
32
|
-
**`to_html()`** writes a standalone HTML file. No server needed
|
|
32
|
+
**`to_html()`** writes a standalone HTML file. No server needed, just open it in a browser. Call it without a path to get the HTML as a string instead.
|
|
33
33
|
|
|
34
34
|
!!! tip "Fluent chaining"
|
|
35
35
|
|
|
@@ -19,9 +19,9 @@ from mapyta import Map
|
|
|
19
19
|
|
|
20
20
|
gdf = gpd.GeoDataFrame(
|
|
21
21
|
{
|
|
22
|
-
"name": ["
|
|
23
|
-
"population": [872_680, 651_446
|
|
24
|
-
"geometry": [Point(
|
|
22
|
+
"name": ["Utrecht", "Amsterdam", "Rotterdam"],
|
|
23
|
+
"population": [361_924, 872_680, 651_446],
|
|
24
|
+
"geometry": [Point(5.1214, 52.0907), Point(4.9041, 52.3676), Point(4.4777, 51.9244)],
|
|
25
25
|
},
|
|
26
26
|
crs="EPSG:4326",
|
|
27
27
|
)
|
|
@@ -1,44 +1,50 @@
|
|
|
1
1
|
# Lines & Polygons
|
|
2
2
|
|
|
3
|
-
Points are useful, but maps really come alive with shapes. Let's draw a walking route and highlight a neighbourhood.
|
|
3
|
+
Points are useful, but maps really come alive with shapes. Let's draw a walking route and highlight a neighbourhood in Utrecht.
|
|
4
4
|
|
|
5
5
|
```python exec="true" html="true" source="tabbed-right"
|
|
6
6
|
from shapely.geometry import LineString, Polygon
|
|
7
7
|
from mapyta import Map, StrokeStyle, FillStyle
|
|
8
8
|
|
|
9
|
-
m = Map(title="
|
|
9
|
+
m = Map(title="Utrecht Walk")
|
|
10
10
|
|
|
11
11
|
route = LineString([
|
|
12
|
-
(
|
|
13
|
-
(
|
|
14
|
-
(
|
|
15
|
-
(
|
|
12
|
+
(5.1097, 52.0894), # Centraal Station
|
|
13
|
+
(5.1133, 52.0934), # Vredenburg
|
|
14
|
+
(5.1197, 52.0919), # Neude
|
|
15
|
+
(5.1213, 52.0908), # Dom Tower
|
|
16
16
|
])
|
|
17
17
|
m.add_linestring(
|
|
18
18
|
line=route,
|
|
19
|
-
tooltip="**Walking route**\n*Centraal →
|
|
19
|
+
tooltip="**Walking route**\n*Centraal → Dom Tower*",
|
|
20
20
|
stroke=StrokeStyle(color="#e74c3c", weight=4, dash_array="10 6"),
|
|
21
21
|
)
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
(
|
|
25
|
-
(
|
|
23
|
+
wittevrouwen = Polygon([
|
|
24
|
+
(5.1195, 52.0915), # SW near Dom Tower
|
|
25
|
+
(5.1242, 52.0897), # S along Drift
|
|
26
|
+
(5.1298, 52.0893), # SE bend
|
|
27
|
+
(5.1362, 52.0908), # E along Singel (south)
|
|
28
|
+
(5.1378, 52.0948), # NE corner
|
|
29
|
+
(5.1318, 52.0975), # N Wittevrouwensingel
|
|
30
|
+
(5.1252, 52.0970), # NW notch
|
|
31
|
+
(5.1208, 52.0952), # W back toward Dom
|
|
26
32
|
])
|
|
27
33
|
m.add_polygon(
|
|
28
|
-
polygon=
|
|
29
|
-
tooltip="**
|
|
34
|
+
polygon=wittevrouwen,
|
|
35
|
+
tooltip="**Wittevrouwen**\nHistoric neighbourhood",
|
|
30
36
|
stroke=StrokeStyle(color="#2ecc71", weight=2),
|
|
31
37
|
fill=FillStyle(color="#2ecc71", opacity=0.15),
|
|
32
38
|
)
|
|
33
39
|
|
|
34
|
-
m.to_html("
|
|
40
|
+
m.to_html("utrecht_walk.html")
|
|
35
41
|
|
|
36
42
|
print(m.to_html()) # markdown-exec: hide # markdown-exec: hide
|
|
37
43
|
```
|
|
38
44
|
|
|
39
45
|
## How it works
|
|
40
46
|
|
|
41
|
-
**Coordinates are always `(longitude, latitude)
|
|
47
|
+
**Coordinates are always `(longitude, latitude)`**, that's the Shapely convention (x, y). Map handles the flip to Leaflet's `(lat, lon)` internally.
|
|
42
48
|
|
|
43
49
|
**`StrokeStyle`** controls borders and lines. Fields: `color`, `weight` (pixels), `opacity`, and `dash_array` (SVG pattern like `"10 6"` for dashes).
|
|
44
50
|
|
|
@@ -63,7 +69,10 @@ print(m.to_html()) # markdown-exec: hide # markdown-exec: hide
|
|
|
63
69
|
from mapyta import Map
|
|
64
70
|
|
|
65
71
|
m = Map(title="Quick styling")
|
|
66
|
-
poly = Polygon([
|
|
72
|
+
poly = Polygon([
|
|
73
|
+
(5.100, 52.080), (5.120, 52.076), (5.138, 52.083),
|
|
74
|
+
(5.133, 52.095), (5.114, 52.099), (5.101, 52.090),
|
|
75
|
+
])
|
|
67
76
|
|
|
68
77
|
m.add_polygon(
|
|
69
78
|
poly,
|
|
@@ -83,8 +92,14 @@ print(m.to_html()) # markdown-exec: hide # markdown-exec: hide
|
|
|
83
92
|
m = Map(title="Reusable styles")
|
|
84
93
|
my_stroke = StrokeStyle(color="red", weight=4)
|
|
85
94
|
|
|
86
|
-
poly1 = Polygon([
|
|
87
|
-
|
|
95
|
+
poly1 = Polygon([
|
|
96
|
+
(5.100, 52.080), (5.120, 52.076), (5.138, 52.083),
|
|
97
|
+
(5.133, 52.095), (5.114, 52.099), (5.101, 52.090),
|
|
98
|
+
])
|
|
99
|
+
poly2 = Polygon([
|
|
100
|
+
(5.082, 52.088), (5.098, 52.083), (5.108, 52.091),
|
|
101
|
+
(5.102, 52.101), (5.083, 52.098), (5.076, 52.093),
|
|
102
|
+
])
|
|
88
103
|
m.add_polygon(poly1, stroke=my_stroke)
|
|
89
104
|
m.add_polygon(poly2, stroke=my_stroke)
|
|
90
105
|
|
|
@@ -93,12 +108,25 @@ print(m.to_html()) # markdown-exec: hide # markdown-exec: hide
|
|
|
93
108
|
|
|
94
109
|
!!! tip "Polygons with holes"
|
|
95
110
|
|
|
96
|
-
Pass interior rings as the second argument to `Polygon
|
|
111
|
+
Pass interior rings as the second argument to `Polygon`, they render as cutouts:
|
|
97
112
|
|
|
98
|
-
```python
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
113
|
+
```python exec="true" html="true" source="tabbed-left"
|
|
114
|
+
from shapely.geometry import Polygon
|
|
115
|
+
from mapyta import Map
|
|
116
|
+
|
|
117
|
+
m = Map(title="Wilhelminapark")
|
|
118
|
+
wilhelminapark = Polygon(
|
|
119
|
+
[
|
|
120
|
+
(5.1215, 52.0835), (5.1252, 52.0828), (5.1278, 52.0838),
|
|
121
|
+
(5.1282, 52.0863), (5.1262, 52.0880), (5.1232, 52.0881),
|
|
122
|
+
(5.1203, 52.0868), (5.1198, 52.0848),
|
|
123
|
+
],
|
|
124
|
+
[[
|
|
125
|
+
(5.1228, 52.0848), (5.1255, 52.0845), (5.1260, 52.0860),
|
|
126
|
+
(5.1242, 52.0867), (5.1222, 52.0859),
|
|
127
|
+
]],
|
|
102
128
|
)
|
|
103
|
-
m.add_polygon(
|
|
129
|
+
m.add_polygon(wilhelminapark, tooltip="**Wilhelminapark**, the hole is the pond!")
|
|
130
|
+
|
|
131
|
+
print(m.to_html()) # markdown-exec: hide
|
|
104
132
|
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Heatmaps
|
|
2
2
|
|
|
3
|
-
For dense point data
|
|
3
|
+
For dense point data, sensor readings, incidents, GPS traces, a heatmap shows intensity patterns better than individual markers.
|
|
4
4
|
|
|
5
5
|
```python exec="true" html="true" source="tabbed-right"
|
|
6
6
|
import random
|
|
@@ -9,7 +9,7 @@ from mapyta import Map, HeatmapStyle
|
|
|
9
9
|
|
|
10
10
|
random.seed(42)
|
|
11
11
|
points = [
|
|
12
|
-
Point(
|
|
12
|
+
Point(5.12 + random.gauss(0, 0.03), 52.09 + random.gauss(0, 0.015))
|
|
13
13
|
for _ in range(200)
|
|
14
14
|
]
|
|
15
15
|
|
|
@@ -29,5 +29,6 @@ pip install mapyta
|
|
|
29
29
|
| [Coordinate Detection](coordinates.md) | Automatic RD New → WGS84 transformation |
|
|
30
30
|
| [Map Configuration](configuration.md) | Tile providers, zoom, and optional plugins |
|
|
31
31
|
| [Text Annotations](text-annotations.md) | Floating labels and site plan markers |
|
|
32
|
-
| [Export](export.md) | HTML, PNG, SVG, async,
|
|
32
|
+
| [Export](export.md) | HTML, PNG, SVG, GeoJSON, download button, async, BytesIO |
|
|
33
|
+
| [Drawing Tools](drawing.md) | Let users draw on the map and capture their input |
|
|
33
34
|
| [Advanced](advanced.md) | Merge maps, GeoJSON layers, escape hatch |
|