@maptec/cli 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +284 -0
- package/bin/maptec.js +2 -0
- package/dist/chunk-K574OFFK.js +122 -0
- package/dist/chunk-K574OFFK.js.map +1 -0
- package/dist/cli.js +899 -0
- package/dist/cli.js.map +1 -0
- package/dist/store-ZU7HLXCV.js +18 -0
- package/dist/store-ZU7HLXCV.js.map +1 -0
- package/package.json +47 -0
- package/skills/README.md +30 -0
- package/skills/jsapi-skills/README.md +60 -0
- package/skills/jsapi-skills/SKILL.md +145 -0
- package/skills/jsapi-skills/package.json +31 -0
- package/skills/jsapi-skills/references/controls.md +195 -0
- package/skills/jsapi-skills/references/events.md +222 -0
- package/skills/jsapi-skills/references/geocoding.md +184 -0
- package/skills/jsapi-skills/references/map-style.md +123 -0
- package/skills/jsapi-skills/references/map.md +154 -0
- package/skills/jsapi-skills/references/marker.md +136 -0
- package/skills/jsapi-skills/references/operate.md +138 -0
- package/skills/jsapi-skills/references/overlay.md +311 -0
- package/skills/jsapi-skills/references/place-search.md +411 -0
- package/skills/jsapi-skills/references/poi-categories.md +123 -0
- package/skills/jsapi-skills/references/popup.md +146 -0
- package/skills/jsapi-skills/references/re-geocoding.md +183 -0
- package/skills/jsapi-skills/references/routing.md +347 -0
- package/skills/jsapi-skills/references/track.md +240 -0
- package/skills/jsapi-skills/scripts/validate_jsapi_skill.py +160 -0
- package/skills/webapi-skills/README.md +73 -0
- package/skills/webapi-skills/SKILL.md +63 -0
- package/skills/webapi-skills/package.json +32 -0
- package/skills/webapi-skills/references/direction-api.md +175 -0
- package/skills/webapi-skills/references/geocoding.md +195 -0
- package/skills/webapi-skills/references/ip-location.md +87 -0
- package/skills/webapi-skills/references/matrix-api.md +149 -0
- package/skills/webapi-skills/references/nearby-search.md +223 -0
- package/skills/webapi-skills/references/places.md +239 -0
- package/skills/webapi-skills/references/quick-start-cn.md +219 -0
- package/skills/webapi-skills/references/reverse-geocoding.md +157 -0
- package/skills/webapi-skills/references/suggest.md +111 -0
- package/skills/webapi-skills/references/text-search.md +282 -0
- package/skills/webapi-skills/scripts/validate_webapi_skill.py +158 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Maptec Controls Reference
|
|
2
|
+
|
|
3
|
+
Use this reference when adding built-in map controls such as navigation, scale, fullscreen, compass, or hawkeye.
|
|
4
|
+
|
|
5
|
+
## 中文能力入口
|
|
6
|
+
|
|
7
|
+
本文件对应功能 **地图控件**:支持缩放导航、比例尺、全屏、指南针、鹰眼控件的位置配置、添加、移除与清理。
|
|
8
|
+
|
|
9
|
+
当前公开控件类:
|
|
10
|
+
|
|
11
|
+
- `Maptec.NavigationControl`
|
|
12
|
+
- `Maptec.ScaleControl`
|
|
13
|
+
- `Maptec.FullscreenControl`
|
|
14
|
+
- `Maptec.CompassControl`
|
|
15
|
+
- `Maptec.HawkeyeControl`
|
|
16
|
+
|
|
17
|
+
| 用户需求 | 优先实现 |
|
|
18
|
+
|---|---|
|
|
19
|
+
| “添加缩放控件” | `new Maptec.NavigationControl()` + `map.addControl(nav, position)` |
|
|
20
|
+
| “在地图右下角添加比例尺控件” | `new Maptec.ScaleControl()` + `map.addControl(scale, "bottom-right")` |
|
|
21
|
+
| “添加全屏按钮” | `new Maptec.FullscreenControl()` |
|
|
22
|
+
| “添加指南针控件” | `new Maptec.CompassControl()` 或使用 `NavigationControl` 内置指南针 |
|
|
23
|
+
| “添加鹰眼地图” | `new Maptec.HawkeyeControl(options)` |
|
|
24
|
+
| “隐藏/显示某个控件” | 保存 control 实例,使用 `map.addControl` / `map.removeControl` 切换 |
|
|
25
|
+
|
|
26
|
+
## Common Pattern
|
|
27
|
+
|
|
28
|
+
Controls are created with `new Maptec.XControl(...)` and added with `map.addControl(control, position?)`.
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
map.on("load", () => {
|
|
32
|
+
const scale = new Maptec.ScaleControl();
|
|
33
|
+
map.addControl(scale, "bottom-left");
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Supported positions:
|
|
38
|
+
|
|
39
|
+
- `"top-left"`
|
|
40
|
+
- `"top-right"`
|
|
41
|
+
- `"bottom-left"`
|
|
42
|
+
- `"bottom-right"`
|
|
43
|
+
|
|
44
|
+
Use `map.removeControl(control)` for cleanup when needed.
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
const controls = [];
|
|
48
|
+
|
|
49
|
+
function addControl(control, position) {
|
|
50
|
+
map.addControl(control, position);
|
|
51
|
+
controls.push(control);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function cleanup() {
|
|
55
|
+
controls.forEach((control) => map.removeControl(control));
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## NavigationControl
|
|
60
|
+
|
|
61
|
+
Contains zoom buttons and compass.
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
const nav = new Maptec.NavigationControl();
|
|
65
|
+
map.addControl(nav, "top-left");
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Use this when users need standard zoom and orientation controls.
|
|
69
|
+
|
|
70
|
+
## ScaleControl
|
|
71
|
+
|
|
72
|
+
Displays a distance scale.
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
const scale = new Maptec.ScaleControl({
|
|
76
|
+
maxWidth: 100,
|
|
77
|
+
unit: "metric"
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
map.addControl(scale, "bottom-left");
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Supported units:
|
|
84
|
+
|
|
85
|
+
- `"metric"`
|
|
86
|
+
- `"imperial"`
|
|
87
|
+
- `"nautical"`
|
|
88
|
+
|
|
89
|
+
## FullscreenControl
|
|
90
|
+
|
|
91
|
+
Adds a fullscreen toggle button.
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
const fullscreen = new Maptec.FullscreenControl();
|
|
95
|
+
map.addControl(fullscreen, "top-right");
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
It follows the evented pattern where supported:
|
|
99
|
+
|
|
100
|
+
- `on(type, listener)`
|
|
101
|
+
- `once(type, listener?)`
|
|
102
|
+
- `off(type, listener)`
|
|
103
|
+
|
|
104
|
+
## CompassControl
|
|
105
|
+
|
|
106
|
+
Shows a compass with rotation controls.
|
|
107
|
+
|
|
108
|
+
- Left/right arrows rotate the map.
|
|
109
|
+
- Center compass resets north when not facing north.
|
|
110
|
+
- When already north, center toggles 2D/3D pitch.
|
|
111
|
+
|
|
112
|
+
```js
|
|
113
|
+
const compass = new Maptec.CompassControl();
|
|
114
|
+
map.addControl(compass, "top-right");
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## HawkeyeControl
|
|
118
|
+
|
|
119
|
+
Shows an overview map and viewport box.
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
const hawkeye = new Maptec.HawkeyeControl({
|
|
123
|
+
zoomDiff: 4,
|
|
124
|
+
overviewBoxColor: "blue",
|
|
125
|
+
width: "150px",
|
|
126
|
+
height: "100px"
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
map.addControl(hawkeye, "bottom-right");
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Options:
|
|
133
|
+
|
|
134
|
+
- `zoomDiff`: zoom difference between main map and overview map; default `4`.
|
|
135
|
+
- `overviewBoxColor`: CSS color for viewport box.
|
|
136
|
+
- `width`: overview width; default `"150px"`.
|
|
137
|
+
- `height`: overview height; default `"100px"`.
|
|
138
|
+
|
|
139
|
+
## Business Locate Button
|
|
140
|
+
|
|
141
|
+
`maptec-js/src/index.ts` 未公开导出 `GeolocateControl`。如果产品需要定位按钮,用浏览器定位能力实现业务按钮,再移动地图并添加或更新 Marker。
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
const locateButton = document.createElement("button");
|
|
145
|
+
locateButton.type = "button";
|
|
146
|
+
locateButton.textContent = "定位";
|
|
147
|
+
locateButton.className = "map-locate-button";
|
|
148
|
+
|
|
149
|
+
let userMarker = null;
|
|
150
|
+
|
|
151
|
+
locateButton.addEventListener("click", () => {
|
|
152
|
+
if (!navigator.geolocation) {
|
|
153
|
+
console.warn("当前浏览器不支持定位");
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
navigator.geolocation.getCurrentPosition(
|
|
158
|
+
(position) => {
|
|
159
|
+
const lngLat = [
|
|
160
|
+
position.coords.longitude,
|
|
161
|
+
position.coords.latitude
|
|
162
|
+
];
|
|
163
|
+
|
|
164
|
+
if (!userMarker) {
|
|
165
|
+
userMarker = new Maptec.Marker({
|
|
166
|
+
position: lngLat,
|
|
167
|
+
color: "#2563eb"
|
|
168
|
+
});
|
|
169
|
+
map.addOverlay(userMarker);
|
|
170
|
+
} else {
|
|
171
|
+
userMarker.position = lngLat;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
map.flyTo({ center: lngLat, zoom: 16 });
|
|
175
|
+
},
|
|
176
|
+
(error) => {
|
|
177
|
+
console.error("定位失败", error);
|
|
178
|
+
},
|
|
179
|
+
{ enableHighAccuracy: true, timeout: 10000 }
|
|
180
|
+
);
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Pitfalls
|
|
185
|
+
|
|
186
|
+
- Do not write `new Maptec.PerformanceMonitorControl()`, `new Maptec.GeolocateControl()`, `new Maptec.LogoControl()`, or `new Maptec.AttributionControl()` in user-facing examples unless those classes are explicitly exported by the current SDK.
|
|
187
|
+
- Do not add both `NavigationControl` and separate `CompassControl` unless the UI intentionally needs both.
|
|
188
|
+
- Keep control instances so they can be removed during component cleanup.
|
|
189
|
+
|
|
190
|
+
## Agent 规则
|
|
191
|
+
|
|
192
|
+
- 添加控件必须使用 `map.addControl(control, position?)`,清理时使用 `map.removeControl(control)`。
|
|
193
|
+
- 内置控件只能使用当前公开导出的 `NavigationControl`、`ScaleControl`、`FullscreenControl`、`CompassControl`、`HawkeyeControl`。
|
|
194
|
+
- 定位按钮使用浏览器 `navigator.geolocation` 加自定义业务按钮方案,不要编造 `Maptec.GeolocateControl`。
|
|
195
|
+
- 控件位置只能使用 SDK 支持的位置值:`top-left`、`top-right`、`bottom-left`、`bottom-right`。
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# Maptec Events Reference
|
|
2
|
+
|
|
3
|
+
Use this reference when handling map events, mouse/wheel events, subscriptions, custom events, overlay events, or cleanup.
|
|
4
|
+
|
|
5
|
+
## 中文能力入口
|
|
6
|
+
|
|
7
|
+
本文件对应功能 **事件监听**:支持地图点击、缩放变化、中心点变化、Marker 点击、矢量覆盖物点击、信息窗口打开/关闭等事件监听代码。
|
|
8
|
+
|
|
9
|
+
| 用户需求 | 事件 |
|
|
10
|
+
|---|---|
|
|
11
|
+
| “点击地图获取当前位置的经纬度” | `map.on("click", handler)`,读取 `event.lngLat` |
|
|
12
|
+
| “监听地图缩放级别变化” | `map.on("zoomend", handler)`,读取 `map.zoom` |
|
|
13
|
+
| “监听中心点变化” | `map.on("moveend", handler)`,读取 `map.center` |
|
|
14
|
+
| “监听Marker点击” | `marker.on("click", handler)` |
|
|
15
|
+
| “监听矢量覆盖物点击” | `circleOverlay.on("click", handler)`、`polylineOverlay.on("click", handler)`、`polygonOverlay.on("click", handler)`、`geojsonOverlay.on("click", handler)` |
|
|
16
|
+
| “监听信息窗口打开/关闭” | `popup.on("open", handler)`、`popup.on("close", handler)` |
|
|
17
|
+
|
|
18
|
+
## Evented Pattern
|
|
19
|
+
|
|
20
|
+
Maptec map, overlays, and some controls support:
|
|
21
|
+
|
|
22
|
+
- `on(type, listener)`: subscribe.
|
|
23
|
+
- `once(type, listener?)`: subscribe once, or return a promise when no listener is provided.
|
|
24
|
+
- `off(type, listener)`: remove listener.
|
|
25
|
+
|
|
26
|
+
Some `on` calls return a `Subscription` with `unsubscribe()`.
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
const subscription = map.on("click", (event) => {
|
|
30
|
+
console.log("clicked", event.lngLat);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
subscription.unsubscribe();
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
If the runtime does not return a subscription, keep the listener reference and call `off`.
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
const onMoveEnd = () => {
|
|
40
|
+
console.log(map.center, map.zoom);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
map.on("moveend", onMoveEnd);
|
|
44
|
+
map.off("moveend", onMoveEnd);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Map Event Types
|
|
48
|
+
|
|
49
|
+
Common `MapEventType` entries:
|
|
50
|
+
|
|
51
|
+
- Lifecycle: `load`, `destroy`, `resize`
|
|
52
|
+
- Mouse: `click`, `dblclick`, `contextmenu`, `mousedown`, `mouseup`, `mousemove`, `mouseover`, `mouseout`, `mouseenter`, `mouseleave`
|
|
53
|
+
- Wheel: `wheel`
|
|
54
|
+
- Touch: `touchstart`, `touchmove`, `touchend`, `touchcancel`
|
|
55
|
+
- Move: `movestart`, `move`, `moveend`
|
|
56
|
+
- Drag: `dragstart`, `drag`, `dragend`
|
|
57
|
+
- Zoom: `zoomstart`, `zoom`, `zoomend`
|
|
58
|
+
- Rotate: `rotatestart`, `rotate`, `rotateend`
|
|
59
|
+
- Pitch: `pitchstart`, `pitch`, `pitchend`
|
|
60
|
+
- Box zoom: `boxzoomstart`, `boxzoomend`, `boxzoomcancel`
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
map.on("load", () => {
|
|
64
|
+
console.log("map loaded");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
map.on("moveend", () => {
|
|
68
|
+
console.log("view", map.center, map.zoom);
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## MapMouseEvent
|
|
73
|
+
|
|
74
|
+
Mouse events such as `click` provide a `MapMouseEvent`.
|
|
75
|
+
|
|
76
|
+
Important fields:
|
|
77
|
+
|
|
78
|
+
- `type`
|
|
79
|
+
- `target`: map instance
|
|
80
|
+
- `originalEvent`: original DOM mouse event
|
|
81
|
+
- `point`: screen pixel point
|
|
82
|
+
- `lngLat`: geographic coordinate
|
|
83
|
+
- `defaultPrevented`
|
|
84
|
+
|
|
85
|
+
Method:
|
|
86
|
+
|
|
87
|
+
- `preventDefault()`
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
map.on("click", (event) => {
|
|
91
|
+
console.log("screen point", event.point);
|
|
92
|
+
console.log("lngLat", event.lngLat);
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Click map and get `[lng, lat]`:
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
const onMapClick = (event) => {
|
|
100
|
+
const lngLat = Maptec.LngLat.convert(event.lngLat).toArray();
|
|
101
|
+
console.log("点击坐标", lngLat);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
map.on("click", onMapClick);
|
|
105
|
+
|
|
106
|
+
// cleanup
|
|
107
|
+
map.off("click", onMapClick);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Use `event.lngLat` for map coordinates and `event.point` for UI pixel calculations.
|
|
111
|
+
|
|
112
|
+
## MapWheelEvent
|
|
113
|
+
|
|
114
|
+
`wheel` events provide `MapWheelEvent`.
|
|
115
|
+
|
|
116
|
+
Fields:
|
|
117
|
+
|
|
118
|
+
- `type`: `"wheel"`
|
|
119
|
+
- `target`: map instance
|
|
120
|
+
- `originalEvent`: original `WheelEvent`
|
|
121
|
+
- `defaultPrevented`
|
|
122
|
+
|
|
123
|
+
Method:
|
|
124
|
+
|
|
125
|
+
- `preventDefault()`: prevents the map's default zoom behavior for that wheel event.
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
map.on("wheel", (event) => {
|
|
129
|
+
if (shouldBlockWheelZoom(event.originalEvent)) {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## MaptecEvent
|
|
136
|
+
|
|
137
|
+
`Maptec.Event` can be created and fired.
|
|
138
|
+
|
|
139
|
+
```js
|
|
140
|
+
const event = new Maptec.Event("custom:ready", {
|
|
141
|
+
message: "地图初始化完成"
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
map.fire(event);
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Use custom events sparingly. Prefer normal application state events unless the event should be part of the Maptec map event pipeline.
|
|
148
|
+
|
|
149
|
+
## Overlay Events
|
|
150
|
+
|
|
151
|
+
Overlays such as `Marker`, `Popup`, `CircleOverlay`, `PolylineOverlay`, `PolygonOverlay`, and `GeoJSONOverlay` expose event methods where supported.
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
const marker = new Maptec.Marker({
|
|
155
|
+
position: [103.8198, 1.3521]
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
marker.on("click", () => {
|
|
159
|
+
marker.togglePopup();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
map.addOverlay(marker);
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
```js
|
|
166
|
+
const polyline = new Maptec.PolylineOverlay({
|
|
167
|
+
positions: [
|
|
168
|
+
[103.8318, 1.3048],
|
|
169
|
+
[103.8198, 1.3521]
|
|
170
|
+
],
|
|
171
|
+
strokeColor: "#7c3aed",
|
|
172
|
+
strokeWeight: 5
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
const onLineClick = (event) => {
|
|
176
|
+
console.log("点击折线", event.features);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
polyline.on("click", onLineClick);
|
|
180
|
+
map.addOverlay(polyline);
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Cleanup Pattern
|
|
184
|
+
|
|
185
|
+
```js
|
|
186
|
+
const cleanups = [];
|
|
187
|
+
|
|
188
|
+
function listen(target, type, listener) {
|
|
189
|
+
const subscription = target.on(type, listener);
|
|
190
|
+
cleanups.push(() => {
|
|
191
|
+
if (subscription?.unsubscribe) {
|
|
192
|
+
subscription.unsubscribe();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
target.off?.(type, listener);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
listen(map, "moveend", () => {
|
|
200
|
+
console.log(map.center);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
function cleanup() {
|
|
204
|
+
cleanups.splice(0).forEach((fn) => fn());
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Pitfalls
|
|
209
|
+
|
|
210
|
+
- Do not attach listeners repeatedly inside render loops without cleanup.
|
|
211
|
+
- Use `once` for one-time initialization reactions.
|
|
212
|
+
- Use `preventDefault()` only when intentionally overriding SDK behavior.
|
|
213
|
+
- Use `lngLat` for geographic work and `point` for pixel/UI work.
|
|
214
|
+
- 覆盖物事件示例必须使用真实公开类名,不要写 `Circle`、`Polyline`、`Polygon`。
|
|
215
|
+
|
|
216
|
+
## Agent 规则
|
|
217
|
+
|
|
218
|
+
- 监听事件时必须保存 listener 引用或订阅对象,清理阶段使用 `off` 或 `unsubscribe()`。
|
|
219
|
+
- 地图点击获取经纬度时使用 `event.lngLat`,需要数组时再转换为 `[lng, lat]`。
|
|
220
|
+
- 缩放、中心点、旋转、倾斜等状态应从地图实例读取,不要自行缓存后当作真实状态。
|
|
221
|
+
- 覆盖物事件使用 `Marker`、`Popup`、`CircleOverlay`、`PolylineOverlay`、`PolygonOverlay`、`GeoJSONOverlay` 的事件能力。
|
|
222
|
+
- 不要编造未确认事件名;未确认事件必须标记为 `需确认 Maptec 是否支持`。
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# 地理编码能力参考
|
|
2
|
+
|
|
3
|
+
当用户要求把地址、地名、地标、道路或 POI 名称转换为经纬度坐标时,使用本参考。本文件只覆盖功能 **地理编码**。
|
|
4
|
+
|
|
5
|
+
逆地理编码,即坐标反查地址,请读取 `re-geocoding.md`。
|
|
6
|
+
|
|
7
|
+
## 能力入口
|
|
8
|
+
|
|
9
|
+
| 用户需求 | 优先实现 |
|
|
10
|
+
|---|---|
|
|
11
|
+
| “将新加坡摩天观景轮标注在地图上” | `Geocode.getLocation` 获取坐标,再添加 `Marker` |
|
|
12
|
+
| “将地址转换为经纬度坐标” | `Geocode.getLocation(address, options, callback)` |
|
|
13
|
+
| “把地名作为路线起终点” | 先 `Geocode.getLocation`,再把 `[lng, lat]` 传给路线规划 |
|
|
14
|
+
|
|
15
|
+
## Geocode 服务
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const geocode = new Maptec.Geocode({
|
|
19
|
+
language: "en",
|
|
20
|
+
region: "SG",
|
|
21
|
+
timeout: 10000
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`GeocodeOptions`:
|
|
26
|
+
|
|
27
|
+
- `language?: string`:IETF language tag,默认 `"en"`。
|
|
28
|
+
- `region?: string`:ccTLD region code,例如 `"SG"` 或 `"BR"`。
|
|
29
|
+
- `timeout?: number`:请求超时时间,默认 `10000` 毫秒。
|
|
30
|
+
|
|
31
|
+
## getLocation
|
|
32
|
+
|
|
33
|
+
当用户输入地址、地名、地标或道路名,代码需要坐标时使用 `getLocation`。
|
|
34
|
+
|
|
35
|
+
调用模式:
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
geocode.getLocation(address, callback);
|
|
39
|
+
geocode.getLocation(address, options, callback);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
示例:
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
geocode.getLocation("Singapore Flyer", {
|
|
46
|
+
language: "en",
|
|
47
|
+
region: "SG"
|
|
48
|
+
}, (error, result) => {
|
|
49
|
+
if (error) {
|
|
50
|
+
console.error("地理编码失败", error);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const first = result?.results?.[0];
|
|
55
|
+
const location = first?.geometry?.location;
|
|
56
|
+
if (!location) {
|
|
57
|
+
console.warn("没有地理编码结果", result?.status);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const position = [location.longitude, location.latitude];
|
|
62
|
+
map.flyTo({ center: position, zoom: 15 });
|
|
63
|
+
|
|
64
|
+
const marker = new Maptec.Marker({ position });
|
|
65
|
+
map.addOverlay(marker);
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`GeocodeLocationOptions`:
|
|
70
|
+
|
|
71
|
+
- `language?: string`
|
|
72
|
+
- `region?: string`
|
|
73
|
+
- `components?: string`:过滤格式为 `component:value|component:value`。
|
|
74
|
+
- `locationBias?: { southwest: LngLatLike; northeast: LngLatLike }`:偏向某个矩形范围,但不保证结果一定在范围内。
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
geocode.getLocation("coffee", {
|
|
78
|
+
locationBias: {
|
|
79
|
+
southwest: [103.6, 1.20],
|
|
80
|
+
northeast: [104.1, 1.48]
|
|
81
|
+
}
|
|
82
|
+
}, callback);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 结果类型
|
|
86
|
+
|
|
87
|
+
`GeocodeCallback = (error, result?) => void`。
|
|
88
|
+
|
|
89
|
+
`GeocodeError`:
|
|
90
|
+
|
|
91
|
+
- `code: string`
|
|
92
|
+
- `message: string`
|
|
93
|
+
|
|
94
|
+
`GeocodeStatus`:
|
|
95
|
+
|
|
96
|
+
- `"OK"`
|
|
97
|
+
- `"ZERO_RESULTS"`
|
|
98
|
+
- `"ERROR"`
|
|
99
|
+
|
|
100
|
+
`GeocodeResult`:
|
|
101
|
+
|
|
102
|
+
- `status: GeocodeStatus`
|
|
103
|
+
- `results: GeoResult[]`
|
|
104
|
+
- `error?: GeocodeError`
|
|
105
|
+
|
|
106
|
+
`GeoResult`:
|
|
107
|
+
|
|
108
|
+
- `formattedAddress: string`
|
|
109
|
+
- `placeId: string`
|
|
110
|
+
- `types: string[]`
|
|
111
|
+
- `languageCode: string`
|
|
112
|
+
- `geometry: GeocodeGeometry`
|
|
113
|
+
- `addressComponents: GeocodeAddressComponent[]`
|
|
114
|
+
- `matchDetails: GeocodeMatchDetails`
|
|
115
|
+
- `supplementaryInfo: GeocodeSupplementaryInfo`
|
|
116
|
+
|
|
117
|
+
`GeocodeGeometry`:
|
|
118
|
+
|
|
119
|
+
- `location: LngLatObject`
|
|
120
|
+
- `locationType: GeocodeLocationType`
|
|
121
|
+
- `viewport: GeocodeViewport`
|
|
122
|
+
- `distance: number`
|
|
123
|
+
|
|
124
|
+
`GeocodeLocationType`:
|
|
125
|
+
|
|
126
|
+
- `"ROOFTOP"`
|
|
127
|
+
- `"INTERPOLATED"`
|
|
128
|
+
- `"CENTER"`
|
|
129
|
+
|
|
130
|
+
`GeocodeViewport`:
|
|
131
|
+
|
|
132
|
+
- `southwest: LngLatObject`
|
|
133
|
+
- `northeast: LngLatObject`
|
|
134
|
+
|
|
135
|
+
## 坐标转换
|
|
136
|
+
|
|
137
|
+
地理编码结果中的 `location` 是对象形式,需要转换为 `[lng, lat]`。
|
|
138
|
+
|
|
139
|
+
```js
|
|
140
|
+
function toLngLatFromGeocode(location) {
|
|
141
|
+
if (!location) return null;
|
|
142
|
+
return [location.longitude, location.latitude];
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
转换后可传给 `Marker`、`Popup`、`Driving.search`、`fitBounds`、`flyTo` 或 `GeoJSON`。
|
|
147
|
+
|
|
148
|
+
## 路线规划集成
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
async function geocodeOne(query, region = "SG") {
|
|
152
|
+
return new Promise((resolve, reject) => {
|
|
153
|
+
geocode.getLocation(query, { region }, (error, result) => {
|
|
154
|
+
if (error) {
|
|
155
|
+
reject(error);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const location = result?.results?.[0]?.geometry?.location;
|
|
160
|
+
if (!location) {
|
|
161
|
+
reject(new Error(`No geocode result: ${query}`));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
resolve([location.longitude, location.latitude]);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## 注意事项
|
|
172
|
+
|
|
173
|
+
- 不要使用 `[location.latitude, location.longitude]`;必须转换成 `[longitude, latitude]`。
|
|
174
|
+
- `locationBias` 只是偏向,不是硬边界过滤。
|
|
175
|
+
- 必须处理 `ZERO_RESULTS` 和空 `results`。
|
|
176
|
+
- 地址或地名作为路线起终点时,先地理编码,再调用路线规划。
|
|
177
|
+
- 对关键业务可使用 `matchDetails` 判断低置信度结果,不要直接绘制高风险结果。
|
|
178
|
+
|
|
179
|
+
## Agent 规则
|
|
180
|
+
|
|
181
|
+
- 地址、地名、地标或道路名称转坐标必须使用 `Maptec.Geocode.getLocation`。
|
|
182
|
+
- 地理编码结果必须从 `geometry.location` 转换为 `[longitude, latitude]`,不能写成 `[latitude, longitude]`。
|
|
183
|
+
- 必须处理错误、`ZERO_RESULTS` 和空 `results`。
|
|
184
|
+
- 地理编码结果用于 Marker 或路线规划前,应确认存在有效坐标。
|