mapyta 0.2.0__tar.gz → 0.4.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.4.0/.github/workflows/docs-preview.yml +76 -0
- mapyta-0.4.0/.github/workflows/docs.yml +30 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/.github/workflows/lint.yml +1 -1
- {mapyta-0.2.0 → mapyta-0.4.0}/.github/workflows/publish.yml +1 -1
- {mapyta-0.2.0 → mapyta-0.4.0}/.github/workflows/tests.yml +1 -1
- {mapyta-0.2.0 → mapyta-0.4.0}/.gitignore +4 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/PKG-INFO +2 -1
- {mapyta-0.2.0 → mapyta-0.4.0}/README.md +1 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/tutorial/.nav.yml +5 -0
- mapyta-0.4.0/docs/tutorial/animated.md +209 -0
- mapyta-0.4.0/docs/tutorial/choropleth.md +216 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/tutorial/clusters.md +3 -3
- mapyta-0.4.0/docs/tutorial/dataframe.md +115 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/tutorial/drawing.md +6 -7
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/tutorial/export.md +15 -0
- mapyta-0.4.0/docs/tutorial/faq.md +359 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/tutorial/index.md +5 -0
- mapyta-0.4.0/docs/tutorial/layers.md +102 -0
- mapyta-0.4.0/docs/tutorial/min-zoom.md +113 -0
- mapyta-0.4.0/docs/tutorial/open-data.md +211 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/tutorial/tooltips-popups.md +31 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/mapyta/__init__.py +6 -1
- {mapyta-0.2.0 → mapyta-0.4.0}/mapyta/config.py +14 -7
- mapyta-0.4.0/mapyta/dataframe.py +118 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/mapyta/export.py +10 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/mapyta/map.py +687 -94
- {mapyta-0.2.0 → mapyta-0.4.0}/mapyta/style.py +15 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/mapyta/tiles.py +24 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/pyproject.toml +5 -1
- mapyta-0.4.0/tests/test_dataframe.py +467 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/tests/test_draw.py +1 -1
- {mapyta-0.2.0 → mapyta-0.4.0}/tests/test_export.py +63 -1
- {mapyta-0.2.0 → mapyta-0.4.0}/tests/test_geometry.py +2 -2
- {mapyta-0.2.0 → mapyta-0.4.0}/tests/test_layers.py +280 -3
- {mapyta-0.2.0 → mapyta-0.4.0}/tests/test_map.py +514 -8
- {mapyta-0.2.0 → mapyta-0.4.0}/tests/test_utilities.py +2 -2
- {mapyta-0.2.0 → mapyta-0.4.0}/uv.lock +37 -1
- mapyta-0.2.0/.github/workflows/docs.yml +0 -36
- mapyta-0.2.0/docs/tutorial/choropleth.md +0 -65
- mapyta-0.2.0/docs/tutorial/layers.md +0 -44
- {mapyta-0.2.0 → mapyta-0.4.0}/.pre-commit-config.yaml +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/.ruff.toml +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/LICENSE +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/.nav.yml +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/_overrides/assets/images/favicon.ico +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/_overrides/assets/images/logo-dark-mode.svg +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/_overrides/assets/images/mapyta-logo-dark-mode.svg +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/_overrides/assets/images/mapyta-logo-light-mode.svg +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/_overrides/assets/javascripts/katex.js +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/_overrides/assets/stylesheets/extra.css +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/_overrides/main.html +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/_scripts/__init__.py +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/_scripts/generate_index.py +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/_scripts/generate_reference_pages.py +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/tutorial/advanced.md +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/tutorial/configuration.md +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/tutorial/coordinates.md +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/tutorial/first-map.md +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/tutorial/geodataframe.md +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/tutorial/geometries.md +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/tutorial/heatmaps.md +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/tutorial/markers.md +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/docs/tutorial/text-annotations.md +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/mapyta/coordinates.py +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/mapyta/geojson.py +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/mapyta/markdown.py +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/mapyta/markers.py +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/properdocs.yml +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/tests/__init__.py +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/tests/conftest.py +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/tests/test_data.py +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/tests/test_map_creation.py +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/tests/test_markers.py +0 -0
- {mapyta-0.2.0 → mapyta-0.4.0}/tests/test_merge_and_chaining.py +0 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
name: Docs preview
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [opened, reopened, synchronize, closed]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: write
|
|
9
|
+
pull-requests: write
|
|
10
|
+
|
|
11
|
+
concurrency:
|
|
12
|
+
group: docs-preview-pr-${{ github.event.pull_request.number }}
|
|
13
|
+
cancel-in-progress: true
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
preview:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v5
|
|
20
|
+
|
|
21
|
+
- if: github.event.action != 'closed'
|
|
22
|
+
uses: astral-sh/setup-uv@v5
|
|
23
|
+
with:
|
|
24
|
+
python-version: "3.13"
|
|
25
|
+
|
|
26
|
+
- if: github.event.action != 'closed'
|
|
27
|
+
name: Install docs dependencies
|
|
28
|
+
run: uv sync --group docs
|
|
29
|
+
|
|
30
|
+
- if: github.event.action != 'closed'
|
|
31
|
+
name: Build docs
|
|
32
|
+
run: uv run properdocs build --clean --strict
|
|
33
|
+
|
|
34
|
+
- name: Deploy preview
|
|
35
|
+
if: github.event.action != 'closed'
|
|
36
|
+
uses: JamesIves/github-pages-deploy-action@v4
|
|
37
|
+
with:
|
|
38
|
+
folder: site
|
|
39
|
+
target-folder: pr-preview/pr-${{ github.event.pull_request.number }}
|
|
40
|
+
clean: false
|
|
41
|
+
|
|
42
|
+
- name: Comment preview URL
|
|
43
|
+
if: github.event.action != 'closed'
|
|
44
|
+
uses: actions/github-script@v7
|
|
45
|
+
with:
|
|
46
|
+
script: |
|
|
47
|
+
const url = `https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/`;
|
|
48
|
+
const body = `## 📖 Docs preview\n\n🔗 ${url}\n\n_Updated on every push. Removed when the PR is closed._`;
|
|
49
|
+
const { data: comments } = await github.rest.issues.listComments({
|
|
50
|
+
owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number,
|
|
51
|
+
});
|
|
52
|
+
const bot = comments.find(c => c.user.type === 'Bot' && c.body.includes('Docs preview'));
|
|
53
|
+
if (bot) {
|
|
54
|
+
await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: bot.id, body });
|
|
55
|
+
} else {
|
|
56
|
+
await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, body });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
- name: Remove preview on close
|
|
60
|
+
if: github.event.action == 'closed'
|
|
61
|
+
env:
|
|
62
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
63
|
+
run: |
|
|
64
|
+
# Skip if gh-pages branch doesn't exist yet
|
|
65
|
+
git ls-remote --heads https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git gh-pages \
|
|
66
|
+
| grep -q gh-pages || exit 0
|
|
67
|
+
PR_NUM=${{ github.event.pull_request.number }}
|
|
68
|
+
git clone --depth=1 --branch=gh-pages \
|
|
69
|
+
https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git /tmp/gh-pages
|
|
70
|
+
rm -rf /tmp/gh-pages/pr-preview/pr-${PR_NUM}
|
|
71
|
+
cd /tmp/gh-pages
|
|
72
|
+
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
73
|
+
git config user.name "github-actions[bot]"
|
|
74
|
+
git add -A
|
|
75
|
+
git diff --quiet HEAD || git commit -m "chore: remove docs preview for PR #${PR_NUM}"
|
|
76
|
+
git push
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Publish docs
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: write
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
docs:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v5
|
|
15
|
+
|
|
16
|
+
- uses: astral-sh/setup-uv@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: "3.13"
|
|
19
|
+
|
|
20
|
+
- name: Install docs dependencies
|
|
21
|
+
run: uv sync --group docs
|
|
22
|
+
|
|
23
|
+
- name: Build docs
|
|
24
|
+
run: uv run properdocs build --clean --strict
|
|
25
|
+
|
|
26
|
+
- name: Deploy to GitHub Pages
|
|
27
|
+
uses: JamesIves/github-pages-deploy-action@v4
|
|
28
|
+
with:
|
|
29
|
+
folder: site
|
|
30
|
+
clean-exclude: pr-preview
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mapyta
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.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,216 @@
|
|
|
1
|
+
# Choropleth Maps
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
```python exec="true" html="true" source="tabbed-right"
|
|
6
|
+
from mapyta import Map
|
|
7
|
+
|
|
8
|
+
geojson = {
|
|
9
|
+
"type": "FeatureCollection",
|
|
10
|
+
"features": [
|
|
11
|
+
{
|
|
12
|
+
"type": "Feature",
|
|
13
|
+
"properties": {"name": "Binnenstad", "score": 92},
|
|
14
|
+
"geometry": {
|
|
15
|
+
"type": "Polygon",
|
|
16
|
+
"coordinates": [[[5.10, 52.08], [5.14, 52.08], [5.14, 52.10], [5.10, 52.10], [5.10, 52.08]]],
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"type": "Feature",
|
|
21
|
+
"properties": {"name": "West", "score": 74},
|
|
22
|
+
"geometry": {
|
|
23
|
+
"type": "Polygon",
|
|
24
|
+
"coordinates": [[[5.06, 52.08], [5.10, 52.08], [5.10, 52.10], [5.06, 52.10], [5.06, 52.08]]],
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"type": "Feature",
|
|
29
|
+
"properties": {"name": "Oost", "score": 85},
|
|
30
|
+
"geometry": {
|
|
31
|
+
"type": "Polygon",
|
|
32
|
+
"coordinates": [[[5.14, 52.08], [5.18, 52.08], [5.18, 52.10], [5.14, 52.10], [5.14, 52.08]]],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
m = Map(title="Neighbourhood Scores")
|
|
39
|
+
m.add_choropleth(
|
|
40
|
+
geojson_data=geojson,
|
|
41
|
+
value_column="score",
|
|
42
|
+
key_on="feature.properties.name",
|
|
43
|
+
legend_name="Liveability Score",
|
|
44
|
+
hover_fields=["name", "score"],
|
|
45
|
+
fill_opacity=0.7,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
m.to_html("choropleth.html")
|
|
49
|
+
|
|
50
|
+
print(m.to_html()) # markdown-exec: hide
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## How it works
|
|
54
|
+
|
|
55
|
+
**`value_column`** tells Map which GeoJSON property holds the numeric value.
|
|
56
|
+
|
|
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
|
+
|
|
59
|
+
If you don't pass `values` explicitly, Map reads them straight from the GeoJSON properties, which is usually what you want.
|
|
60
|
+
|
|
61
|
+
**`hover_fields`** turns property keys into a tooltip table on mouse-over.
|
|
62
|
+
|
|
63
|
+
!!! tip "Multiple ways to pass GeoJSON"
|
|
64
|
+
|
|
65
|
+
`geojson_data` accepts a dict, a JSON string, or a `Path` to a `.geojson` file, Map handles all three.
|
|
66
|
+
|
|
67
|
+
## Custom color palettes
|
|
68
|
+
|
|
69
|
+
By default choropleths use a yellow-to-red gradient (`"ylrd"`). Pass a named palette or a list of hex colors to the `colors` parameter:
|
|
70
|
+
|
|
71
|
+
```python exec="true" html="true" source="tabbed-right"
|
|
72
|
+
from mapyta import Map
|
|
73
|
+
|
|
74
|
+
geojson = {
|
|
75
|
+
"type": "FeatureCollection",
|
|
76
|
+
"features": [
|
|
77
|
+
{
|
|
78
|
+
"type": "Feature",
|
|
79
|
+
"properties": {"name": "Binnenstad", "score": 92},
|
|
80
|
+
"geometry": {
|
|
81
|
+
"type": "Polygon",
|
|
82
|
+
"coordinates": [[[5.10, 52.08], [5.14, 52.08], [5.14, 52.10], [5.10, 52.10], [5.10, 52.08]]],
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"type": "Feature",
|
|
87
|
+
"properties": {"name": "West", "score": 74},
|
|
88
|
+
"geometry": {
|
|
89
|
+
"type": "Polygon",
|
|
90
|
+
"coordinates": [[[5.06, 52.08], [5.10, 52.08], [5.10, 52.10], [5.06, 52.10], [5.06, 52.08]]],
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"type": "Feature",
|
|
95
|
+
"properties": {"name": "Oost", "score": 85},
|
|
96
|
+
"geometry": {
|
|
97
|
+
"type": "Polygon",
|
|
98
|
+
"coordinates": [[[5.14, 52.08], [5.18, 52.08], [5.18, 52.10], [5.14, 52.10], [5.14, 52.08]]],
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
m = Map(title="Neighbourhood Scores — Blues palette")
|
|
105
|
+
m.add_choropleth(
|
|
106
|
+
geojson_data=geojson,
|
|
107
|
+
value_column="score",
|
|
108
|
+
key_on="feature.properties.name",
|
|
109
|
+
legend_name="Liveability Score",
|
|
110
|
+
hover_fields=["name", "score"],
|
|
111
|
+
fill_opacity=0.7,
|
|
112
|
+
colors="blues",
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
print(m.to_html()) # markdown-exec: hide
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
You can also pass a custom list of hex colors (ordered from low to high values):
|
|
119
|
+
|
|
120
|
+
```python exec="true" html="true" source="tabbed-right"
|
|
121
|
+
from mapyta import Map
|
|
122
|
+
|
|
123
|
+
geojson = {
|
|
124
|
+
"type": "FeatureCollection",
|
|
125
|
+
"features": [
|
|
126
|
+
{
|
|
127
|
+
"type": "Feature",
|
|
128
|
+
"properties": {"name": "Binnenstad", "score": 92},
|
|
129
|
+
"geometry": {
|
|
130
|
+
"type": "Polygon",
|
|
131
|
+
"coordinates": [[[5.10, 52.08], [5.14, 52.08], [5.14, 52.10], [5.10, 52.10], [5.10, 52.08]]],
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"type": "Feature",
|
|
136
|
+
"properties": {"name": "West", "score": 74},
|
|
137
|
+
"geometry": {
|
|
138
|
+
"type": "Polygon",
|
|
139
|
+
"coordinates": [[[5.06, 52.08], [5.10, 52.08], [5.10, 52.10], [5.06, 52.10], [5.06, 52.08]]],
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"type": "Feature",
|
|
144
|
+
"properties": {"name": "Oost", "score": 85},
|
|
145
|
+
"geometry": {
|
|
146
|
+
"type": "Polygon",
|
|
147
|
+
"coordinates": [[[5.14, 52.08], [5.18, 52.08], [5.18, 52.10], [5.14, 52.10], [5.14, 52.08]]],
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
m = Map(title="Neighbourhood Scores — Custom colors")
|
|
154
|
+
m.add_choropleth(
|
|
155
|
+
geojson_data=geojson,
|
|
156
|
+
value_column="score",
|
|
157
|
+
key_on="feature.properties.name",
|
|
158
|
+
legend_name="Liveability Score",
|
|
159
|
+
hover_fields=["name", "score"],
|
|
160
|
+
fill_opacity=0.7,
|
|
161
|
+
colors=["#f7fbff", "#6baed6", "#084594"],
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
print(m.to_html()) # markdown-exec: hide
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
All available palette names are exposed in `mapyta.PALETTES`:
|
|
168
|
+
|
|
169
|
+
```python exec="true" result="ansi" source="tabbed-right"
|
|
170
|
+
from mapyta import PALETTES
|
|
171
|
+
|
|
172
|
+
print(list(PALETTES.keys()))
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The same `colors` parameter works on `Map.from_geodataframe()` when using `color_column`.
|
|
176
|
+
|
|
177
|
+
## Categorical data
|
|
178
|
+
|
|
179
|
+
If your values are string categories (land use type, municipality class, etc.), set `categorical=True` or pass string values and mapyta auto-detects them. Each unique category gets a distinct color from the palette:
|
|
180
|
+
|
|
181
|
+
```python exec="true" html="true" source="tabbed-right"
|
|
182
|
+
from mapyta import Map
|
|
183
|
+
|
|
184
|
+
geojson = {
|
|
185
|
+
"type": "FeatureCollection",
|
|
186
|
+
"features": [
|
|
187
|
+
{
|
|
188
|
+
"type": "Feature",
|
|
189
|
+
"properties": {"name": "Binnenstad", "type": "urban"},
|
|
190
|
+
"geometry": {"type": "Polygon", "coordinates": [[[5.10, 52.08], [5.14, 52.08], [5.14, 52.10], [5.10, 52.10], [5.10, 52.08]]]},
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"type": "Feature",
|
|
194
|
+
"properties": {"name": "West", "type": "suburban"},
|
|
195
|
+
"geometry": {"type": "Polygon", "coordinates": [[[5.06, 52.08], [5.10, 52.08], [5.10, 52.10], [5.06, 52.10], [5.06, 52.08]]]},
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
"type": "Feature",
|
|
199
|
+
"properties": {"name": "Oost", "type": "urban"},
|
|
200
|
+
"geometry": {"type": "Polygon", "coordinates": [[[5.14, 52.08], [5.18, 52.08], [5.18, 52.10], [5.14, 52.10], [5.14, 52.08]]]},
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
m = Map(title="Area Types")
|
|
206
|
+
m.add_choropleth(
|
|
207
|
+
geojson_data=geojson,
|
|
208
|
+
value_column="type",
|
|
209
|
+
key_on="feature.properties.name",
|
|
210
|
+
legend_name="Area type",
|
|
211
|
+
colors="spectral",
|
|
212
|
+
hover_fields=["name", "type"],
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
print(m.to_html()) # markdown-exec: hide
|
|
216
|
+
```
|
|
@@ -10,10 +10,10 @@ from mapyta import Map
|
|
|
10
10
|
random.seed(42)
|
|
11
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
|
+
tooltips = [f"**Café #{i + 1}**" for i in range(50)]
|
|
14
14
|
|
|
15
15
|
m = Map(title="Utrecht Cafés")
|
|
16
|
-
m.add_marker_cluster(points=cafes, labels=labels,
|
|
16
|
+
m.add_marker_cluster(points=cafes, labels=labels, tooltips=tooltips, name="Cafés")
|
|
17
17
|
|
|
18
18
|
m.to_html("clusters.html")
|
|
19
19
|
|
|
@@ -28,7 +28,7 @@ At low zoom you'll see cluster bubbles with counts. Zoom in and they split into
|
|
|
28
28
|
|-----------|-------------|
|
|
29
29
|
| `points` | List of Shapely `Point` objects |
|
|
30
30
|
| `labels` | Marker text per point (emoji, text, or FA icon name) |
|
|
31
|
-
| `
|
|
31
|
+
| `tooltips` | Markdown tooltip per point |
|
|
32
32
|
| `popups` | Markdown popup per point |
|
|
33
33
|
| `captions` | Text label below each marker |
|
|
34
34
|
| `marker_style` | CSS dict applied to all markers |
|