@lin1538001/unified-map 0.0.0-stage → 0.1.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 +82 -2
- package/dist/chunks/AMapAdapter-6257126f.js +528 -0
- package/dist/chunks/ArcGISAdapter-09b4e73f.js +863 -0
- package/dist/chunks/BMapAdapter-eb942a66.js +530 -0
- package/dist/chunks/color-128d7dff.js +38 -0
- package/dist/chunks/index-5b75eace.js +893 -0
- package/dist/chunks/mapLoader-06d6e155.js +226 -0
- package/dist/index.js +6 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/map/UnifiedMap.d.ts +240 -0
- package/dist/types/map/UnifiedMap.d.ts.map +1 -0
- package/dist/types/map/adapters/AMapAdapter.d.ts +82 -0
- package/dist/types/map/adapters/AMapAdapter.d.ts.map +1 -0
- package/dist/types/map/adapters/ArcGISAdapter.d.ts +85 -0
- package/dist/types/map/adapters/ArcGISAdapter.d.ts.map +1 -0
- package/dist/types/map/adapters/BMapAdapter.d.ts +77 -0
- package/dist/types/map/adapters/BMapAdapter.d.ts.map +1 -0
- package/dist/types/map/adapters/MapAdapter.d.ts +40 -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 +4 -0
- package/dist/types/map/index.d.ts.map +1 -0
- package/dist/types/map/types.d.ts +204 -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
|
+
# @linyy/unified-map
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
一个 TypeScript 地图适配层,为高德地图、百度地图和 ArcGIS 提供统一的生命周期、覆盖物、批量图层、绘制与编辑 API。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @linyy/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 '@linyy/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,528 @@
|
|
|
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 P } from "./mapLoader-06d6e155.js";
|
|
5
|
+
import { M as n, a as u } from "./index-5b75eace.js";
|
|
6
|
+
import { t as m } from "./color-128d7dff.js";
|
|
7
|
+
import "vue";
|
|
8
|
+
class v {
|
|
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, r, s, i;
|
|
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 P(e.key), this.loca = new this.locaSdk.Container({ map: this.map });
|
|
35
|
+
} catch (a) {
|
|
36
|
+
throw (r = (o = this.loca) == null ? void 0 : o.destroy) == null || r.call(o), this.loca = null, this.locaSdk = null, (i = (s = this.map) == null ? void 0 : s.destroy) == null || i.call(s), 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, r, s;
|
|
41
|
+
this.activeEdit && this.finishEdit(this.activeEdit), this.cancelDraw();
|
|
42
|
+
for (const i of this.massPointLayers)
|
|
43
|
+
this.destroyMassPointLayer(i);
|
|
44
|
+
this.massPointLayers.clear();
|
|
45
|
+
for (const i of this.scatterLayers)
|
|
46
|
+
this.destroyScatterLayer(i);
|
|
47
|
+
this.scatterLayers.clear();
|
|
48
|
+
for (const i of this.polylineLayers)
|
|
49
|
+
this.destroyPolylineLayer(i);
|
|
50
|
+
this.polylineLayers.clear();
|
|
51
|
+
for (const i of this.polygonLayers)
|
|
52
|
+
this.destroyPolygonLayer(i);
|
|
53
|
+
this.polygonLayers.clear(), (o = (t = (e = this.loca) == null ? void 0 : e.animate) == null ? void 0 : t.stop) == null || o.call(t), (s = (r = this.loca) == null ? void 0 : r.destroy) == null || s.call(r), 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 i, a;
|
|
75
|
+
const r = e;
|
|
76
|
+
if (!this.polylineLayers.has(r))
|
|
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 = (i = r.layer).setStyle) == null || a.call(i, this.toPolylineLayerStyle(t))), "visible" in o && this.setLocaLayerVisibility(r.layer, t.visible !== !1), e;
|
|
80
|
+
const s = this.createPolylineLayer(t);
|
|
81
|
+
return this.polylineLayers.add(s), this.destroyPolylineLayer(r), this.polylineLayers.delete(r), s;
|
|
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 i, a, l, h;
|
|
95
|
+
const r = e;
|
|
96
|
+
if (!this.polygonLayers.has(r))
|
|
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 = (i = r.layer).setStyle) == null || a.call(i, this.toPolygonLayerStyle(t)), (h = (l = r.outlineLayer).setStyle) == null || h.call(l, this.toPolygonOutlineStyle(t))), "visible" in o && (this.setLocaLayerVisibility(r.layer, t.visible !== !1), this.setLocaLayerVisibility(r.outlineLayer, t.visible !== !1)), e;
|
|
100
|
+
const s = this.createPolygonLayer(t);
|
|
101
|
+
return this.polygonLayers.add(s), this.destroyPolygonLayer(r), this.polygonLayers.delete(r), s;
|
|
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 r = this.createMassPointLayer(t);
|
|
118
|
+
return this.massPointLayers.add(r), this.destroyMassPointLayer(o), this.massPointLayers.delete(o), r;
|
|
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, r;
|
|
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), (r = (o = this.loca.animate) == null ? void 0 : o.start) == null || r.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 r = this.createScatterLayer(t);
|
|
136
|
+
return this.scatterLayers.add(r), this.destroyScatterLayer(o), this.scatterLayers.delete(o), r;
|
|
137
|
+
}
|
|
138
|
+
removeScatterLayer(e) {
|
|
139
|
+
var o, r, s;
|
|
140
|
+
const t = e;
|
|
141
|
+
this.scatterLayers.has(t) && (this.destroyScatterLayer(t), this.scatterLayers.delete(t), this.scatterLayers.size === 0 && ((s = (r = (o = this.loca) == null ? void 0 : o.animate) == null ? void 0 : r.stop) == null || s.call(r)));
|
|
142
|
+
}
|
|
143
|
+
updateOverlay(e, t, o) {
|
|
144
|
+
var i, a, l, h;
|
|
145
|
+
const r = this.overlayKinds.get(e);
|
|
146
|
+
if (!r)
|
|
147
|
+
throw new n("OVERLAY_NOT_FOUND", "Overlay is no longer registered");
|
|
148
|
+
const s = e;
|
|
149
|
+
if (r === "polyline") {
|
|
150
|
+
const c = t;
|
|
151
|
+
return (i = s.setOptions) == null || i.call(s, this.toPolylineStyle(c)), "path" in o && ((a = s.setPath) == null || a.call(s, c.path)), e;
|
|
152
|
+
}
|
|
153
|
+
if (r === "polygon") {
|
|
154
|
+
const c = t;
|
|
155
|
+
return (l = s.setOptions) == null || l.call(s, this.toPolygonStyle(c)), "path" in o && ((h = s.setPath) == null || h.call(s, c.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 r;
|
|
169
|
+
const t = e;
|
|
170
|
+
if (!t)
|
|
171
|
+
return null;
|
|
172
|
+
const o = typeof t.getPosition == "function" ? t.getPosition() : (r = t.getCenter) == null ? void 0 : r.call(t);
|
|
173
|
+
return o ? u([o.lng, o.lat]) : null;
|
|
174
|
+
}
|
|
175
|
+
onMapClick(e) {
|
|
176
|
+
const t = (o) => {
|
|
177
|
+
const r = this.toClickEvent(o);
|
|
178
|
+
r && e(r);
|
|
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 s;
|
|
187
|
+
const o = (i) => {
|
|
188
|
+
const a = this.toClickEvent(i, e);
|
|
189
|
+
a && t(a);
|
|
190
|
+
}, r = e;
|
|
191
|
+
return (s = r.on) == null || s.call(r, "click", o), () => {
|
|
192
|
+
var i;
|
|
193
|
+
return (i = r.off) == null ? void 0 : i.call(r, "click", o);
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
startEdit(e, t, o) {
|
|
197
|
+
var l, h, c;
|
|
198
|
+
if (this.overlayKinds.get(e) !== t)
|
|
199
|
+
throw new n("INVALID_OPTIONS", "Only polyline and polygon overlays can be edited");
|
|
200
|
+
const r = t === "polyline" ? (l = this.sdk) == null ? void 0 : l.PolylineEditor : (h = this.sdk) == null ? void 0 : h.PolygonEditor;
|
|
201
|
+
if (!r)
|
|
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 s = new r(this.map, e), i = { native: e, editor: s, handlers: [], onChange: o, stopped: !1 }, a = () => {
|
|
207
|
+
if (i.stopped)
|
|
208
|
+
return;
|
|
209
|
+
const d = this.getPath(i.native);
|
|
210
|
+
d && i.onChange(d);
|
|
211
|
+
};
|
|
212
|
+
for (const d of ["adjust", "addnode", "removenode", "end"])
|
|
213
|
+
(c = s.on) == null || c.call(s, d, a), i.handlers.push({ event: d, handler: a });
|
|
214
|
+
this.activeEdit = i;
|
|
215
|
+
try {
|
|
216
|
+
s.open();
|
|
217
|
+
} catch (d) {
|
|
218
|
+
throw this.finishEdit(i), new n("SDK_ERROR", `Failed to start AMap ${t} editing`, { cause: d });
|
|
219
|
+
}
|
|
220
|
+
return () => this.finishEdit(i);
|
|
221
|
+
}
|
|
222
|
+
startDraw(e, t, o, r) {
|
|
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 s = (i) => {
|
|
227
|
+
const a = this.activeDraw;
|
|
228
|
+
if (!a || a.completed)
|
|
229
|
+
return;
|
|
230
|
+
a.completed = !0, this.cleanupDraw(a);
|
|
231
|
+
const l = i == null ? void 0 : i.obj;
|
|
232
|
+
l && this.remember(l, e);
|
|
233
|
+
const h = this.getPath(l) || [];
|
|
234
|
+
o(l, h);
|
|
235
|
+
};
|
|
236
|
+
this.activeDraw = { handler: s, onCancel: r, completed: !1 }, this.mouseTool.on("draw", s), 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
|
+
resolveContainer(e) {
|
|
256
|
+
if (typeof e == "string") {
|
|
257
|
+
if (!document.getElementById(e))
|
|
258
|
+
throw new n("INVALID_OPTIONS", `Container not found: ${e}`);
|
|
259
|
+
return e;
|
|
260
|
+
}
|
|
261
|
+
if (!e)
|
|
262
|
+
throw new n("INVALID_OPTIONS", "A map container is required");
|
|
263
|
+
return e.id || (e.id = `unified-map-${Math.random().toString(36).slice(2)}`), e.id;
|
|
264
|
+
}
|
|
265
|
+
remember(e, t) {
|
|
266
|
+
this.overlayKinds.set(e, t);
|
|
267
|
+
}
|
|
268
|
+
toClickEvent(e, t) {
|
|
269
|
+
const o = this.resolveClickPosition(e, t);
|
|
270
|
+
return o ? {
|
|
271
|
+
lnglat: { lng: o[0], lat: o[1] },
|
|
272
|
+
position: o,
|
|
273
|
+
coordinateSystem: this.coordinateSystem,
|
|
274
|
+
originalEvent: e
|
|
275
|
+
} : null;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* 解析点击坐标:优先事件自带 lnglat,其次覆盖物锚点,
|
|
279
|
+
* 最后回退到线/面路径首点——保证线/面点击事件不因缺少坐标而被整体丢弃
|
|
280
|
+
*/
|
|
281
|
+
resolveClickPosition(e, t) {
|
|
282
|
+
const o = (e == null ? void 0 : e.lnglat) || (t ? this.getPosition(t) : null);
|
|
283
|
+
if (o)
|
|
284
|
+
return Array.isArray(o) ? u(o) : u([o.lng, o.lat]);
|
|
285
|
+
if (!t)
|
|
286
|
+
return null;
|
|
287
|
+
const r = this.getPath(t);
|
|
288
|
+
return r && r.length > 0 ? r[0] : null;
|
|
289
|
+
}
|
|
290
|
+
createMarker(e) {
|
|
291
|
+
const t = e.style || { kind: "circle" };
|
|
292
|
+
if (t.kind === "icon") {
|
|
293
|
+
const o = new this.sdk.Icon({
|
|
294
|
+
image: t.url,
|
|
295
|
+
size: new this.sdk.Size(t.width, t.height),
|
|
296
|
+
imageSize: new this.sdk.Size(t.width, t.height)
|
|
297
|
+
});
|
|
298
|
+
return new this.sdk.Marker({
|
|
299
|
+
position: e.position,
|
|
300
|
+
icon: o,
|
|
301
|
+
anchor: t.anchor || "center",
|
|
302
|
+
bubble: !1
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
return new this.sdk.CircleMarker({
|
|
306
|
+
center: e.position,
|
|
307
|
+
radius: t.radius ?? 8,
|
|
308
|
+
fillColor: t.fillColor || "#1677ff",
|
|
309
|
+
fillOpacity: t.fillOpacity ?? 0.8,
|
|
310
|
+
strokeColor: t.strokeColor || "#ffffff",
|
|
311
|
+
strokeWeight: t.strokeWeight ?? 2,
|
|
312
|
+
bubble: !1
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
createPolyline(e) {
|
|
316
|
+
return new this.sdk.Polyline({
|
|
317
|
+
path: e.path,
|
|
318
|
+
strokeColor: e.strokeColor || "#3366ff",
|
|
319
|
+
strokeWeight: e.strokeWeight ?? 5,
|
|
320
|
+
strokeOpacity: e.strokeOpacity ?? 1,
|
|
321
|
+
strokeStyle: e.strokeStyle || "solid",
|
|
322
|
+
bubble: !1
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
createPolygon(e) {
|
|
326
|
+
return new this.sdk.Polygon({
|
|
327
|
+
path: e.path,
|
|
328
|
+
strokeColor: e.strokeColor || "#3366ff",
|
|
329
|
+
strokeWeight: e.strokeWeight ?? 3,
|
|
330
|
+
strokeOpacity: e.strokeOpacity ?? 1,
|
|
331
|
+
strokeStyle: e.strokeStyle || "solid",
|
|
332
|
+
fillColor: e.fillColor || "#3366ff",
|
|
333
|
+
fillOpacity: e.fillOpacity ?? 0.3,
|
|
334
|
+
bubble: !1
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
createMassPointLayer(e) {
|
|
338
|
+
const t = new this.locaSdk.GeoJSONSource({ data: this.toMassPointGeoJSON(e) }), o = new this.locaSdk.PointLayer({
|
|
339
|
+
zIndex: e.zIndex ?? 100,
|
|
340
|
+
opacity: 1,
|
|
341
|
+
visible: e.visible !== !1,
|
|
342
|
+
zooms: [e.minZoom ?? 2, e.maxZoom ?? 26]
|
|
343
|
+
}), r = e.style || {};
|
|
344
|
+
return o.setSource(t), o.setStyle({
|
|
345
|
+
radius: (r.size ?? 10) / 2,
|
|
346
|
+
color: m(r.color || "#1677ff", r.opacity ?? 0.85),
|
|
347
|
+
borderWidth: r.borderWidth ?? 0,
|
|
348
|
+
borderColor: r.borderColor || "#ffffff",
|
|
349
|
+
unit: r.unit || "px"
|
|
350
|
+
}), this.loca.add(o), { layer: o, source: t };
|
|
351
|
+
}
|
|
352
|
+
createPolylineLayer(e) {
|
|
353
|
+
const t = new this.locaSdk.GeoJSONSource({ data: this.toPolylineLayerGeoJSON(e) }), o = new this.locaSdk.LineLayer({
|
|
354
|
+
zIndex: e.zIndex ?? 90,
|
|
355
|
+
opacity: 1,
|
|
356
|
+
visible: e.visible !== !1,
|
|
357
|
+
zooms: [e.minZoom ?? 2, e.maxZoom ?? 26]
|
|
358
|
+
});
|
|
359
|
+
return o.setSource(t), o.setStyle(this.toPolylineLayerStyle(e)), this.loca.add(o), { layer: o, source: t };
|
|
360
|
+
}
|
|
361
|
+
destroyPolylineLayer(e) {
|
|
362
|
+
var t, o, r, s, i, a;
|
|
363
|
+
(o = (t = this.loca) == null ? void 0 : t.remove) == null || o.call(t, e.layer), (s = (r = e.layer) == null ? void 0 : r.destroy) == null || s.call(r), (a = (i = e.source) == null ? void 0 : i.destroy) == null || a.call(i);
|
|
364
|
+
}
|
|
365
|
+
createPolygonLayer(e) {
|
|
366
|
+
const t = new this.locaSdk.GeoJSONSource({ data: this.toPolygonLayerGeoJSON(e) }), o = new this.locaSdk.GeoJSONSource({ data: this.toPolygonOutlineGeoJSON(e) }), r = new this.locaSdk.PolygonLayer({
|
|
367
|
+
zIndex: e.zIndex ?? 80,
|
|
368
|
+
opacity: 1,
|
|
369
|
+
visible: e.visible !== !1,
|
|
370
|
+
zooms: [e.minZoom ?? 2, e.maxZoom ?? 26],
|
|
371
|
+
cullface: "none",
|
|
372
|
+
acceptLight: !1,
|
|
373
|
+
hasSide: !1,
|
|
374
|
+
hasBottom: !1,
|
|
375
|
+
depth: !1
|
|
376
|
+
});
|
|
377
|
+
r.setSource(t), r.setStyle(this.toPolygonLayerStyle(e));
|
|
378
|
+
const s = new this.locaSdk.LineLayer({
|
|
379
|
+
zIndex: (e.zIndex ?? 80) + 1,
|
|
380
|
+
opacity: 1,
|
|
381
|
+
visible: e.visible !== !1,
|
|
382
|
+
zooms: [e.minZoom ?? 2, e.maxZoom ?? 26]
|
|
383
|
+
});
|
|
384
|
+
return s.setSource(o), s.setStyle(this.toPolygonOutlineStyle(e)), this.loca.add(r), this.loca.add(s), { layer: r, outlineLayer: s, source: t, outlineSource: o };
|
|
385
|
+
}
|
|
386
|
+
destroyPolygonLayer(e) {
|
|
387
|
+
var t, o, r, s, i, a, l, h, c, d, p, L;
|
|
388
|
+
(o = (t = this.loca) == null ? void 0 : t.remove) == null || o.call(t, e.outlineLayer), (s = (r = this.loca) == null ? void 0 : r.remove) == null || s.call(r, e.layer), (a = (i = e.outlineLayer) == null ? void 0 : i.destroy) == null || a.call(i), (h = (l = e.layer) == null ? void 0 : l.destroy) == null || h.call(l), (d = (c = e.outlineSource) == null ? void 0 : c.destroy) == null || d.call(c), (L = (p = e.source) == null ? void 0 : p.destroy) == null || L.call(p);
|
|
389
|
+
}
|
|
390
|
+
toPolylineLayerStyle(e) {
|
|
391
|
+
const t = e.style || {};
|
|
392
|
+
return {
|
|
393
|
+
color: m(t.strokeColor || "#3366ff", t.strokeOpacity ?? 1),
|
|
394
|
+
lineWidth: t.strokeWeight ?? 3,
|
|
395
|
+
borderWidth: 0,
|
|
396
|
+
dash: t.strokeStyle === "dashed" ? [10, 10, 10, 10] : [0, 0, 0, 0]
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
toPolygonLayerStyle(e) {
|
|
400
|
+
const t = e.style || {};
|
|
401
|
+
return {
|
|
402
|
+
topColor: m(t.fillColor || "#3366ff", t.fillOpacity ?? 0.3),
|
|
403
|
+
altitude: 0,
|
|
404
|
+
height: 0
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
toPolygonOutlineStyle(e) {
|
|
408
|
+
const t = e.style || {};
|
|
409
|
+
return {
|
|
410
|
+
color: m(t.strokeColor || "#3366ff", t.strokeOpacity ?? 1),
|
|
411
|
+
lineWidth: t.strokeWeight ?? 2,
|
|
412
|
+
borderWidth: 0,
|
|
413
|
+
dash: t.strokeStyle === "dashed" ? [10, 10, 10, 10] : [0, 0, 0, 0]
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
setLocaLayerVisibility(e, t) {
|
|
417
|
+
var o, r;
|
|
418
|
+
t ? (o = e == null ? void 0 : e.show) == null || o.call(e) : (r = e == null ? void 0 : e.hide) == null || r.call(e);
|
|
419
|
+
}
|
|
420
|
+
destroyMassPointLayer(e) {
|
|
421
|
+
var t, o, r, s, i, a;
|
|
422
|
+
(o = (t = this.loca) == null ? void 0 : t.remove) == null || o.call(t, e.layer), (s = (r = e.layer) == null ? void 0 : r.destroy) == null || s.call(r), (a = (i = e.source) == null ? void 0 : i.destroy) == null || a.call(i);
|
|
423
|
+
}
|
|
424
|
+
createScatterLayer(e) {
|
|
425
|
+
const t = new this.locaSdk.GeoJSONSource({ data: this.toMassPointGeoJSON(e) }), o = new this.locaSdk.ScatterLayer({
|
|
426
|
+
zIndex: e.zIndex ?? 120,
|
|
427
|
+
opacity: 1,
|
|
428
|
+
visible: e.visible !== !1,
|
|
429
|
+
zooms: [e.minZoom ?? 2, e.maxZoom ?? 26]
|
|
430
|
+
}), r = e.style || {};
|
|
431
|
+
return o.setSource(t), o.setStyle({
|
|
432
|
+
size: [r.size ?? 40, r.size ?? 40],
|
|
433
|
+
color: "#ffffff",
|
|
434
|
+
borderWidth: r.borderWidth ?? 0,
|
|
435
|
+
borderColor: r.borderColor || "#ffffff",
|
|
436
|
+
unit: r.unit || "px",
|
|
437
|
+
texture: r.texture || "/breath_red.png",
|
|
438
|
+
animate: !0,
|
|
439
|
+
duration: r.duration ?? 2e3
|
|
440
|
+
}), this.loca.add(o), { layer: o, source: t };
|
|
441
|
+
}
|
|
442
|
+
destroyScatterLayer(e) {
|
|
443
|
+
var t, o, r, s, i, a;
|
|
444
|
+
(o = (t = this.loca) == null ? void 0 : t.remove) == null || o.call(t, e.layer), (s = (r = e.layer) == null ? void 0 : r.destroy) == null || s.call(r), (a = (i = e.source) == null ? void 0 : i.destroy) == null || a.call(i);
|
|
445
|
+
}
|
|
446
|
+
toMassPointGeoJSON(e) {
|
|
447
|
+
return {
|
|
448
|
+
type: "FeatureCollection",
|
|
449
|
+
features: e.points.map((t) => ({
|
|
450
|
+
type: "Feature",
|
|
451
|
+
properties: t.properties || {},
|
|
452
|
+
geometry: { type: "Point", coordinates: t.position }
|
|
453
|
+
}))
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
toPolylineLayerGeoJSON(e) {
|
|
457
|
+
return {
|
|
458
|
+
type: "FeatureCollection",
|
|
459
|
+
features: e.polylines.map((t) => ({
|
|
460
|
+
type: "Feature",
|
|
461
|
+
properties: t.properties || {},
|
|
462
|
+
geometry: { type: "LineString", coordinates: t.path }
|
|
463
|
+
}))
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
toPolygonLayerGeoJSON(e) {
|
|
467
|
+
return {
|
|
468
|
+
type: "FeatureCollection",
|
|
469
|
+
features: e.polygons.map((t) => ({
|
|
470
|
+
type: "Feature",
|
|
471
|
+
properties: t.properties || {},
|
|
472
|
+
geometry: { type: "Polygon", coordinates: [this.closeRing(t.path)] }
|
|
473
|
+
}))
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
toPolygonOutlineGeoJSON(e) {
|
|
477
|
+
return {
|
|
478
|
+
type: "FeatureCollection",
|
|
479
|
+
features: e.polygons.map((t) => ({
|
|
480
|
+
type: "Feature",
|
|
481
|
+
properties: t.properties || {},
|
|
482
|
+
geometry: { type: "LineString", coordinates: this.closeRing(t.path) }
|
|
483
|
+
}))
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
closeRing(e) {
|
|
487
|
+
const t = e[0], o = e[e.length - 1];
|
|
488
|
+
return t[0] === o[0] && t[1] === o[1] ? e : [...e, t];
|
|
489
|
+
}
|
|
490
|
+
toPolylineStyle(e) {
|
|
491
|
+
return {
|
|
492
|
+
strokeColor: e.strokeColor || "#3366ff",
|
|
493
|
+
strokeWeight: e.strokeWeight ?? 5,
|
|
494
|
+
strokeOpacity: e.strokeOpacity ?? 1,
|
|
495
|
+
strokeStyle: e.strokeStyle || "solid",
|
|
496
|
+
bubble: !1
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
toPolygonStyle(e) {
|
|
500
|
+
const t = e;
|
|
501
|
+
return {
|
|
502
|
+
strokeColor: e.strokeColor || "#3366ff",
|
|
503
|
+
strokeWeight: e.strokeWeight ?? 3,
|
|
504
|
+
strokeOpacity: e.strokeOpacity ?? 1,
|
|
505
|
+
strokeStyle: e.strokeStyle || "solid",
|
|
506
|
+
fillColor: t.fillColor || "#3366ff",
|
|
507
|
+
fillOpacity: t.fillOpacity ?? 0.3,
|
|
508
|
+
bubble: !1
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
cleanupDraw(e) {
|
|
512
|
+
var t, o, r, s;
|
|
513
|
+
(o = (t = this.mouseTool) == null ? void 0 : t.off) == null || o.call(t, "draw", e.handler), (s = (r = this.mouseTool) == null ? void 0 : r.close) == null || s.call(r), this.activeDraw === e && (this.activeDraw = null);
|
|
514
|
+
}
|
|
515
|
+
finishEdit(e) {
|
|
516
|
+
var o, r, s, i;
|
|
517
|
+
if (e.stopped)
|
|
518
|
+
return;
|
|
519
|
+
const t = this.getPath(e.native);
|
|
520
|
+
t && e.onChange(t), e.stopped = !0, (r = (o = e.editor).close) == null || r.call(o);
|
|
521
|
+
for (const { event: a, handler: l } of e.handlers)
|
|
522
|
+
(i = (s = e.editor).off) == null || i.call(s, a, l);
|
|
523
|
+
this.activeEdit === e && (this.activeEdit = null);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
export {
|
|
527
|
+
v as AMapAdapter
|
|
528
|
+
};
|