mapnetwork-mcp 1.1.0__tar.gz → 1.2.1__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.
- {mapnetwork_mcp-1.1.0 → mapnetwork_mcp-1.2.1}/PKG-INFO +21 -4
- {mapnetwork_mcp-1.1.0 → mapnetwork_mcp-1.2.1}/README.md +20 -3
- mapnetwork_mcp-1.2.1/images/Kanazawa21Museum-black.png +0 -0
- mapnetwork_mcp-1.2.1/images/Kanazawa21Museum-darkGreen.png +0 -0
- mapnetwork_mcp-1.2.1/images/Kanazawa21Museum-grey.png +0 -0
- mapnetwork_mcp-1.2.1/images/Kanazawa21Museum-lightGreen.png +0 -0
- mapnetwork_mcp-1.2.1/images/Kanazawa21Museum-popArt.png +0 -0
- mapnetwork_mcp-1.2.1/images/Kanazawa21Museum-white.png +0 -0
- {mapnetwork_mcp-1.1.0 → mapnetwork_mcp-1.2.1}/manifest.json +1 -1
- {mapnetwork_mcp-1.1.0 → mapnetwork_mcp-1.2.1}/mapnetwork_mcp/server.py +108 -71
- {mapnetwork_mcp-1.1.0 → mapnetwork_mcp-1.2.1}/pyproject.toml +1 -1
- mapnetwork_mcp-1.1.0/images/Kanazawa21Museum-beige.png +0 -0
- mapnetwork_mcp-1.1.0/images/Kanazawa21Museum-black.png +0 -0
- mapnetwork_mcp-1.1.0/images/Kanazawa21Museum-brawn.png +0 -0
- mapnetwork_mcp-1.1.0/images/Kanazawa21Museum-darkBlue.png +0 -0
- mapnetwork_mcp-1.1.0/images/Kanazawa21Museum-lightGreen.png +0 -0
- mapnetwork_mcp-1.1.0/images/Kanazawa21Museum-popArt.png +0 -0
- mapnetwork_mcp-1.1.0/images/Kanazawa21Museum-white.png +0 -0
- {mapnetwork_mcp-1.1.0 → mapnetwork_mcp-1.2.1}/.gitignore +0 -0
- {mapnetwork_mcp-1.1.0 → mapnetwork_mcp-1.2.1}/.mcpbignore +0 -0
- {mapnetwork_mcp-1.1.0 → mapnetwork_mcp-1.2.1}/LICENSE +0 -0
- {mapnetwork_mcp-1.1.0 → mapnetwork_mcp-1.2.1}/RELEASING.md +0 -0
- {mapnetwork_mcp-1.1.0 → mapnetwork_mcp-1.2.1}/mapnetwork_mcp/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mapnetwork-mcp
|
|
3
|
-
Version: 1.1
|
|
3
|
+
Version: 1.2.1
|
|
4
4
|
Summary: MCP server — generate styled map images via mapnetwork.app
|
|
5
5
|
Project-URL: Homepage, https://mapnetwork.app
|
|
6
6
|
Project-URL: Repository, https://github.com/toruproject/mapnetwork-mcp
|
|
@@ -34,9 +34,9 @@ Here is the map it generated:
|
|
|
34
34
|
|
|
35
35
|
The same map, redownloaded in different color themes:
|
|
36
36
|
|
|
37
|
-
|
|
|
38
|
-
|
|
39
|
-
| <img src="https://raw.githubusercontent.com/toruproject/mapnetwork-mcp/main/images/Kanazawa21Museum-
|
|
37
|
+
| Dark Green Style | Light Green Style | Pop Art Style | Black Style |
|
|
38
|
+
|:-------------------------------------------------------------------------------------------------------------------------------:|:--------------------------------------------------------------:|:----------------------------------------------------------------:|:---------------------------------------------------------:|
|
|
39
|
+
| <img src="https://raw.githubusercontent.com/toruproject/mapnetwork-mcp/main/images/Kanazawa21Museum-darkGreen.png" width="160"> | <img src="https://raw.githubusercontent.com/toruproject/mapnetwork-mcp/main/images/Kanazawa21Museum-lightGreen.png" width="160"> | <img src="https://raw.githubusercontent.com/toruproject/mapnetwork-mcp/main/images/Kanazawa21Museum-popArt.png" width="160"> | <img src="https://raw.githubusercontent.com/toruproject/mapnetwork-mcp/main/images/Kanazawa21Museum-black.png" width="160"> |
|
|
40
40
|
|
|
41
41
|
## Installation
|
|
42
42
|
|
|
@@ -82,6 +82,18 @@ pip install mapnetwork-mcp
|
|
|
82
82
|
}
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
+
## Remote MCP Server
|
|
86
|
+
|
|
87
|
+
You can also use MapNetwork through MCP without installing anything, via the remote MCP server:
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
https://mapnetwork.app/mcp
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
In Claude, go to **Settings** → **Connectors** → **Add custom connector** and register the URL above.
|
|
94
|
+
|
|
95
|
+
The key difference from this local server is how you receive the generated map image. Since `mapnetwork-mcp` runs on your PC, it can save the generated image directly to your Downloads folder. The remote server can't do this — most AI assistants are unable to properly display or save tool-result images within the chat — so instead of image data, it returns a text response with a download link and a link to edit the map at [mapnetwork.app](https://mapnetwork.app). Open the links in a browser to view or save the image, or to edit the map.
|
|
96
|
+
|
|
85
97
|
## Tools
|
|
86
98
|
|
|
87
99
|
| Tool | Description |
|
|
@@ -96,17 +108,22 @@ pip install mapnetwork-mcp
|
|
|
96
108
|
- "渋谷駅周辺の地図を作って"
|
|
97
109
|
- "赤坂駅から赤坂氷川神社までの徒歩ルートを地図にして"
|
|
98
110
|
- "東京駅・日本橋駅・京橋駅を1枚の地図に表示して"
|
|
111
|
+
- "日比谷公園の1キロ四方の地図を出して"
|
|
99
112
|
- "その地図を darkBlue テーマでSVG画像で出し直して"
|
|
113
|
+
- "生成した地図の編集用リンクをください"
|
|
100
114
|
|
|
101
115
|
**English**
|
|
102
116
|
- "Generate a map around Shibuya Station"
|
|
103
117
|
- "Show a walking route from Akasaka Station to Akasaka Hikawa Shrine on a map"
|
|
104
118
|
- "Put Tokyo Station, Nihonbashi Station, and Kyobashi Station on a single map"
|
|
119
|
+
- "Show a 1km square map of Hibiya Park"
|
|
105
120
|
- "Redownload that map as an SVG in the darkBlue theme"
|
|
121
|
+
- "Give me a link to edit the generated map"
|
|
106
122
|
|
|
107
123
|
## Links
|
|
108
124
|
|
|
109
125
|
- Web UI: [https://mapnetwork.app](https://mapnetwork.app)
|
|
126
|
+
- Web UI Manual: [https://mapnetwork.app/manual](https://mapnetwork.app/manual)
|
|
110
127
|
- API docs: [https://mapnetwork.app/openapi.json](https://mapnetwork.app/openapi.json)
|
|
111
128
|
|
|
112
129
|
mcp-name: io.github.toruproject/mapnetwork-mcp
|
|
@@ -22,9 +22,9 @@ Here is the map it generated:
|
|
|
22
22
|
|
|
23
23
|
The same map, redownloaded in different color themes:
|
|
24
24
|
|
|
25
|
-
|
|
|
26
|
-
|
|
27
|
-
| <img src="https://raw.githubusercontent.com/toruproject/mapnetwork-mcp/main/images/Kanazawa21Museum-
|
|
25
|
+
| Dark Green Style | Light Green Style | Pop Art Style | Black Style |
|
|
26
|
+
|:-------------------------------------------------------------------------------------------------------------------------------:|:--------------------------------------------------------------:|:----------------------------------------------------------------:|:---------------------------------------------------------:|
|
|
27
|
+
| <img src="https://raw.githubusercontent.com/toruproject/mapnetwork-mcp/main/images/Kanazawa21Museum-darkGreen.png" width="160"> | <img src="https://raw.githubusercontent.com/toruproject/mapnetwork-mcp/main/images/Kanazawa21Museum-lightGreen.png" width="160"> | <img src="https://raw.githubusercontent.com/toruproject/mapnetwork-mcp/main/images/Kanazawa21Museum-popArt.png" width="160"> | <img src="https://raw.githubusercontent.com/toruproject/mapnetwork-mcp/main/images/Kanazawa21Museum-black.png" width="160"> |
|
|
28
28
|
|
|
29
29
|
## Installation
|
|
30
30
|
|
|
@@ -70,6 +70,18 @@ pip install mapnetwork-mcp
|
|
|
70
70
|
}
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
+
## Remote MCP Server
|
|
74
|
+
|
|
75
|
+
You can also use MapNetwork through MCP without installing anything, via the remote MCP server:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
https://mapnetwork.app/mcp
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
In Claude, go to **Settings** → **Connectors** → **Add custom connector** and register the URL above.
|
|
82
|
+
|
|
83
|
+
The key difference from this local server is how you receive the generated map image. Since `mapnetwork-mcp` runs on your PC, it can save the generated image directly to your Downloads folder. The remote server can't do this — most AI assistants are unable to properly display or save tool-result images within the chat — so instead of image data, it returns a text response with a download link and a link to edit the map at [mapnetwork.app](https://mapnetwork.app). Open the links in a browser to view or save the image, or to edit the map.
|
|
84
|
+
|
|
73
85
|
## Tools
|
|
74
86
|
|
|
75
87
|
| Tool | Description |
|
|
@@ -84,17 +96,22 @@ pip install mapnetwork-mcp
|
|
|
84
96
|
- "渋谷駅周辺の地図を作って"
|
|
85
97
|
- "赤坂駅から赤坂氷川神社までの徒歩ルートを地図にして"
|
|
86
98
|
- "東京駅・日本橋駅・京橋駅を1枚の地図に表示して"
|
|
99
|
+
- "日比谷公園の1キロ四方の地図を出して"
|
|
87
100
|
- "その地図を darkBlue テーマでSVG画像で出し直して"
|
|
101
|
+
- "生成した地図の編集用リンクをください"
|
|
88
102
|
|
|
89
103
|
**English**
|
|
90
104
|
- "Generate a map around Shibuya Station"
|
|
91
105
|
- "Show a walking route from Akasaka Station to Akasaka Hikawa Shrine on a map"
|
|
92
106
|
- "Put Tokyo Station, Nihonbashi Station, and Kyobashi Station on a single map"
|
|
107
|
+
- "Show a 1km square map of Hibiya Park"
|
|
93
108
|
- "Redownload that map as an SVG in the darkBlue theme"
|
|
109
|
+
- "Give me a link to edit the generated map"
|
|
94
110
|
|
|
95
111
|
## Links
|
|
96
112
|
|
|
97
113
|
- Web UI: [https://mapnetwork.app](https://mapnetwork.app)
|
|
114
|
+
- Web UI Manual: [https://mapnetwork.app/manual](https://mapnetwork.app/manual)
|
|
98
115
|
- API docs: [https://mapnetwork.app/openapi.json](https://mapnetwork.app/openapi.json)
|
|
99
116
|
|
|
100
117
|
mcp-name: io.github.toruproject/mapnetwork-mcp
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"manifest_version": "0.4",
|
|
3
3
|
"name": "mapnetwork-mcp",
|
|
4
4
|
"display_name": "MapNetwork",
|
|
5
|
-
"version": "1.1
|
|
5
|
+
"version": "1.2.1",
|
|
6
6
|
"description": "Generate styled PNG/SVG map images of any location with 11 customizable color themes.",
|
|
7
7
|
"long_description": "MCP server for MapNetwork — generate styled map images (PNG / SVG) for any location on Earth, directly from Claude.\n\n- Generate maps from a place name, coordinates, or a list of markers\n- 11 color themes (white, darkBlue, darkGreen, popArt, lightBlue, lightGreen, beige, magenta, gray, black, brawn)\n- Overlay walking / driving routes on the map\n- PNG or SVG output, saved to your Downloads folder\n- Re-download a previously generated map in a different theme or format without regenerating\n- Open any generated map in the MapNetwork web editor for manual customization",
|
|
8
8
|
"author": {
|
|
@@ -5,15 +5,71 @@ import os
|
|
|
5
5
|
import re
|
|
6
6
|
from datetime import datetime
|
|
7
7
|
from pathlib import Path
|
|
8
|
-
from typing import Annotated
|
|
8
|
+
from typing import Annotated, Literal
|
|
9
9
|
|
|
10
10
|
import httpx
|
|
11
|
-
from mcp.server.fastmcp import FastMCP, Image
|
|
11
|
+
from mcp.server.fastmcp import Context, FastMCP, Image
|
|
12
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
12
13
|
|
|
13
14
|
BASE_URL = os.environ.get("MAPNETWORK_BASE_URL", "https://mapnetwork.app")
|
|
14
15
|
POLL_INTERVAL_SEC = 10.0
|
|
15
16
|
MAX_WAIT_SEC = 600
|
|
16
17
|
|
|
18
|
+
# layersは自由な多値配列にすると、モデルが「roadはhighway/driving/walkingの上位互換」
|
|
19
|
+
# といった内部の組み合わせルールを知らないまま組み合わせを選んでしまう。
|
|
20
|
+
# 人間側で意味のある4パターンだけに絞り込み、モデルにはこのプリセット名だけを選ばせる。
|
|
21
|
+
_LAYER_PRESETS: dict[str, list[str]] = {
|
|
22
|
+
"default": ["road", "poi"],
|
|
23
|
+
"road_and_railway": ["road", "railway", "poi"],
|
|
24
|
+
"only_driving_road": ["driving"],
|
|
25
|
+
"fully_detailed": ["road", "railway", "poi", "waterline", "greenarea"],
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Location(BaseModel):
|
|
30
|
+
lat: float
|
|
31
|
+
lng: float
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Marker(BaseModel):
|
|
35
|
+
label: str | None = Field(default=None, description="Place name for geocoding and/or display.")
|
|
36
|
+
location: Location | None = Field(
|
|
37
|
+
default=None,
|
|
38
|
+
description="Explicit coordinates. If provided, geocoding of 'label' is skipped.",
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class RouteEndpoint(BaseModel):
|
|
43
|
+
label: str | None = Field(default=None, description="Place name for geocoding and/or display.")
|
|
44
|
+
location: Location | None = Field(default=None, description="Explicit coordinates.")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class RouteInput(BaseModel):
|
|
48
|
+
"""generate_mapのrouteパラメータ。compute_routeの戻り値をそのまま渡せる形にする。"""
|
|
49
|
+
model_config = ConfigDict(populate_by_name=True)
|
|
50
|
+
|
|
51
|
+
coords: list[list[float]] | None = Field(
|
|
52
|
+
default=None, description="Ordered list of [lat, lng] pairs along the route."
|
|
53
|
+
)
|
|
54
|
+
mode: Literal["walking", "driving"] | None = None
|
|
55
|
+
from_: RouteEndpoint | None = Field(default=None, alias="from", description="Route start point.")
|
|
56
|
+
to: RouteEndpoint | None = Field(default=None, description="Route end point.")
|
|
57
|
+
color: str | None = Field(default=None, description="Optional line color as a CSS hex color (e.g. '#FF4500').")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class MapConfig(BaseModel):
|
|
61
|
+
patchworked: bool | None = Field(
|
|
62
|
+
default=None, description="Auto-color closed areas and building shapes on the drawing. Default true."
|
|
63
|
+
)
|
|
64
|
+
withBuilding: bool | None = Field(
|
|
65
|
+
default=None, description="Draw building shapes. Default true when building data is available."
|
|
66
|
+
)
|
|
67
|
+
withSeaRibbon: bool | None = Field(
|
|
68
|
+
default=None,
|
|
69
|
+
description="Draw a band representing the sea along the coastline. Default true when coastline data is available.",
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
17
73
|
mcp = FastMCP(
|
|
18
74
|
"MapNetwork",
|
|
19
75
|
instructions=(
|
|
@@ -29,10 +85,10 @@ mcp = FastMCP(
|
|
|
29
85
|
"- **Circular area**: specify `radius` in meters (default 500, max 2500) around the center\n"
|
|
30
86
|
"- **Rectangular area**: specify `size_ew` (east-west) and `size_ns` (north-south) in meters "
|
|
31
87
|
"instead of radius — useful when the area of interest is not square\n"
|
|
32
|
-
"- **Layers**: choose
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
88
|
+
"- **Layers**: choose a preset via `layers` — 'default' (roads + POI), "
|
|
89
|
+
"'only_driving_road' (car-accessible roads only), 'road_and_railway' (roads + railway, no POI), "
|
|
90
|
+
"or 'fully_detailed' (roads + railway + waterline + greenarea + POI; waterline/greenarea only "
|
|
91
|
+
"apply within Japan). Omit for 'default'.\n"
|
|
36
92
|
"- **Color themes** via `color_set`: "
|
|
37
93
|
"white (clean, default), darkBlue (navy bg), darkGreen (dark teal bg), "
|
|
38
94
|
"popArt (blue bg, bold contrast), lightBlue (pale blue bg), lightGreen (pale green bg), "
|
|
@@ -105,14 +161,13 @@ async def _download(client: httpx.AsyncClient, data_key: str, format: str,
|
|
|
105
161
|
@mcp.tool()
|
|
106
162
|
async def compute_route(
|
|
107
163
|
from_location: Annotated[
|
|
108
|
-
|
|
109
|
-
"Start point of the route. "
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"Example: {\"label\": \"赤坂駅\"}",
|
|
164
|
+
RouteEndpoint,
|
|
165
|
+
"Start point of the route. Provide 'location' for explicit coordinates (no geocoding), "
|
|
166
|
+
"or only 'label' to geocode server-side. Both may be provided — 'location' takes precedence, "
|
|
167
|
+
"'label' is used for display. Example: {\"label\": \"赤坂駅\"}",
|
|
113
168
|
],
|
|
114
169
|
to_location: Annotated[
|
|
115
|
-
|
|
170
|
+
RouteEndpoint,
|
|
116
171
|
"End point of the route. Same format as from_location. "
|
|
117
172
|
"Example: {\"label\": \"赤坂氷川神社\"}",
|
|
118
173
|
],
|
|
@@ -134,7 +189,11 @@ async def compute_route(
|
|
|
134
189
|
if mode not in ("walking", "driving"):
|
|
135
190
|
raise ValueError("mode must be 'walking' or 'driving'")
|
|
136
191
|
|
|
137
|
-
body = {
|
|
192
|
+
body = {
|
|
193
|
+
"from": from_location.model_dump(exclude_none=True),
|
|
194
|
+
"to": to_location.model_dump(exclude_none=True),
|
|
195
|
+
"mode": mode,
|
|
196
|
+
}
|
|
138
197
|
async with httpx.AsyncClient() as client:
|
|
139
198
|
resp = await client.post(f"{BASE_URL}/route", json=body, timeout=180)
|
|
140
199
|
if resp.status_code == 404:
|
|
@@ -177,25 +236,13 @@ async def generate_map(
|
|
|
177
236
|
"Omit when using markers-only mode.",
|
|
178
237
|
] = None,
|
|
179
238
|
markers: Annotated[
|
|
180
|
-
list[
|
|
239
|
+
list[Marker] | None,
|
|
181
240
|
"List of locations to pin on the map as blue markers. "
|
|
182
|
-
"Each item
|
|
183
|
-
"Optionally include explicit coordinates: {\"label\": \"...\", \"location\": {\"lat\": ..., \"lng\": ...}}. "
|
|
184
|
-
"Each marker may also include an optional \"icon\" field to override its appearance: "
|
|
185
|
-
"{\"label\": \"...\", \"icon\": {\"color\": \"#ff0000\"}}. "
|
|
186
|
-
"All icon sub-fields (code/size/color) are optional — omit any to keep the default. "
|
|
241
|
+
"Each item needs only a 'label' (geocoded automatically); explicit 'location' {lat, lng} is optional. "
|
|
187
242
|
"When markers are provided without place/lat/lng, the server derives the map center from their centroid "
|
|
188
243
|
"and sets radius automatically. "
|
|
189
244
|
"Example for two stations: [{\"label\": \"東京駅\"}, {\"label\": \"新宿駅\"}]",
|
|
190
245
|
] = None,
|
|
191
|
-
place_icon: Annotated[
|
|
192
|
-
dict | None,
|
|
193
|
-
"Custom icon for the `place` pin (or center pin if no `place`). "
|
|
194
|
-
"All fields are optional — specify only what you want to override. "
|
|
195
|
-
"Fields: code (FontAwesome \\uXXXX), size (pixels), color (CSS hex). "
|
|
196
|
-
"Example (red icon, larger): {\"color\": \"#ff0000\", \"size\": 50}. "
|
|
197
|
-
"Omit entirely to use the default icon.",
|
|
198
|
-
] = None,
|
|
199
246
|
name: Annotated[
|
|
200
247
|
str | None,
|
|
201
248
|
"Map name stored in the data file. Used as the default download filename. "
|
|
@@ -222,39 +269,24 @@ async def generate_map(
|
|
|
222
269
|
"ONLY set this when the user has explicitly requested a rectangular area of specific dimensions.",
|
|
223
270
|
] = None,
|
|
224
271
|
layers: Annotated[
|
|
225
|
-
|
|
226
|
-
"
|
|
227
|
-
"
|
|
228
|
-
"'
|
|
229
|
-
"'
|
|
230
|
-
"
|
|
231
|
-
"'
|
|
232
|
-
"'railway' — train and subway lines\n"
|
|
233
|
-
"'waterline' — rivers, lakes, and coastlines\n"
|
|
234
|
-
"'greenarea' — forests and woods\n"
|
|
235
|
-
"'poi' — point-of-interest icons (filterable with poi_types)\n"
|
|
236
|
-
"Example for road + railway + POI: ['road', 'railway', 'poi']",
|
|
237
|
-
] = None,
|
|
238
|
-
poi_types: Annotated[
|
|
239
|
-
list[str] | None,
|
|
240
|
-
"Filter POI categories when 'poi' is in layers. Omit to include all. "
|
|
241
|
-
"Valid values: museum, library, theatre, convenience, supermarket, "
|
|
242
|
-
"school, religion, station, park, hospital, cityhall, cafe, restaurant.",
|
|
272
|
+
Literal["default", "road_and_railway", "only_driving_road", "fully_detailed"] | None,
|
|
273
|
+
"Preset combination of map layers. 'default': roads + POI icons. "
|
|
274
|
+
"'only_driving_road': car-accessible roads only, nothing else. "
|
|
275
|
+
"'road_and_railway': roads + railway lines, no POI. "
|
|
276
|
+
"'fully_detailed': roads + railway + waterline + greenarea + POI "
|
|
277
|
+
"(waterline/greenarea only apply within Japan; ignored elsewhere). "
|
|
278
|
+
"Omit for 'default'.",
|
|
243
279
|
] = None,
|
|
244
280
|
route: Annotated[
|
|
245
|
-
|
|
281
|
+
RouteInput | None,
|
|
246
282
|
"Route to overlay on the map. Pass the full response from compute_route() directly — "
|
|
247
283
|
"the server uses coords and (optionally) color from it. "
|
|
248
|
-
"To customise the line color,
|
|
284
|
+
"To customise the line color, set/override the 'color' field (e.g. '#FF4500'). "
|
|
249
285
|
"Omit to generate a map without a route overlay.",
|
|
250
286
|
] = None,
|
|
251
287
|
config: Annotated[
|
|
252
|
-
|
|
288
|
+
MapConfig | None,
|
|
253
289
|
"Overrides for automatic layer-visibility defaults. Omit any field to keep the default. "
|
|
254
|
-
"Fields (all optional booleans): "
|
|
255
|
-
"'patchworked' (auto-color closed areas and building shapes, default true), "
|
|
256
|
-
"'withBuilding' (draw building shapes, default true when building data is available), "
|
|
257
|
-
"'withSeaRibbon' (draw a band representing the sea along the coastline, default true when coastline data is available). "
|
|
258
290
|
"Example to turn off buildings: {\"withBuilding\": false}.",
|
|
259
291
|
] = None,
|
|
260
292
|
color_set: Annotated[
|
|
@@ -269,12 +301,8 @@ async def generate_map(
|
|
|
269
301
|
"Output file format: 'png' (default, raster image) or 'svg' (vector, scalable to any size).",
|
|
270
302
|
] = "png",
|
|
271
303
|
canvas_width: Annotated[int | None, "Canvas width in pixels. Omit to use server default (1000)."] = None,
|
|
272
|
-
canvas_height: Annotated[int | None, "Canvas height in pixels. Omit to use server default (
|
|
273
|
-
|
|
274
|
-
int | None,
|
|
275
|
-
"Road and line width adjustment. Positive values thicken lines, negative values thin them. "
|
|
276
|
-
"Default 0 (no adjustment). Example: 2 to make roads slightly thicker, -1 to make them thinner.",
|
|
277
|
-
] = None,
|
|
304
|
+
canvas_height: Annotated[int | None, "Canvas height in pixels. Omit to use server default (600)."] = None,
|
|
305
|
+
ctx: Context = None,
|
|
278
306
|
) -> list:
|
|
279
307
|
"""Generate a styled map image for a given location and save it to Downloads.
|
|
280
308
|
|
|
@@ -288,8 +316,9 @@ async def generate_map(
|
|
|
288
316
|
without waiting for regeneration.
|
|
289
317
|
"""
|
|
290
318
|
has_center = place or (lat is not None and lng is not None)
|
|
291
|
-
|
|
292
|
-
|
|
319
|
+
has_route_coords = route is not None and route.coords is not None and len(route.coords) >= 2
|
|
320
|
+
if not has_center and not markers and not has_route_coords:
|
|
321
|
+
raise ValueError("Specify 'place', both 'lat'+'lng', 'markers', or a 'route' with coords.")
|
|
293
322
|
if radius is not None and (size_ew is not None or size_ns is not None):
|
|
294
323
|
raise ValueError("Specify either 'radius' or 'size_ew'+'size_ns', not both.")
|
|
295
324
|
if (size_ew is None) != (size_ns is None):
|
|
@@ -297,15 +326,13 @@ async def generate_map(
|
|
|
297
326
|
|
|
298
327
|
body: dict = {}
|
|
299
328
|
if layers is not None:
|
|
300
|
-
body["layers"] = layers
|
|
329
|
+
body["layers"] = _LAYER_PRESETS[layers]
|
|
301
330
|
if place:
|
|
302
331
|
body["place"] = place
|
|
303
332
|
elif lat is not None and lng is not None:
|
|
304
333
|
body["center"] = {"lat": lat, "lng": lng}
|
|
305
334
|
if markers is not None:
|
|
306
|
-
body["markers"] = markers
|
|
307
|
-
if place_icon is not None:
|
|
308
|
-
body["icon"] = place_icon
|
|
335
|
+
body["markers"] = [m.model_dump(exclude_none=True) for m in markers]
|
|
309
336
|
if name is not None:
|
|
310
337
|
body["name"] = name
|
|
311
338
|
if color_set is not None:
|
|
@@ -314,12 +341,10 @@ async def generate_map(
|
|
|
314
341
|
body["radius"] = radius
|
|
315
342
|
elif size_ew is not None:
|
|
316
343
|
body["size"] = {"ew": size_ew, "ns": size_ns}
|
|
317
|
-
if poi_types:
|
|
318
|
-
body["poiTypes"] = poi_types
|
|
319
344
|
if route is not None:
|
|
320
|
-
body["route"] = route
|
|
345
|
+
body["route"] = route.model_dump(by_alias=True, exclude_none=True)
|
|
321
346
|
if config is not None:
|
|
322
|
-
body["config"] = config
|
|
347
|
+
body["config"] = config.model_dump(exclude_none=True)
|
|
323
348
|
|
|
324
349
|
async with httpx.AsyncClient() as client:
|
|
325
350
|
# 1. Enqueue
|
|
@@ -333,6 +358,12 @@ async def generate_map(
|
|
|
333
358
|
data_key = resp.json()["dataKey"]
|
|
334
359
|
|
|
335
360
|
# 2. Poll until ready
|
|
361
|
+
# ポーリング中に進捗通知を送らないと、クライアント側のタイムアウトが
|
|
362
|
+
# (MAX_WAIT_SECより手前で)先に発火し、実際には裏で処理が続いているのに
|
|
363
|
+
# クライアントには失敗したように見えてしまう。report_progressはprogressToken
|
|
364
|
+
# が無いクライアントに対しては何もしない安全な呼び出しなので、常に呼んでよい。
|
|
365
|
+
if ctx is not None:
|
|
366
|
+
await ctx.report_progress(0, MAX_WAIT_SEC, "Map generation queued...")
|
|
336
367
|
elapsed = 0.0
|
|
337
368
|
while elapsed < MAX_WAIT_SEC:
|
|
338
369
|
await asyncio.sleep(POLL_INTERVAL_SEC)
|
|
@@ -348,19 +379,25 @@ async def generate_map(
|
|
|
348
379
|
f"Map generation failed (dataKey={data_key}). "
|
|
349
380
|
"Try a different location or smaller radius."
|
|
350
381
|
)
|
|
382
|
+
if ctx is not None:
|
|
383
|
+
await ctx.report_progress(
|
|
384
|
+
elapsed, MAX_WAIT_SEC, f"Map generation in progress... ({elapsed:.0f}s elapsed)"
|
|
385
|
+
)
|
|
351
386
|
else:
|
|
352
387
|
raise TimeoutError(f"Map generation timed out after {MAX_WAIT_SEC}s.")
|
|
353
388
|
|
|
354
389
|
# 3. Download
|
|
355
390
|
image_bytes = await _download(client, data_key, format, color_set,
|
|
356
|
-
canvas_width, canvas_height
|
|
391
|
+
canvas_width, canvas_height)
|
|
357
392
|
|
|
358
393
|
if place:
|
|
359
394
|
label = place
|
|
360
395
|
elif lat is not None and lng is not None:
|
|
361
396
|
label = f"{lat}_{lng}"
|
|
397
|
+
elif markers:
|
|
398
|
+
label = "_".join(m.label or "" for m in markers)[:40]
|
|
362
399
|
else:
|
|
363
|
-
label = "
|
|
400
|
+
label = "route"
|
|
364
401
|
out_path = _make_filename(label, format)
|
|
365
402
|
out_path.write_bytes(image_bytes)
|
|
366
403
|
|
|
@@ -397,7 +434,7 @@ async def redownload_map(
|
|
|
397
434
|
"'png' (raster) or 'svg' (vector, infinitely scalable).",
|
|
398
435
|
] = "png",
|
|
399
436
|
canvas_width: Annotated[int | None, "Canvas width in pixels. Omit to use server default (1000)."] = None,
|
|
400
|
-
canvas_height: Annotated[int | None, "Canvas height in pixels. Omit to use server default (
|
|
437
|
+
canvas_height: Annotated[int | None, "Canvas height in pixels. Omit to use server default (600)."] = None,
|
|
401
438
|
edge_weight: Annotated[
|
|
402
439
|
int | None,
|
|
403
440
|
"Road and line width adjustment. Positive values thicken lines, negative values thin them. "
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|