@lin1538001/unified-map 0.0.0-stage → 0.1.1
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 +82 -2
- package/dist/chunks/AMapAdapter-76901841.js +581 -0
- package/dist/chunks/ArcGISAdapter-5e6881de.js +962 -0
- package/dist/chunks/BMapAdapter-0d882313.js +581 -0
- package/dist/chunks/color-128d7dff.js +38 -0
- package/dist/chunks/index-dd303ebf.js +1190 -0
- package/dist/chunks/mapLoader-06d6e155.js +226 -0
- package/dist/index.js +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/map/InfoWindow.d.ts +38 -0
- package/dist/types/map/InfoWindow.d.ts.map +1 -0
- package/dist/types/map/UnifiedMap.d.ts +266 -0
- package/dist/types/map/UnifiedMap.d.ts.map +1 -0
- package/dist/types/map/adapters/AMapAdapter.d.ts +87 -0
- package/dist/types/map/adapters/AMapAdapter.d.ts.map +1 -0
- package/dist/types/map/adapters/ArcGISAdapter.d.ts +92 -0
- package/dist/types/map/adapters/ArcGISAdapter.d.ts.map +1 -0
- package/dist/types/map/adapters/BMapAdapter.d.ts +83 -0
- package/dist/types/map/adapters/BMapAdapter.d.ts.map +1 -0
- package/dist/types/map/adapters/MapAdapter.d.ts +46 -0
- package/dist/types/map/adapters/MapAdapter.d.ts.map +1 -0
- package/dist/types/map/adapters/color.d.ts +3 -0
- package/dist/types/map/adapters/color.d.ts.map +1 -0
- package/dist/types/map/coordinates.d.ts +29 -0
- package/dist/types/map/coordinates.d.ts.map +1 -0
- package/dist/types/map/errors.d.ts +8 -0
- package/dist/types/map/errors.d.ts.map +1 -0
- package/dist/types/map/index.d.ts +5 -0
- package/dist/types/map/index.d.ts.map +1 -0
- package/dist/types/map/types.d.ts +240 -0
- package/dist/types/map/types.d.ts.map +1 -0
- package/dist/types/utils/mapLoader.d.ts +49 -0
- package/dist/types/utils/mapLoader.d.ts.map +1 -0
- package/package.json +63 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 linyy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,83 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lin1538001/unified-map
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
一个 TypeScript 地图适配层,为高德地图、百度地图和 ArcGIS 提供统一的生命周期、覆盖物、批量图层、绘制与编辑 API。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @lin1538001/unified-map vue
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
仅在使用 ArcGIS provider 时安装 ArcGIS SDK:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @arcgis/core
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 基础用法
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { UnifiedMap } from '@lin1538001/unified-map'
|
|
21
|
+
|
|
22
|
+
const map = new UnifiedMap({
|
|
23
|
+
provider: 'amap',
|
|
24
|
+
container: 'map-container',
|
|
25
|
+
key: 'your-amap-key',
|
|
26
|
+
center: [116.397428, 39.90923],
|
|
27
|
+
zoom: 12
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
await map.init()
|
|
31
|
+
|
|
32
|
+
const marker = map.addMarker({
|
|
33
|
+
position: [116.397428, 39.90923],
|
|
34
|
+
style: {
|
|
35
|
+
kind: 'circle',
|
|
36
|
+
radius: 8,
|
|
37
|
+
fillColor: '#1677ff'
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const unsubscribe = map.on('click', (event) => {
|
|
42
|
+
console.log(event.position, event.coordinateSystem)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// 页面卸载时释放 SDK、事件和图层资源。
|
|
46
|
+
unsubscribe()
|
|
47
|
+
marker.remove()
|
|
48
|
+
map.destroy()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Provider 与坐标系
|
|
52
|
+
|
|
53
|
+
| Provider | `provider` | 原生坐标系 | 是否需要 `key` |
|
|
54
|
+
| --- | --- | --- | --- |
|
|
55
|
+
| 高德 | `amap` | GCJ-02 | 是 |
|
|
56
|
+
| 百度 | `baidu` | BD-09 | 是 |
|
|
57
|
+
| ArcGIS | `arcgis` | WGS84 | 否 |
|
|
58
|
+
|
|
59
|
+
地图 Key 不内置在包中,必须由应用在运行时传入。请为浏览器 Key 配置域名白名单;服务端私密 Token 不应传给本包或进入前端代码。
|
|
60
|
+
|
|
61
|
+
## Vue 使用提示
|
|
62
|
+
|
|
63
|
+
`UnifiedMap` 是命令式实例,可以保存到普通变量或 `shallowRef` 中。实例内部已标记为非深度响应式,避免绘制与编辑会话被 Proxy 破坏。
|
|
64
|
+
|
|
65
|
+
## 浏览器与 SSR
|
|
66
|
+
|
|
67
|
+
地图 SDK 依赖 DOM。请只在浏览器挂载后调用 `init()`;SSR 环境中不要在服务端执行地图初始化。
|
|
68
|
+
|
|
69
|
+
## 本地开发
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pnpm install
|
|
73
|
+
pnpm lint
|
|
74
|
+
pnpm type-check
|
|
75
|
+
pnpm build
|
|
76
|
+
pnpm build:demo
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
演示应用位于 `src/views/Home` 和 `src/components/Map`,不会包含在发布包中。
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
MIT
|
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
var S = Object.defineProperty;
|
|
2
|
+
var g = (f, e, t) => e in f ? S(f, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : f[e] = t;
|
|
3
|
+
var y = (f, e, t) => (g(f, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { l as k, a as w } from "./mapLoader-06d6e155.js";
|
|
5
|
+
import { M as n, a as u } from "./index-dd303ebf.js";
|
|
6
|
+
import { t as p } from "./color-128d7dff.js";
|
|
7
|
+
import "vue";
|
|
8
|
+
class E {
|
|
9
|
+
constructor() {
|
|
10
|
+
y(this, "coordinateSystem", "gcj02");
|
|
11
|
+
y(this, "sdk", null);
|
|
12
|
+
y(this, "locaSdk", null);
|
|
13
|
+
y(this, "loca", null);
|
|
14
|
+
y(this, "map", null);
|
|
15
|
+
y(this, "mouseTool", null);
|
|
16
|
+
y(this, "activeDraw", null);
|
|
17
|
+
y(this, "activeEdit", null);
|
|
18
|
+
y(this, "overlayKinds", /* @__PURE__ */ new WeakMap());
|
|
19
|
+
y(this, "massPointLayers", /* @__PURE__ */ new Set());
|
|
20
|
+
y(this, "scatterLayers", /* @__PURE__ */ new Set());
|
|
21
|
+
y(this, "polylineLayers", /* @__PURE__ */ new Set());
|
|
22
|
+
y(this, "polygonLayers", /* @__PURE__ */ new Set());
|
|
23
|
+
}
|
|
24
|
+
async init(e) {
|
|
25
|
+
var o, s, i, r;
|
|
26
|
+
if (!e.key)
|
|
27
|
+
throw new n("SDK_ERROR", "AMap requires a key");
|
|
28
|
+
const t = this.resolveContainer(e.container);
|
|
29
|
+
try {
|
|
30
|
+
this.sdk = await k(e.key), this.map = new this.sdk.Map(t, {
|
|
31
|
+
center: e.center || [116.397428, 39.90923],
|
|
32
|
+
zoom: e.zoom ?? 12,
|
|
33
|
+
viewMode: "2D"
|
|
34
|
+
}), this.mouseTool = new this.sdk.MouseTool(this.map), this.locaSdk = await w(e.key), this.loca = new this.locaSdk.Container({ map: this.map });
|
|
35
|
+
} catch (a) {
|
|
36
|
+
throw (s = (o = this.loca) == null ? void 0 : o.destroy) == null || s.call(o), this.loca = null, this.locaSdk = null, (r = (i = this.map) == null ? void 0 : i.destroy) == null || r.call(i), this.sdk = null, this.map = null, new n("SDK_ERROR", "Failed to initialize AMap", { cause: a });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
destroy() {
|
|
40
|
+
var e, t, o, s, i;
|
|
41
|
+
this.activeEdit && this.finishEdit(this.activeEdit), this.cancelDraw();
|
|
42
|
+
for (const r of this.massPointLayers)
|
|
43
|
+
this.destroyMassPointLayer(r);
|
|
44
|
+
this.massPointLayers.clear();
|
|
45
|
+
for (const r of this.scatterLayers)
|
|
46
|
+
this.destroyScatterLayer(r);
|
|
47
|
+
this.scatterLayers.clear();
|
|
48
|
+
for (const r of this.polylineLayers)
|
|
49
|
+
this.destroyPolylineLayer(r);
|
|
50
|
+
this.polylineLayers.clear();
|
|
51
|
+
for (const r of this.polygonLayers)
|
|
52
|
+
this.destroyPolygonLayer(r);
|
|
53
|
+
this.polygonLayers.clear(), (o = (t = (e = this.loca) == null ? void 0 : e.animate) == null ? void 0 : t.stop) == null || o.call(t), (i = (s = this.loca) == null ? void 0 : s.destroy) == null || i.call(s), this.loca = null, this.locaSdk = null, this.map && typeof this.map.destroy == "function" && this.map.destroy(), this.mouseTool = null, this.map = null, this.sdk = null;
|
|
54
|
+
}
|
|
55
|
+
addMarker(e) {
|
|
56
|
+
const t = this.createMarker(e);
|
|
57
|
+
return this.map.add(t), this.remember(t, "marker"), t;
|
|
58
|
+
}
|
|
59
|
+
addPolyline(e) {
|
|
60
|
+
const t = this.createPolyline(e);
|
|
61
|
+
return this.map.add(t), this.remember(t, "polyline"), t;
|
|
62
|
+
}
|
|
63
|
+
addPolygon(e) {
|
|
64
|
+
const t = this.createPolygon(e);
|
|
65
|
+
return this.map.add(t), this.remember(t, "polygon"), t;
|
|
66
|
+
}
|
|
67
|
+
addPolylineLayer(e) {
|
|
68
|
+
if (!this.loca || !this.locaSdk)
|
|
69
|
+
throw new n("SDK_ERROR", "AMap Loca is unavailable");
|
|
70
|
+
const t = this.createPolylineLayer(e);
|
|
71
|
+
return this.polylineLayers.add(t), t;
|
|
72
|
+
}
|
|
73
|
+
updatePolylineLayer(e, t, o) {
|
|
74
|
+
var r, a;
|
|
75
|
+
const s = e;
|
|
76
|
+
if (!this.polylineLayers.has(s))
|
|
77
|
+
throw new n("OVERLAY_NOT_FOUND", "Polyline layer is no longer registered");
|
|
78
|
+
if (!("polylines" in o) && !("zIndex" in o) && !("minZoom" in o) && !("maxZoom" in o))
|
|
79
|
+
return "style" in o && ((a = (r = s.layer).setStyle) == null || a.call(r, this.toPolylineLayerStyle(t))), "visible" in o && this.setLocaLayerVisibility(s.layer, t.visible !== !1), e;
|
|
80
|
+
const i = this.createPolylineLayer(t);
|
|
81
|
+
return this.polylineLayers.add(i), this.destroyPolylineLayer(s), this.polylineLayers.delete(s), i;
|
|
82
|
+
}
|
|
83
|
+
removePolylineLayer(e) {
|
|
84
|
+
const t = e;
|
|
85
|
+
this.polylineLayers.has(t) && (this.destroyPolylineLayer(t), this.polylineLayers.delete(t));
|
|
86
|
+
}
|
|
87
|
+
addPolygonLayer(e) {
|
|
88
|
+
if (!this.loca || !this.locaSdk)
|
|
89
|
+
throw new n("SDK_ERROR", "AMap Loca is unavailable");
|
|
90
|
+
const t = this.createPolygonLayer(e);
|
|
91
|
+
return this.polygonLayers.add(t), t;
|
|
92
|
+
}
|
|
93
|
+
updatePolygonLayer(e, t, o) {
|
|
94
|
+
var r, a, l, c;
|
|
95
|
+
const s = e;
|
|
96
|
+
if (!this.polygonLayers.has(s))
|
|
97
|
+
throw new n("OVERLAY_NOT_FOUND", "Polygon layer is no longer registered");
|
|
98
|
+
if (!("polygons" in o) && !("zIndex" in o) && !("minZoom" in o) && !("maxZoom" in o))
|
|
99
|
+
return "style" in o && ((a = (r = s.layer).setStyle) == null || a.call(r, this.toPolygonLayerStyle(t)), (c = (l = s.outlineLayer).setStyle) == null || c.call(l, this.toPolygonOutlineStyle(t))), "visible" in o && (this.setLocaLayerVisibility(s.layer, t.visible !== !1), this.setLocaLayerVisibility(s.outlineLayer, t.visible !== !1)), e;
|
|
100
|
+
const i = this.createPolygonLayer(t);
|
|
101
|
+
return this.polygonLayers.add(i), this.destroyPolygonLayer(s), this.polygonLayers.delete(s), i;
|
|
102
|
+
}
|
|
103
|
+
removePolygonLayer(e) {
|
|
104
|
+
const t = e;
|
|
105
|
+
this.polygonLayers.has(t) && (this.destroyPolygonLayer(t), this.polygonLayers.delete(t));
|
|
106
|
+
}
|
|
107
|
+
addMassPoints(e) {
|
|
108
|
+
if (!this.loca || !this.locaSdk)
|
|
109
|
+
throw new n("SDK_ERROR", "AMap Loca is unavailable");
|
|
110
|
+
const t = this.createMassPointLayer(e);
|
|
111
|
+
return this.massPointLayers.add(t), t;
|
|
112
|
+
}
|
|
113
|
+
updateMassPoints(e, t) {
|
|
114
|
+
const o = e;
|
|
115
|
+
if (!this.massPointLayers.has(o))
|
|
116
|
+
throw new n("OVERLAY_NOT_FOUND", "Mass point layer is no longer registered");
|
|
117
|
+
const s = this.createMassPointLayer(t);
|
|
118
|
+
return this.massPointLayers.add(s), this.destroyMassPointLayer(o), this.massPointLayers.delete(o), s;
|
|
119
|
+
}
|
|
120
|
+
removeMassPoints(e) {
|
|
121
|
+
const t = e;
|
|
122
|
+
this.massPointLayers.has(t) && (this.destroyMassPointLayer(t), this.massPointLayers.delete(t));
|
|
123
|
+
}
|
|
124
|
+
addScatterLayer(e) {
|
|
125
|
+
var o, s;
|
|
126
|
+
if (!this.loca || !this.locaSdk)
|
|
127
|
+
throw new n("SDK_ERROR", "AMap Loca is unavailable");
|
|
128
|
+
const t = this.createScatterLayer(e);
|
|
129
|
+
return this.scatterLayers.add(t), (s = (o = this.loca.animate) == null ? void 0 : o.start) == null || s.call(o), t;
|
|
130
|
+
}
|
|
131
|
+
updateScatterLayer(e, t) {
|
|
132
|
+
const o = e;
|
|
133
|
+
if (!this.scatterLayers.has(o))
|
|
134
|
+
throw new n("OVERLAY_NOT_FOUND", "Scatter layer is no longer registered");
|
|
135
|
+
const s = this.createScatterLayer(t);
|
|
136
|
+
return this.scatterLayers.add(s), this.destroyScatterLayer(o), this.scatterLayers.delete(o), s;
|
|
137
|
+
}
|
|
138
|
+
removeScatterLayer(e) {
|
|
139
|
+
var o, s, i;
|
|
140
|
+
const t = e;
|
|
141
|
+
this.scatterLayers.has(t) && (this.destroyScatterLayer(t), this.scatterLayers.delete(t), this.scatterLayers.size === 0 && ((i = (s = (o = this.loca) == null ? void 0 : o.animate) == null ? void 0 : s.stop) == null || i.call(s)));
|
|
142
|
+
}
|
|
143
|
+
updateOverlay(e, t, o) {
|
|
144
|
+
var r, a, l, c;
|
|
145
|
+
const s = this.overlayKinds.get(e);
|
|
146
|
+
if (!s)
|
|
147
|
+
throw new n("OVERLAY_NOT_FOUND", "Overlay is no longer registered");
|
|
148
|
+
const i = e;
|
|
149
|
+
if (s === "polyline") {
|
|
150
|
+
const h = t;
|
|
151
|
+
return (r = i.setOptions) == null || r.call(i, this.toPolylineStyle(h)), "path" in o && ((a = i.setPath) == null || a.call(i, h.path)), e;
|
|
152
|
+
}
|
|
153
|
+
if (s === "polygon") {
|
|
154
|
+
const h = t;
|
|
155
|
+
return (l = i.setOptions) == null || l.call(i, this.toPolygonStyle(h)), "path" in o && ((c = i.setPath) == null || c.call(i, h.path)), e;
|
|
156
|
+
}
|
|
157
|
+
return this.removeOverlay(e), this.addMarker(t);
|
|
158
|
+
}
|
|
159
|
+
removeOverlay(e) {
|
|
160
|
+
const t = this.activeEdit;
|
|
161
|
+
t && t.native === e && this.finishEdit(t), this.map && e && this.map.remove(e), e && (typeof e == "object" || typeof e == "function") && this.overlayKinds.delete(e);
|
|
162
|
+
}
|
|
163
|
+
getPath(e) {
|
|
164
|
+
const t = e;
|
|
165
|
+
return !t || typeof t.getPath != "function" ? null : t.getPath().map((o) => u([o.lng, o.lat]));
|
|
166
|
+
}
|
|
167
|
+
getPosition(e) {
|
|
168
|
+
var s;
|
|
169
|
+
const t = e;
|
|
170
|
+
if (!t)
|
|
171
|
+
return null;
|
|
172
|
+
const o = typeof t.getPosition == "function" ? t.getPosition() : (s = t.getCenter) == null ? void 0 : s.call(t);
|
|
173
|
+
return o ? u([o.lng, o.lat]) : null;
|
|
174
|
+
}
|
|
175
|
+
onMapClick(e) {
|
|
176
|
+
const t = (o) => {
|
|
177
|
+
const s = this.toClickEvent(o);
|
|
178
|
+
s && e(s);
|
|
179
|
+
};
|
|
180
|
+
return this.map.on("click", t), () => {
|
|
181
|
+
var o;
|
|
182
|
+
(o = this.map) == null || o.off("click", t);
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
onOverlayClick(e, t) {
|
|
186
|
+
var i;
|
|
187
|
+
const o = (r) => {
|
|
188
|
+
const a = this.toClickEvent(r, e);
|
|
189
|
+
a && t(a);
|
|
190
|
+
}, s = e;
|
|
191
|
+
return (i = s.on) == null || i.call(s, "click", o), () => {
|
|
192
|
+
var r;
|
|
193
|
+
return (r = s.off) == null ? void 0 : r.call(s, "click", o);
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
startEdit(e, t, o) {
|
|
197
|
+
var l, c, h;
|
|
198
|
+
if (this.overlayKinds.get(e) !== t)
|
|
199
|
+
throw new n("INVALID_OPTIONS", "Only polyline and polygon overlays can be edited");
|
|
200
|
+
const s = t === "polyline" ? (l = this.sdk) == null ? void 0 : l.PolylineEditor : (c = this.sdk) == null ? void 0 : c.PolygonEditor;
|
|
201
|
+
if (!s)
|
|
202
|
+
throw new n("SDK_ERROR", `AMap ${t} editor is unavailable`);
|
|
203
|
+
if (this.activeDraw)
|
|
204
|
+
throw new n("DRAW_IN_PROGRESS", "Cannot edit while drawing");
|
|
205
|
+
this.activeEdit && this.finishEdit(this.activeEdit);
|
|
206
|
+
const i = new s(this.map, e), r = { native: e, editor: i, handlers: [], onChange: o, stopped: !1 }, a = () => {
|
|
207
|
+
if (r.stopped)
|
|
208
|
+
return;
|
|
209
|
+
const d = this.getPath(r.native);
|
|
210
|
+
d && r.onChange(d);
|
|
211
|
+
};
|
|
212
|
+
for (const d of ["adjust", "addnode", "removenode", "end"])
|
|
213
|
+
(h = i.on) == null || h.call(i, d, a), r.handlers.push({ event: d, handler: a });
|
|
214
|
+
this.activeEdit = r;
|
|
215
|
+
try {
|
|
216
|
+
i.open();
|
|
217
|
+
} catch (d) {
|
|
218
|
+
throw this.finishEdit(r), new n("SDK_ERROR", `Failed to start AMap ${t} editing`, { cause: d });
|
|
219
|
+
}
|
|
220
|
+
return () => this.finishEdit(r);
|
|
221
|
+
}
|
|
222
|
+
startDraw(e, t, o, s) {
|
|
223
|
+
if (this.activeDraw)
|
|
224
|
+
throw new n("DRAW_IN_PROGRESS", "A drawing operation is already active");
|
|
225
|
+
this.activeEdit && this.finishEdit(this.activeEdit);
|
|
226
|
+
const i = (r) => {
|
|
227
|
+
const a = this.activeDraw;
|
|
228
|
+
if (!a || a.completed)
|
|
229
|
+
return;
|
|
230
|
+
a.completed = !0, this.cleanupDraw(a);
|
|
231
|
+
const l = r == null ? void 0 : r.obj;
|
|
232
|
+
l && this.remember(l, e);
|
|
233
|
+
const c = this.getPath(l) || [];
|
|
234
|
+
o(l, c);
|
|
235
|
+
};
|
|
236
|
+
this.activeDraw = { handler: i, onCancel: s, completed: !1 }, this.mouseTool.on("draw", i), e === "polyline" ? this.mouseTool.polyline(this.toPolylineStyle(t)) : this.mouseTool.polygon(this.toPolygonStyle(t));
|
|
237
|
+
}
|
|
238
|
+
cancelDraw() {
|
|
239
|
+
const e = this.activeDraw;
|
|
240
|
+
e && (e.completed = !0, this.cleanupDraw(e), e.onCancel());
|
|
241
|
+
}
|
|
242
|
+
setCenter(e) {
|
|
243
|
+
this.map.setCenter(e);
|
|
244
|
+
}
|
|
245
|
+
getCenter() {
|
|
246
|
+
const e = this.map.getCenter();
|
|
247
|
+
return u([e.lng, e.lat]);
|
|
248
|
+
}
|
|
249
|
+
setZoom(e) {
|
|
250
|
+
this.map.setZoom(e);
|
|
251
|
+
}
|
|
252
|
+
getZoom() {
|
|
253
|
+
return this.map.getZoom();
|
|
254
|
+
}
|
|
255
|
+
fitView(e, t, o, s) {
|
|
256
|
+
if (e.length === 0)
|
|
257
|
+
return;
|
|
258
|
+
const i = new this.sdk.LngLat(e[0][0], e[0][1]), r = new this.sdk.Bounds(i, i);
|
|
259
|
+
if (e.slice(1).forEach((a) => r.extend(new this.sdk.LngLat(a[0], a[1]))), typeof this.map.getFitZoomAndCenterByBounds == "function") {
|
|
260
|
+
const [a, l] = this.map.getFitZoomAndCenterByBounds(r, [...o], s);
|
|
261
|
+
this.map.setZoomAndCenter(a, l, t);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
this.map.setBounds(r, t, [...o]), s !== void 0 && this.map.getZoom() > s && this.map.setZoom(s);
|
|
265
|
+
}
|
|
266
|
+
createInfoWindow(e, t, o) {
|
|
267
|
+
var a, l;
|
|
268
|
+
const s = new this.sdk.InfoWindow({
|
|
269
|
+
content: e.content ?? "",
|
|
270
|
+
position: e.position,
|
|
271
|
+
isCustom: e.isCustom ?? !1,
|
|
272
|
+
autoMove: e.autoMove ?? !0,
|
|
273
|
+
closeWhenClickMap: e.closeWhenClickMap ?? !1,
|
|
274
|
+
anchor: e.anchor ?? "bottom-center",
|
|
275
|
+
offset: e.offset ? new this.sdk.Pixel(e.offset[0], e.offset[1]) : void 0,
|
|
276
|
+
size: e.size ? new this.sdk.Size(e.size[0], e.size[1]) : void 0,
|
|
277
|
+
extData: e.extData
|
|
278
|
+
}), i = (c) => t(c), r = (c) => o(c);
|
|
279
|
+
return (a = s.on) == null || a.call(s, "open", i), (l = s.on) == null || l.call(s, "close", r), { value: s, openHandler: i, closeHandler: r };
|
|
280
|
+
}
|
|
281
|
+
openInfoWindow(e, t) {
|
|
282
|
+
e.value.open(this.map, t);
|
|
283
|
+
}
|
|
284
|
+
closeInfoWindow(e) {
|
|
285
|
+
var o, s;
|
|
286
|
+
(s = (o = e.value).close) == null || s.call(o);
|
|
287
|
+
}
|
|
288
|
+
destroyInfoWindow(e) {
|
|
289
|
+
var o, s, i, r, a, l;
|
|
290
|
+
const t = e;
|
|
291
|
+
(s = (o = t.value).off) == null || s.call(o, "open", t.openHandler), (r = (i = t.value).off) == null || r.call(i, "close", t.closeHandler), (l = (a = t.value).close) == null || l.call(a);
|
|
292
|
+
}
|
|
293
|
+
resolveContainer(e) {
|
|
294
|
+
if (typeof e == "string") {
|
|
295
|
+
if (!document.getElementById(e))
|
|
296
|
+
throw new n("INVALID_OPTIONS", `Container not found: ${e}`);
|
|
297
|
+
return e;
|
|
298
|
+
}
|
|
299
|
+
if (!e)
|
|
300
|
+
throw new n("INVALID_OPTIONS", "A map container is required");
|
|
301
|
+
return e.id || (e.id = `unified-map-${Math.random().toString(36).slice(2)}`), e.id;
|
|
302
|
+
}
|
|
303
|
+
remember(e, t) {
|
|
304
|
+
this.overlayKinds.set(e, t);
|
|
305
|
+
}
|
|
306
|
+
toClickEvent(e, t) {
|
|
307
|
+
const o = this.resolveClickPosition(e, t);
|
|
308
|
+
return o ? {
|
|
309
|
+
lnglat: { lng: o[0], lat: o[1] },
|
|
310
|
+
position: o,
|
|
311
|
+
coordinateSystem: this.coordinateSystem,
|
|
312
|
+
originalEvent: e
|
|
313
|
+
} : null;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* 解析点击坐标:优先事件自带 lnglat,其次覆盖物锚点,
|
|
317
|
+
* 最后回退到线/面路径首点——保证线/面点击事件不因缺少坐标而被整体丢弃
|
|
318
|
+
*/
|
|
319
|
+
resolveClickPosition(e, t) {
|
|
320
|
+
const o = (e == null ? void 0 : e.lnglat) || (t ? this.getPosition(t) : null);
|
|
321
|
+
if (o)
|
|
322
|
+
return Array.isArray(o) ? u(o) : u([o.lng, o.lat]);
|
|
323
|
+
if (!t)
|
|
324
|
+
return null;
|
|
325
|
+
const s = this.getPath(t);
|
|
326
|
+
return s && s.length > 0 ? s[0] : null;
|
|
327
|
+
}
|
|
328
|
+
createMarker(e) {
|
|
329
|
+
const t = e.style || { kind: "circle" };
|
|
330
|
+
if (t.kind === "icon") {
|
|
331
|
+
const o = new this.sdk.Icon({
|
|
332
|
+
image: t.url,
|
|
333
|
+
size: new this.sdk.Size(t.width, t.height),
|
|
334
|
+
imageSize: new this.sdk.Size(t.width, t.height)
|
|
335
|
+
});
|
|
336
|
+
return new this.sdk.Marker({
|
|
337
|
+
position: e.position,
|
|
338
|
+
icon: o,
|
|
339
|
+
anchor: t.anchor || "center",
|
|
340
|
+
bubble: !1
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
return new this.sdk.CircleMarker({
|
|
344
|
+
center: e.position,
|
|
345
|
+
radius: t.radius ?? 8,
|
|
346
|
+
fillColor: t.fillColor || "#1677ff",
|
|
347
|
+
fillOpacity: t.fillOpacity ?? 0.8,
|
|
348
|
+
strokeColor: t.strokeColor || "#ffffff",
|
|
349
|
+
strokeWeight: t.strokeWeight ?? 2,
|
|
350
|
+
bubble: !1
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
createPolyline(e) {
|
|
354
|
+
return new this.sdk.Polyline({
|
|
355
|
+
path: e.path,
|
|
356
|
+
strokeColor: e.strokeColor || "#3366ff",
|
|
357
|
+
strokeWeight: e.strokeWeight ?? 5,
|
|
358
|
+
strokeOpacity: e.strokeOpacity ?? 1,
|
|
359
|
+
strokeStyle: e.strokeStyle || "solid",
|
|
360
|
+
bubble: !1
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
createPolygon(e) {
|
|
364
|
+
return new this.sdk.Polygon({
|
|
365
|
+
path: e.path,
|
|
366
|
+
strokeColor: e.strokeColor || "#3366ff",
|
|
367
|
+
strokeWeight: e.strokeWeight ?? 3,
|
|
368
|
+
strokeOpacity: e.strokeOpacity ?? 1,
|
|
369
|
+
strokeStyle: e.strokeStyle || "solid",
|
|
370
|
+
fillColor: e.fillColor || "#3366ff",
|
|
371
|
+
fillOpacity: e.fillOpacity ?? 0.3,
|
|
372
|
+
bubble: !1
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
createMassPointLayer(e) {
|
|
376
|
+
const t = new this.locaSdk.GeoJSONSource({ data: this.toMassPointGeoJSON(e) }), o = e.style || {}, s = o.icon ? new this.locaSdk.IconLayer({
|
|
377
|
+
zIndex: e.zIndex ?? 100,
|
|
378
|
+
opacity: o.opacity ?? 1,
|
|
379
|
+
visible: e.visible !== !1,
|
|
380
|
+
zooms: [e.minZoom ?? 2, e.maxZoom ?? 26]
|
|
381
|
+
}) : new this.locaSdk.PointLayer({
|
|
382
|
+
zIndex: e.zIndex ?? 100,
|
|
383
|
+
opacity: 1,
|
|
384
|
+
visible: e.visible !== !1,
|
|
385
|
+
zooms: [e.minZoom ?? 2, e.maxZoom ?? 26]
|
|
386
|
+
});
|
|
387
|
+
if (s.setSource(t), o.icon) {
|
|
388
|
+
const i = o.icon.width ?? o.size ?? 20, r = o.icon.height ?? o.size ?? 20;
|
|
389
|
+
s.setStyle({
|
|
390
|
+
icon: o.icon.url,
|
|
391
|
+
iconSize: [i, r],
|
|
392
|
+
offset: o.icon.anchor === "bottom-center" ? [0, r / 2] : [0, 0],
|
|
393
|
+
unit: o.unit || "px"
|
|
394
|
+
});
|
|
395
|
+
} else
|
|
396
|
+
s.setStyle({
|
|
397
|
+
radius: (o.size ?? 10) / 2,
|
|
398
|
+
color: p(o.color || "#1677ff", o.opacity ?? 0.85),
|
|
399
|
+
borderWidth: o.borderWidth ?? 0,
|
|
400
|
+
borderColor: o.borderColor || "#ffffff",
|
|
401
|
+
unit: o.unit || "px"
|
|
402
|
+
});
|
|
403
|
+
return this.loca.add(s), { layer: s, source: t };
|
|
404
|
+
}
|
|
405
|
+
createPolylineLayer(e) {
|
|
406
|
+
const t = new this.locaSdk.GeoJSONSource({ data: this.toPolylineLayerGeoJSON(e) }), o = new this.locaSdk.LineLayer({
|
|
407
|
+
zIndex: e.zIndex ?? 90,
|
|
408
|
+
opacity: 1,
|
|
409
|
+
visible: e.visible !== !1,
|
|
410
|
+
zooms: [e.minZoom ?? 2, e.maxZoom ?? 26]
|
|
411
|
+
});
|
|
412
|
+
return o.setSource(t), o.setStyle(this.toPolylineLayerStyle(e)), this.loca.add(o), { layer: o, source: t };
|
|
413
|
+
}
|
|
414
|
+
destroyPolylineLayer(e) {
|
|
415
|
+
var t, o, s, i, r, a;
|
|
416
|
+
(o = (t = this.loca) == null ? void 0 : t.remove) == null || o.call(t, e.layer), (i = (s = e.layer) == null ? void 0 : s.destroy) == null || i.call(s), (a = (r = e.source) == null ? void 0 : r.destroy) == null || a.call(r);
|
|
417
|
+
}
|
|
418
|
+
createPolygonLayer(e) {
|
|
419
|
+
const t = new this.locaSdk.GeoJSONSource({ data: this.toPolygonLayerGeoJSON(e) }), o = new this.locaSdk.GeoJSONSource({ data: this.toPolygonOutlineGeoJSON(e) }), s = new this.locaSdk.PolygonLayer({
|
|
420
|
+
zIndex: e.zIndex ?? 80,
|
|
421
|
+
opacity: 1,
|
|
422
|
+
visible: e.visible !== !1,
|
|
423
|
+
zooms: [e.minZoom ?? 2, e.maxZoom ?? 26],
|
|
424
|
+
cullface: "none",
|
|
425
|
+
acceptLight: !1,
|
|
426
|
+
hasSide: !1,
|
|
427
|
+
hasBottom: !1,
|
|
428
|
+
depth: !1
|
|
429
|
+
});
|
|
430
|
+
s.setSource(t), s.setStyle(this.toPolygonLayerStyle(e));
|
|
431
|
+
const i = new this.locaSdk.LineLayer({
|
|
432
|
+
zIndex: (e.zIndex ?? 80) + 1,
|
|
433
|
+
opacity: 1,
|
|
434
|
+
visible: e.visible !== !1,
|
|
435
|
+
zooms: [e.minZoom ?? 2, e.maxZoom ?? 26]
|
|
436
|
+
});
|
|
437
|
+
return i.setSource(o), i.setStyle(this.toPolygonOutlineStyle(e)), this.loca.add(s), this.loca.add(i), { layer: s, outlineLayer: i, source: t, outlineSource: o };
|
|
438
|
+
}
|
|
439
|
+
destroyPolygonLayer(e) {
|
|
440
|
+
var t, o, s, i, r, a, l, c, h, d, m, L;
|
|
441
|
+
(o = (t = this.loca) == null ? void 0 : t.remove) == null || o.call(t, e.outlineLayer), (i = (s = this.loca) == null ? void 0 : s.remove) == null || i.call(s, e.layer), (a = (r = e.outlineLayer) == null ? void 0 : r.destroy) == null || a.call(r), (c = (l = e.layer) == null ? void 0 : l.destroy) == null || c.call(l), (d = (h = e.outlineSource) == null ? void 0 : h.destroy) == null || d.call(h), (L = (m = e.source) == null ? void 0 : m.destroy) == null || L.call(m);
|
|
442
|
+
}
|
|
443
|
+
toPolylineLayerStyle(e) {
|
|
444
|
+
const t = e.style || {};
|
|
445
|
+
return {
|
|
446
|
+
color: p(t.strokeColor || "#3366ff", t.strokeOpacity ?? 1),
|
|
447
|
+
lineWidth: t.strokeWeight ?? 3,
|
|
448
|
+
borderWidth: 0,
|
|
449
|
+
dash: t.strokeStyle === "dashed" ? [10, 10, 10, 10] : [0, 0, 0, 0]
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
toPolygonLayerStyle(e) {
|
|
453
|
+
const t = e.style || {};
|
|
454
|
+
return {
|
|
455
|
+
topColor: p(t.fillColor || "#3366ff", t.fillOpacity ?? 0.3),
|
|
456
|
+
altitude: 0,
|
|
457
|
+
height: 0
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
toPolygonOutlineStyle(e) {
|
|
461
|
+
const t = e.style || {};
|
|
462
|
+
return {
|
|
463
|
+
color: p(t.strokeColor || "#3366ff", t.strokeOpacity ?? 1),
|
|
464
|
+
lineWidth: t.strokeWeight ?? 2,
|
|
465
|
+
borderWidth: 0,
|
|
466
|
+
dash: t.strokeStyle === "dashed" ? [10, 10, 10, 10] : [0, 0, 0, 0]
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
setLocaLayerVisibility(e, t) {
|
|
470
|
+
var o, s;
|
|
471
|
+
t ? (o = e == null ? void 0 : e.show) == null || o.call(e) : (s = e == null ? void 0 : e.hide) == null || s.call(e);
|
|
472
|
+
}
|
|
473
|
+
destroyMassPointLayer(e) {
|
|
474
|
+
var t, o, s, i, r, a;
|
|
475
|
+
(o = (t = this.loca) == null ? void 0 : t.remove) == null || o.call(t, e.layer), (i = (s = e.layer) == null ? void 0 : s.destroy) == null || i.call(s), (a = (r = e.source) == null ? void 0 : r.destroy) == null || a.call(r);
|
|
476
|
+
}
|
|
477
|
+
createScatterLayer(e) {
|
|
478
|
+
const t = new this.locaSdk.GeoJSONSource({ data: this.toMassPointGeoJSON(e) }), o = new this.locaSdk.ScatterLayer({
|
|
479
|
+
zIndex: e.zIndex ?? 120,
|
|
480
|
+
opacity: 1,
|
|
481
|
+
visible: e.visible !== !1,
|
|
482
|
+
zooms: [e.minZoom ?? 2, e.maxZoom ?? 26]
|
|
483
|
+
}), s = e.style || {};
|
|
484
|
+
return o.setSource(t), o.setStyle({
|
|
485
|
+
size: [s.size ?? 40, s.size ?? 40],
|
|
486
|
+
color: "#ffffff",
|
|
487
|
+
borderWidth: s.borderWidth ?? 0,
|
|
488
|
+
borderColor: s.borderColor || "#ffffff",
|
|
489
|
+
unit: s.unit || "px",
|
|
490
|
+
texture: s.texture || "/breath_red.png",
|
|
491
|
+
animate: !0,
|
|
492
|
+
duration: s.duration ?? 2e3
|
|
493
|
+
}), this.loca.add(o), { layer: o, source: t };
|
|
494
|
+
}
|
|
495
|
+
destroyScatterLayer(e) {
|
|
496
|
+
var t, o, s, i, r, a;
|
|
497
|
+
(o = (t = this.loca) == null ? void 0 : t.remove) == null || o.call(t, e.layer), (i = (s = e.layer) == null ? void 0 : s.destroy) == null || i.call(s), (a = (r = e.source) == null ? void 0 : r.destroy) == null || a.call(r);
|
|
498
|
+
}
|
|
499
|
+
toMassPointGeoJSON(e) {
|
|
500
|
+
return {
|
|
501
|
+
type: "FeatureCollection",
|
|
502
|
+
features: e.points.map((t) => ({
|
|
503
|
+
type: "Feature",
|
|
504
|
+
properties: t.properties || {},
|
|
505
|
+
geometry: { type: "Point", coordinates: t.position }
|
|
506
|
+
}))
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
toPolylineLayerGeoJSON(e) {
|
|
510
|
+
return {
|
|
511
|
+
type: "FeatureCollection",
|
|
512
|
+
features: e.polylines.map((t) => ({
|
|
513
|
+
type: "Feature",
|
|
514
|
+
properties: t.properties || {},
|
|
515
|
+
geometry: { type: "LineString", coordinates: t.path }
|
|
516
|
+
}))
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
toPolygonLayerGeoJSON(e) {
|
|
520
|
+
return {
|
|
521
|
+
type: "FeatureCollection",
|
|
522
|
+
features: e.polygons.map((t) => ({
|
|
523
|
+
type: "Feature",
|
|
524
|
+
properties: t.properties || {},
|
|
525
|
+
geometry: { type: "Polygon", coordinates: [this.closeRing(t.path)] }
|
|
526
|
+
}))
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
toPolygonOutlineGeoJSON(e) {
|
|
530
|
+
return {
|
|
531
|
+
type: "FeatureCollection",
|
|
532
|
+
features: e.polygons.map((t) => ({
|
|
533
|
+
type: "Feature",
|
|
534
|
+
properties: t.properties || {},
|
|
535
|
+
geometry: { type: "LineString", coordinates: this.closeRing(t.path) }
|
|
536
|
+
}))
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
closeRing(e) {
|
|
540
|
+
const t = e[0], o = e[e.length - 1];
|
|
541
|
+
return t[0] === o[0] && t[1] === o[1] ? e : [...e, t];
|
|
542
|
+
}
|
|
543
|
+
toPolylineStyle(e) {
|
|
544
|
+
return {
|
|
545
|
+
strokeColor: e.strokeColor || "#3366ff",
|
|
546
|
+
strokeWeight: e.strokeWeight ?? 5,
|
|
547
|
+
strokeOpacity: e.strokeOpacity ?? 1,
|
|
548
|
+
strokeStyle: e.strokeStyle || "solid",
|
|
549
|
+
bubble: !1
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
toPolygonStyle(e) {
|
|
553
|
+
const t = e;
|
|
554
|
+
return {
|
|
555
|
+
strokeColor: e.strokeColor || "#3366ff",
|
|
556
|
+
strokeWeight: e.strokeWeight ?? 3,
|
|
557
|
+
strokeOpacity: e.strokeOpacity ?? 1,
|
|
558
|
+
strokeStyle: e.strokeStyle || "solid",
|
|
559
|
+
fillColor: t.fillColor || "#3366ff",
|
|
560
|
+
fillOpacity: t.fillOpacity ?? 0.3,
|
|
561
|
+
bubble: !1
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
cleanupDraw(e) {
|
|
565
|
+
var t, o, s, i;
|
|
566
|
+
(o = (t = this.mouseTool) == null ? void 0 : t.off) == null || o.call(t, "draw", e.handler), (i = (s = this.mouseTool) == null ? void 0 : s.close) == null || i.call(s), this.activeDraw === e && (this.activeDraw = null);
|
|
567
|
+
}
|
|
568
|
+
finishEdit(e) {
|
|
569
|
+
var o, s, i, r;
|
|
570
|
+
if (e.stopped)
|
|
571
|
+
return;
|
|
572
|
+
const t = this.getPath(e.native);
|
|
573
|
+
t && e.onChange(t), e.stopped = !0, (s = (o = e.editor).close) == null || s.call(o);
|
|
574
|
+
for (const { event: a, handler: l } of e.handlers)
|
|
575
|
+
(r = (i = e.editor).off) == null || r.call(i, a, l);
|
|
576
|
+
this.activeEdit === e && (this.activeEdit = null);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
export {
|
|
580
|
+
E as AMapAdapter
|
|
581
|
+
};
|