@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
|
@@ -0,0 +1,893 @@
|
|
|
1
|
+
var O = Object.defineProperty;
|
|
2
|
+
var g = (a, e, t) => e in a ? O(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
|
|
3
|
+
var d = (a, e, t) => (g(a, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { markRaw as v } from "vue";
|
|
5
|
+
class o extends Error {
|
|
6
|
+
constructor(t, i, s) {
|
|
7
|
+
super(i);
|
|
8
|
+
d(this, "code");
|
|
9
|
+
if (this.name = "MapError", this.code = t, s && "cause" in s) {
|
|
10
|
+
const r = this;
|
|
11
|
+
r.cause = s.cause;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function L(a) {
|
|
16
|
+
return a === "amap" ? "gcj02" : a === "baidu" ? "bd09" : "wgs84";
|
|
17
|
+
}
|
|
18
|
+
function w(a, e = "coordinate") {
|
|
19
|
+
if (a.length !== 2 || !Number.isFinite(a[0]) || !Number.isFinite(a[1]) || a[0] < -180 || a[0] > 180 || a[1] < -90 || a[1] > 90)
|
|
20
|
+
throw new o("INVALID_OPTIONS", `${e} must be [longitude, latitude] in valid ranges`);
|
|
21
|
+
return [a[0], a[1]];
|
|
22
|
+
}
|
|
23
|
+
function m(a, e) {
|
|
24
|
+
const t = L(e);
|
|
25
|
+
if (a && a !== t)
|
|
26
|
+
throw new o(
|
|
27
|
+
"COORDINATE_SYSTEM_MISMATCH",
|
|
28
|
+
`${e} expects ${t} coordinates, received ${a}`
|
|
29
|
+
);
|
|
30
|
+
return a || t;
|
|
31
|
+
}
|
|
32
|
+
function p(a, e) {
|
|
33
|
+
if (!Array.isArray(a) || a.length < e)
|
|
34
|
+
throw new o("INVALID_GEOMETRY", `path requires at least ${e} points`);
|
|
35
|
+
const t = a.map((i, s) => w(i, `path[${s}]`));
|
|
36
|
+
if (t.length > 1) {
|
|
37
|
+
const i = t[0], s = t[t.length - 1];
|
|
38
|
+
i[0] === s[0] && i[1] === s[1] && t.pop();
|
|
39
|
+
}
|
|
40
|
+
if (t.length < e)
|
|
41
|
+
throw new o("INVALID_GEOMETRY", `path requires at least ${e} distinct points`);
|
|
42
|
+
return t;
|
|
43
|
+
}
|
|
44
|
+
class I {
|
|
45
|
+
constructor(e, t, i, s) {
|
|
46
|
+
d(this, "id");
|
|
47
|
+
d(this, "kind");
|
|
48
|
+
d(this, "coordinateSystem");
|
|
49
|
+
this.owner = e, this.id = t, this.kind = i, this.coordinateSystem = s;
|
|
50
|
+
}
|
|
51
|
+
/** 获取覆盖物路径(仅折线/多边形有值,marker 返回 null) */
|
|
52
|
+
getPath() {
|
|
53
|
+
return this.owner.getOverlayPath(this.id);
|
|
54
|
+
}
|
|
55
|
+
/** 获取覆盖物锚点位置(具体语义由各适配器实现决定) */
|
|
56
|
+
getPosition() {
|
|
57
|
+
return this.owner.getOverlayPosition(this.id);
|
|
58
|
+
}
|
|
59
|
+
/** 部分更新覆盖物配置 */
|
|
60
|
+
setOptions(e) {
|
|
61
|
+
this.owner.updateOverlay(this.id, e);
|
|
62
|
+
}
|
|
63
|
+
/** 删除该覆盖物 */
|
|
64
|
+
remove() {
|
|
65
|
+
this.owner.removeOverlay(this);
|
|
66
|
+
}
|
|
67
|
+
/** 绑定该覆盖物的点击事件,返回退订函数 */
|
|
68
|
+
on(e, t) {
|
|
69
|
+
if (e !== "click")
|
|
70
|
+
throw new o("INVALID_OPTIONS", `Unsupported overlay event: ${e}`);
|
|
71
|
+
return this.owner.onOverlayClick(this.id, t);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
class f {
|
|
75
|
+
constructor(e, t, i) {
|
|
76
|
+
d(this, "id");
|
|
77
|
+
d(this, "coordinateSystem");
|
|
78
|
+
this.owner = e, this.id = t, this.coordinateSystem = i;
|
|
79
|
+
}
|
|
80
|
+
setData(e) {
|
|
81
|
+
this.owner.updateMassPointLayer(this.id, { points: e });
|
|
82
|
+
}
|
|
83
|
+
setOptions(e) {
|
|
84
|
+
this.owner.updateMassPointLayer(this.id, e);
|
|
85
|
+
}
|
|
86
|
+
show() {
|
|
87
|
+
this.owner.updateMassPointLayer(this.id, { visible: !0 });
|
|
88
|
+
}
|
|
89
|
+
hide() {
|
|
90
|
+
this.owner.updateMassPointLayer(this.id, { visible: !1 });
|
|
91
|
+
}
|
|
92
|
+
remove() {
|
|
93
|
+
this.owner.removeMassPointLayer(this.id);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
class P {
|
|
97
|
+
constructor(e, t, i) {
|
|
98
|
+
d(this, "id");
|
|
99
|
+
d(this, "coordinateSystem");
|
|
100
|
+
this.owner = e, this.id = t, this.coordinateSystem = i;
|
|
101
|
+
}
|
|
102
|
+
setData(e) {
|
|
103
|
+
this.owner.updateScatterLayer(this.id, { points: e });
|
|
104
|
+
}
|
|
105
|
+
setOptions(e) {
|
|
106
|
+
this.owner.updateScatterLayer(this.id, e);
|
|
107
|
+
}
|
|
108
|
+
show() {
|
|
109
|
+
this.owner.updateScatterLayer(this.id, { visible: !0 });
|
|
110
|
+
}
|
|
111
|
+
hide() {
|
|
112
|
+
this.owner.updateScatterLayer(this.id, { visible: !1 });
|
|
113
|
+
}
|
|
114
|
+
remove() {
|
|
115
|
+
this.owner.removeScatterLayer(this.id);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
class b {
|
|
119
|
+
constructor(e, t, i) {
|
|
120
|
+
d(this, "id");
|
|
121
|
+
d(this, "coordinateSystem");
|
|
122
|
+
this.owner = e, this.id = t, this.coordinateSystem = i;
|
|
123
|
+
}
|
|
124
|
+
setData(e) {
|
|
125
|
+
this.owner.updatePolylineLayer(this.id, { polylines: e });
|
|
126
|
+
}
|
|
127
|
+
setOptions(e) {
|
|
128
|
+
this.owner.updatePolylineLayer(this.id, e);
|
|
129
|
+
}
|
|
130
|
+
show() {
|
|
131
|
+
this.owner.updatePolylineLayer(this.id, { visible: !0 });
|
|
132
|
+
}
|
|
133
|
+
hide() {
|
|
134
|
+
this.owner.updatePolylineLayer(this.id, { visible: !1 });
|
|
135
|
+
}
|
|
136
|
+
remove() {
|
|
137
|
+
this.owner.removePolylineLayer(this.id);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
class S {
|
|
141
|
+
constructor(e, t, i) {
|
|
142
|
+
d(this, "id");
|
|
143
|
+
d(this, "coordinateSystem");
|
|
144
|
+
this.owner = e, this.id = t, this.coordinateSystem = i;
|
|
145
|
+
}
|
|
146
|
+
setData(e) {
|
|
147
|
+
this.owner.updatePolygonLayer(this.id, { polygons: e });
|
|
148
|
+
}
|
|
149
|
+
setOptions(e) {
|
|
150
|
+
this.owner.updatePolygonLayer(this.id, e);
|
|
151
|
+
}
|
|
152
|
+
show() {
|
|
153
|
+
this.owner.updatePolygonLayer(this.id, { visible: !0 });
|
|
154
|
+
}
|
|
155
|
+
hide() {
|
|
156
|
+
this.owner.updatePolygonLayer(this.id, { visible: !1 });
|
|
157
|
+
}
|
|
158
|
+
remove() {
|
|
159
|
+
this.owner.removePolygonLayer(this.id);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
class A {
|
|
163
|
+
/** 构造函数:只校验配置,具体厂商适配器在 init 时按需加载。 */
|
|
164
|
+
constructor(e) {
|
|
165
|
+
/** 构造时传入的初始化配置(已做浅拷贝,外部修改不影响内部状态) */
|
|
166
|
+
d(this, "options");
|
|
167
|
+
/** 具体 SDK 适配器按 provider 延迟加载,避免未使用的厂商 SDK 进入首包。 */
|
|
168
|
+
d(this, "adapterInstance", null);
|
|
169
|
+
/** 并发 init 调用共享同一个 Promise,防止 SDK 被重复初始化。 */
|
|
170
|
+
d(this, "initPromise", null);
|
|
171
|
+
/** 覆盖物注册表:id → 记录 */
|
|
172
|
+
d(this, "overlays", /* @__PURE__ */ new Map());
|
|
173
|
+
/** 海量点图层注册表:与普通覆盖物分开管理,避免逐点创建 Overlay。 */
|
|
174
|
+
d(this, "massPointLayers", /* @__PURE__ */ new Map());
|
|
175
|
+
/** 呼吸点图层注册表。 */
|
|
176
|
+
d(this, "scatterLayers", /* @__PURE__ */ new Map());
|
|
177
|
+
/** 批量折线图层注册表。 */
|
|
178
|
+
d(this, "polylineLayers", /* @__PURE__ */ new Map());
|
|
179
|
+
/** 批量多边形图层注册表。 */
|
|
180
|
+
d(this, "polygonLayers", /* @__PURE__ */ new Map());
|
|
181
|
+
/** 全局地图点击监听器集合 */
|
|
182
|
+
d(this, "clickListeners", /* @__PURE__ */ new Set());
|
|
183
|
+
/** 全局绘制完成监听器集合 */
|
|
184
|
+
d(this, "drawListeners", /* @__PURE__ */ new Set());
|
|
185
|
+
/** 当前状态机状态 */
|
|
186
|
+
d(this, "state", "idle");
|
|
187
|
+
/** 覆盖物 id 自增种子 */
|
|
188
|
+
d(this, "idSeed", 0);
|
|
189
|
+
/** 地图点击事件的退订函数(init 成功后绑定,destroy 时解绑) */
|
|
190
|
+
d(this, "mapClickUnsubscribe", null);
|
|
191
|
+
/** 进行中绘制的取消回调(cancelDraw / destroy 触发,使挂起的 Promise resolve null) */
|
|
192
|
+
d(this, "pendingDrawResolve", null);
|
|
193
|
+
/** 当前手动开启的线段或多边形编辑会话 */
|
|
194
|
+
d(this, "activeEdit", null);
|
|
195
|
+
v(this), this.options = { ...e }, this.assertConstructorOptions();
|
|
196
|
+
}
|
|
197
|
+
/** 已完成加载的适配器;所有地图操作都必须在 ready 状态后调用。 */
|
|
198
|
+
get adapter() {
|
|
199
|
+
if (!this.adapterInstance)
|
|
200
|
+
throw new o("MAP_NOT_READY", "Call init() before using the map");
|
|
201
|
+
return this.adapterInstance;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* 初始化地图(幂等)
|
|
205
|
+
* - 已销毁:抛 MAP_DESTROYED
|
|
206
|
+
* - 已就绪或绘制中:直接返回,不重复初始化
|
|
207
|
+
* - 初始化失败:回退到 idle 状态并抛出 MapError
|
|
208
|
+
*/
|
|
209
|
+
init() {
|
|
210
|
+
if (this.state === "destroyed")
|
|
211
|
+
return Promise.reject(new o("MAP_DESTROYED", "Cannot initialize a destroyed map"));
|
|
212
|
+
if (this.state === "ready" || this.state.startsWith("drawing-"))
|
|
213
|
+
return Promise.resolve();
|
|
214
|
+
if (this.initPromise)
|
|
215
|
+
return this.initPromise;
|
|
216
|
+
this.state = "initializing";
|
|
217
|
+
const e = this.initialize();
|
|
218
|
+
return this.initPromise = e, e.finally(() => {
|
|
219
|
+
this.initPromise === e && (this.initPromise = null);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
async initialize() {
|
|
223
|
+
let e = null;
|
|
224
|
+
try {
|
|
225
|
+
if (e = await this.createAdapter(this.options.provider), this.isDestroyed())
|
|
226
|
+
throw e.destroy(), new o("MAP_DESTROYED", "Map destroyed during initialization");
|
|
227
|
+
if (this.adapterInstance = e, await e.init(this.options), this.isDestroyed())
|
|
228
|
+
throw e.destroy(), this.adapterInstance = null, new o("MAP_DESTROYED", "Map destroyed during initialization");
|
|
229
|
+
this.mapClickUnsubscribe = e.onMapClick((t, i) => {
|
|
230
|
+
i == null && this.emitMapClick({ ...t, overlay: null });
|
|
231
|
+
}), this.state = "ready";
|
|
232
|
+
} catch (t) {
|
|
233
|
+
throw e == null || e.destroy(), this.adapterInstance === e && (this.adapterInstance = null), this.state !== "destroyed" && (this.state = "idle"), t instanceof o ? t : new o("SDK_ERROR", "Failed to initialize map", { cause: t });
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* 销毁地图(幂等)
|
|
238
|
+
* 依次执行:取消进行中的绘制并结算挂起的 Promise →
|
|
239
|
+
* 解绑地图点击 → 清理全部覆盖物及其点击事件 → 清空监听器 → 销毁适配器
|
|
240
|
+
*/
|
|
241
|
+
destroy() {
|
|
242
|
+
var t, i, s;
|
|
243
|
+
if (this.state === "destroyed")
|
|
244
|
+
return;
|
|
245
|
+
this.activeEdit && this.stopEdit();
|
|
246
|
+
const e = this.adapterInstance;
|
|
247
|
+
(this.state === "drawing-polyline" || this.state === "drawing-polygon") && (e == null || e.cancelDraw(), (t = this.pendingDrawResolve) == null || t.call(this), this.pendingDrawResolve = null), this.state = "destroyed", (i = this.mapClickUnsubscribe) == null || i.call(this), this.mapClickUnsubscribe = null;
|
|
248
|
+
for (const r of this.overlays.values())
|
|
249
|
+
(s = r.globalClickUnsubscribe) == null || s.call(r), r.clickUnsubscribers.forEach((n) => n()), e == null || e.removeOverlay(r.native);
|
|
250
|
+
this.overlays.clear();
|
|
251
|
+
for (const r of this.massPointLayers.values())
|
|
252
|
+
e == null || e.removeMassPoints(r.native);
|
|
253
|
+
this.massPointLayers.clear();
|
|
254
|
+
for (const r of this.scatterLayers.values())
|
|
255
|
+
e == null || e.removeScatterLayer(r.native);
|
|
256
|
+
this.scatterLayers.clear();
|
|
257
|
+
for (const r of this.polylineLayers.values())
|
|
258
|
+
e == null || e.removePolylineLayer(r.native);
|
|
259
|
+
this.polylineLayers.clear();
|
|
260
|
+
for (const r of this.polygonLayers.values())
|
|
261
|
+
e == null || e.removePolygonLayer(r.native);
|
|
262
|
+
this.polygonLayers.clear(), this.clickListeners.clear(), this.drawListeners.clear(), e == null || e.destroy(), this.adapterInstance = null;
|
|
263
|
+
}
|
|
264
|
+
/** 设置地图中心点(坐标会先做合法性校验) */
|
|
265
|
+
setCenter(e) {
|
|
266
|
+
this.assertReady(), this.adapter.setCenter(w(e));
|
|
267
|
+
}
|
|
268
|
+
/** 获取地图中心点 */
|
|
269
|
+
getCenter() {
|
|
270
|
+
return this.assertReady(), this.adapter.getCenter();
|
|
271
|
+
}
|
|
272
|
+
/** 设置缩放级别(必须为非负有限数值) */
|
|
273
|
+
setZoom(e) {
|
|
274
|
+
if (this.assertReady(), !Number.isFinite(e) || e < 0)
|
|
275
|
+
throw new o("INVALID_OPTIONS", "zoom must be a non-negative number");
|
|
276
|
+
this.adapter.setZoom(e);
|
|
277
|
+
}
|
|
278
|
+
/** 获取当前缩放级别 */
|
|
279
|
+
getZoom() {
|
|
280
|
+
return this.assertReady(), this.adapter.getZoom();
|
|
281
|
+
}
|
|
282
|
+
/** 添加标记点:先标准化校验选项,再委托适配器创建并登记到覆盖物注册表 */
|
|
283
|
+
addMarker(e) {
|
|
284
|
+
this.assertReady();
|
|
285
|
+
const t = this.normalizeMarkerOptions(e), i = this.adapter.addMarker(t);
|
|
286
|
+
return this.registerOverlay("marker", t, i);
|
|
287
|
+
}
|
|
288
|
+
/** 添加折线覆盖物 */
|
|
289
|
+
addPolyline(e) {
|
|
290
|
+
this.assertReady();
|
|
291
|
+
const t = this.normalizePolylineOptions(e), i = this.adapter.addPolyline(t);
|
|
292
|
+
return this.registerOverlay("polyline", t, i);
|
|
293
|
+
}
|
|
294
|
+
/** 添加多边形覆盖物 */
|
|
295
|
+
addPolygon(e) {
|
|
296
|
+
this.assertReady();
|
|
297
|
+
const t = this.normalizePolygonOptions(e), i = this.adapter.addPolygon(t);
|
|
298
|
+
return this.registerOverlay("polygon", t, i);
|
|
299
|
+
}
|
|
300
|
+
/** 使用单一原生图层批量绘制折线,适合大量静态线要素。 */
|
|
301
|
+
addPolylineLayer(e) {
|
|
302
|
+
this.assertReady();
|
|
303
|
+
const t = this.normalizePolylineLayerOptions(e), i = t.id || this.nextId("polyline-layer");
|
|
304
|
+
if (this.hasLayerId(i))
|
|
305
|
+
throw new o("INVALID_OPTIONS", `Layer id already exists: ${i}`);
|
|
306
|
+
const s = this.adapter.addPolylineLayer(t), r = this.adapter.coordinateSystem, n = new b(this, i, r);
|
|
307
|
+
return this.polylineLayers.set(i, {
|
|
308
|
+
id: i,
|
|
309
|
+
coordinateSystem: r,
|
|
310
|
+
options: { ...t, id: i, coordinateSystem: r },
|
|
311
|
+
native: s,
|
|
312
|
+
handle: n
|
|
313
|
+
}), n;
|
|
314
|
+
}
|
|
315
|
+
updatePolylineLayer(e, t) {
|
|
316
|
+
this.assertReadyOrDrawing();
|
|
317
|
+
const i = this.getPolylineLayerRecord(e), s = this.normalizePolylineLayerOptions({
|
|
318
|
+
...i.options,
|
|
319
|
+
...t,
|
|
320
|
+
style: t.style ? { ...i.options.style, ...t.style } : i.options.style
|
|
321
|
+
});
|
|
322
|
+
i.native = this.adapter.updatePolylineLayer(i.native, s, t), i.options = { ...s, id: e, coordinateSystem: i.coordinateSystem };
|
|
323
|
+
}
|
|
324
|
+
removePolylineLayer(e) {
|
|
325
|
+
this.assertReadyOrDrawing();
|
|
326
|
+
const t = typeof e == "string" ? e : e.id, i = this.polylineLayers.get(t);
|
|
327
|
+
return i ? (this.adapter.removePolylineLayer(i.native), this.polylineLayers.delete(t), !0) : !1;
|
|
328
|
+
}
|
|
329
|
+
clearPolylineLayers() {
|
|
330
|
+
this.assertReadyOrDrawing();
|
|
331
|
+
for (const e of [...this.polylineLayers.keys()])
|
|
332
|
+
this.removePolylineLayer(e);
|
|
333
|
+
}
|
|
334
|
+
/** 使用单一原生图层批量绘制多边形,适合大量静态面要素。 */
|
|
335
|
+
addPolygonLayer(e) {
|
|
336
|
+
this.assertReady();
|
|
337
|
+
const t = this.normalizePolygonLayerOptions(e), i = t.id || this.nextId("polygon-layer");
|
|
338
|
+
if (this.hasLayerId(i))
|
|
339
|
+
throw new o("INVALID_OPTIONS", `Layer id already exists: ${i}`);
|
|
340
|
+
const s = this.adapter.addPolygonLayer(t), r = this.adapter.coordinateSystem, n = new S(this, i, r);
|
|
341
|
+
return this.polygonLayers.set(i, {
|
|
342
|
+
id: i,
|
|
343
|
+
coordinateSystem: r,
|
|
344
|
+
options: { ...t, id: i, coordinateSystem: r },
|
|
345
|
+
native: s,
|
|
346
|
+
handle: n
|
|
347
|
+
}), n;
|
|
348
|
+
}
|
|
349
|
+
updatePolygonLayer(e, t) {
|
|
350
|
+
this.assertReadyOrDrawing();
|
|
351
|
+
const i = this.getPolygonLayerRecord(e), s = this.normalizePolygonLayerOptions({
|
|
352
|
+
...i.options,
|
|
353
|
+
...t,
|
|
354
|
+
style: t.style ? { ...i.options.style, ...t.style } : i.options.style
|
|
355
|
+
});
|
|
356
|
+
i.native = this.adapter.updatePolygonLayer(i.native, s, t), i.options = { ...s, id: e, coordinateSystem: i.coordinateSystem };
|
|
357
|
+
}
|
|
358
|
+
removePolygonLayer(e) {
|
|
359
|
+
this.assertReadyOrDrawing();
|
|
360
|
+
const t = typeof e == "string" ? e : e.id, i = this.polygonLayers.get(t);
|
|
361
|
+
return i ? (this.adapter.removePolygonLayer(i.native), this.polygonLayers.delete(t), !0) : !1;
|
|
362
|
+
}
|
|
363
|
+
clearPolygonLayers() {
|
|
364
|
+
this.assertReadyOrDrawing();
|
|
365
|
+
for (const e of [...this.polygonLayers.keys()])
|
|
366
|
+
this.removePolygonLayer(e);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* 添加海量点图层。高德由 Loca PointLayer、百度由 MapVGL PointLayer、
|
|
370
|
+
* ArcGIS 由客户端 FeatureLayer 渲染。
|
|
371
|
+
* 点数据作为单一图层批量提交,不会创建成千上万个 Marker。
|
|
372
|
+
*/
|
|
373
|
+
addMassPoints(e) {
|
|
374
|
+
this.assertReady();
|
|
375
|
+
const t = this.normalizeMassPointLayerOptions(e), i = t.id || this.nextId("mass-points");
|
|
376
|
+
if (this.hasLayerId(i))
|
|
377
|
+
throw new o("INVALID_OPTIONS", `Layer id already exists: ${i}`);
|
|
378
|
+
const s = this.adapter.addMassPoints(t), r = this.adapter.coordinateSystem, n = new f(this, i, r);
|
|
379
|
+
return this.massPointLayers.set(i, {
|
|
380
|
+
id: i,
|
|
381
|
+
coordinateSystem: r,
|
|
382
|
+
options: { ...t, id: i, coordinateSystem: r },
|
|
383
|
+
native: s,
|
|
384
|
+
handle: n
|
|
385
|
+
}), n;
|
|
386
|
+
}
|
|
387
|
+
/** 更新海量点数据或样式。 */
|
|
388
|
+
updateMassPointLayer(e, t) {
|
|
389
|
+
this.assertReadyOrDrawing();
|
|
390
|
+
const i = this.getMassPointLayerRecord(e), s = {
|
|
391
|
+
...i.options,
|
|
392
|
+
...t,
|
|
393
|
+
style: t.style ? { ...i.options.style, ...t.style } : i.options.style
|
|
394
|
+
}, r = this.normalizeMassPointLayerOptions(s);
|
|
395
|
+
i.native = this.adapter.updateMassPoints(i.native, r, t), i.options = { ...r, id: e, coordinateSystem: i.coordinateSystem };
|
|
396
|
+
}
|
|
397
|
+
/** 删除海量点图层;不存在时返回 false。 */
|
|
398
|
+
removeMassPointLayer(e) {
|
|
399
|
+
this.assertReadyOrDrawing();
|
|
400
|
+
const t = typeof e == "string" ? e : e.id, i = this.massPointLayers.get(t);
|
|
401
|
+
return i ? (this.adapter.removeMassPoints(i.native), this.massPointLayers.delete(t), !0) : !1;
|
|
402
|
+
}
|
|
403
|
+
/** 清空全部海量点图层。 */
|
|
404
|
+
clearMassPointLayers() {
|
|
405
|
+
this.assertReadyOrDrawing();
|
|
406
|
+
for (const e of [...this.massPointLayers.keys()])
|
|
407
|
+
this.removeMassPointLayer(e);
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* 添加呼吸点图层。高德使用 Loca ScatterLayer,百度使用 MapVGL IconLayer
|
|
411
|
+
* 播放序列帧,ArcGIS 使用带动画 PNG 的 CIMPictureMarker FeatureLayer。
|
|
412
|
+
*/
|
|
413
|
+
addScatterLayer(e) {
|
|
414
|
+
this.assertReady();
|
|
415
|
+
const t = this.normalizeScatterLayerOptions(e), i = t.id || this.nextId("scatter");
|
|
416
|
+
if (this.hasLayerId(i))
|
|
417
|
+
throw new o("INVALID_OPTIONS", `Layer id already exists: ${i}`);
|
|
418
|
+
const s = this.adapter.addScatterLayer(t), r = this.adapter.coordinateSystem, n = new P(this, i, r);
|
|
419
|
+
return this.scatterLayers.set(i, {
|
|
420
|
+
id: i,
|
|
421
|
+
coordinateSystem: r,
|
|
422
|
+
options: { ...t, id: i, coordinateSystem: r },
|
|
423
|
+
native: s,
|
|
424
|
+
handle: n
|
|
425
|
+
}), n;
|
|
426
|
+
}
|
|
427
|
+
/** 更新呼吸点数据、动画或图层样式。 */
|
|
428
|
+
updateScatterLayer(e, t) {
|
|
429
|
+
this.assertReadyOrDrawing();
|
|
430
|
+
const i = this.getScatterLayerRecord(e), s = {
|
|
431
|
+
...i.options,
|
|
432
|
+
...t,
|
|
433
|
+
style: t.style ? { ...i.options.style, ...t.style } : i.options.style
|
|
434
|
+
}, r = this.normalizeScatterLayerOptions(s);
|
|
435
|
+
i.native = this.adapter.updateScatterLayer(i.native, r, t), i.options = { ...r, id: e, coordinateSystem: i.coordinateSystem };
|
|
436
|
+
}
|
|
437
|
+
/** 删除呼吸点图层;不存在时返回 false。 */
|
|
438
|
+
removeScatterLayer(e) {
|
|
439
|
+
this.assertReadyOrDrawing();
|
|
440
|
+
const t = typeof e == "string" ? e : e.id, i = this.scatterLayers.get(t);
|
|
441
|
+
return i ? (this.adapter.removeScatterLayer(i.native), this.scatterLayers.delete(t), !0) : !1;
|
|
442
|
+
}
|
|
443
|
+
/** 清空全部呼吸点图层。 */
|
|
444
|
+
clearScatterLayers() {
|
|
445
|
+
this.assertReadyOrDrawing();
|
|
446
|
+
for (const e of [...this.scatterLayers.keys()])
|
|
447
|
+
this.removeScatterLayer(e);
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* 进入折线交互绘制模式
|
|
451
|
+
* @returns 绘制完成后 resolve 覆盖物句柄;被取消或异常时 resolve null
|
|
452
|
+
*/
|
|
453
|
+
drawPolyline(e = {}) {
|
|
454
|
+
return this.startDrawing("polyline", e);
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* 进入多边形交互绘制模式
|
|
458
|
+
* @returns 绘制完成后 resolve 覆盖物句柄;被取消或异常时 resolve null
|
|
459
|
+
*/
|
|
460
|
+
drawPolygon(e = {}) {
|
|
461
|
+
return this.startDrawing("polygon", e);
|
|
462
|
+
}
|
|
463
|
+
/** 取消当前进行中的交互绘制;未处于绘制状态时为空操作 */
|
|
464
|
+
cancelDraw() {
|
|
465
|
+
this.assertReadyOrDrawing(), (this.state === "drawing-polyline" || this.state === "drawing-polygon") && this.adapter.cancelDraw();
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* 手动开启多边形编辑。
|
|
469
|
+
* 高德使用 PolygonEditor,百度使用覆盖物编辑,ArcGIS 使用 SketchViewModel。
|
|
470
|
+
*/
|
|
471
|
+
editPolygon(e) {
|
|
472
|
+
return this.startEditingOverlay(e, "polygon");
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* 手动开启线段编辑。
|
|
476
|
+
* 高德使用 PolylineEditor,百度使用覆盖物编辑,ArcGIS 使用 SketchViewModel。
|
|
477
|
+
*/
|
|
478
|
+
editPolyline(e) {
|
|
479
|
+
return this.startEditingOverlay(e, "polyline");
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* 手动开启覆盖物编辑;支持 polyline 和 polygon。
|
|
483
|
+
*/
|
|
484
|
+
editOverlay(e) {
|
|
485
|
+
return this.startEditingOverlay(e);
|
|
486
|
+
}
|
|
487
|
+
/** 校验覆盖物类型并开启底层编辑会话。 */
|
|
488
|
+
startEditingOverlay(e, t) {
|
|
489
|
+
if (this.assertReadyOrDrawing(), this.state === "drawing-polyline" || this.state === "drawing-polygon")
|
|
490
|
+
throw new o("DRAW_IN_PROGRESS", "Cannot edit an overlay while drawing");
|
|
491
|
+
const i = typeof e == "string" ? e : e.id, s = this.getRecord(i);
|
|
492
|
+
if (t && s.kind !== t)
|
|
493
|
+
throw new o("INVALID_OPTIONS", `Only ${t} overlays can be edited by this method`);
|
|
494
|
+
if (s.kind !== "polyline" && s.kind !== "polygon")
|
|
495
|
+
throw new o("INVALID_OPTIONS", "Only polyline and polygon overlays can be edited");
|
|
496
|
+
this.stopEdit();
|
|
497
|
+
const r = s.kind, n = r === "polyline" ? 2 : 3, l = this.adapter.startEdit(s.native, r, (h) => {
|
|
498
|
+
if (!this.overlays.has(i) || h.length < n)
|
|
499
|
+
return;
|
|
500
|
+
const y = p(h, n);
|
|
501
|
+
s.options = r === "polyline" ? { ...s.options, path: y } : { ...s.options, path: y };
|
|
502
|
+
});
|
|
503
|
+
return this.activeEdit = { id: i, stop: l }, () => {
|
|
504
|
+
var h;
|
|
505
|
+
((h = this.activeEdit) == null ? void 0 : h.id) === i && this.activeEdit.stop === l && this.stopEdit();
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
/** 结束当前图形编辑并把 SDK 中的最终路径同步回统一覆盖物实例。 */
|
|
509
|
+
stopEdit() {
|
|
510
|
+
this.assertReadyOrDrawing();
|
|
511
|
+
const e = this.activeEdit;
|
|
512
|
+
if (!e)
|
|
513
|
+
return;
|
|
514
|
+
this.activeEdit = null, e.stop();
|
|
515
|
+
const t = this.overlays.get(e.id);
|
|
516
|
+
t && (t.options = this.syncOverlayGeometry(t));
|
|
517
|
+
}
|
|
518
|
+
/** 删除覆盖物(支持传入句柄或 id),不存在时返回 false */
|
|
519
|
+
removeOverlay(e) {
|
|
520
|
+
var s, r;
|
|
521
|
+
this.assertReadyOrDrawing();
|
|
522
|
+
const t = typeof e == "string" ? e : e.id, i = this.overlays.get(t);
|
|
523
|
+
return i ? (((s = this.activeEdit) == null ? void 0 : s.id) === t && this.stopEdit(), (r = i.globalClickUnsubscribe) == null || r.call(i), i.clickUnsubscribers.forEach((n) => n()), this.adapter.removeOverlay(i.native), this.overlays.delete(t), !0) : !1;
|
|
524
|
+
}
|
|
525
|
+
/** 批量删除覆盖物;可按类型过滤(marker/polyline/polygon),不传 kind 则删除全部 */
|
|
526
|
+
clearOverlays(e) {
|
|
527
|
+
this.assertReadyOrDrawing(), [...this.overlays.values()].filter((i) => !e || i.kind === e).map((i) => i.id).forEach((i) => this.removeOverlay(i));
|
|
528
|
+
}
|
|
529
|
+
on(e, t) {
|
|
530
|
+
if (this.assertReadyOrDrawing(), e === "click") {
|
|
531
|
+
const s = t;
|
|
532
|
+
return this.clickListeners.add(s), () => this.clickListeners.delete(s);
|
|
533
|
+
}
|
|
534
|
+
const i = t;
|
|
535
|
+
return this.drawListeners.add(i), () => this.drawListeners.delete(i);
|
|
536
|
+
}
|
|
537
|
+
off(e, t) {
|
|
538
|
+
e === "click" ? this.clickListeners.delete(t) : this.drawListeners.delete(t);
|
|
539
|
+
}
|
|
540
|
+
/** 获取覆盖物路径;marker 返回 null,id 不存在时抛 OVERLAY_NOT_FOUND */
|
|
541
|
+
getOverlayPath(e) {
|
|
542
|
+
return this.getRecord(e).kind === "marker" ? null : this.adapter.getPath(this.getRecord(e).native);
|
|
543
|
+
}
|
|
544
|
+
/** 获取覆盖物锚点位置 */
|
|
545
|
+
getOverlayPosition(e) {
|
|
546
|
+
return this.adapter.getPosition(this.getRecord(e).native);
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* 为指定覆盖物绑定点击事件(由 OverlayHandleImpl 调用)
|
|
550
|
+
* 注意:同一覆盖物上重复绑定同一回调会覆盖先前的退订记录
|
|
551
|
+
* @returns 退订函数
|
|
552
|
+
*/
|
|
553
|
+
onOverlayClick(e, t) {
|
|
554
|
+
const i = this.getRecord(e), s = this.bindOverlayClick(i, i.native, t);
|
|
555
|
+
return i.clickUnsubscribers.set(t, s), () => {
|
|
556
|
+
s(), i.clickUnsubscribers.delete(t);
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* 更新覆盖物配置
|
|
561
|
+
* 流程:合并新旧配置 → 按类型重新标准化校验 → 委托适配器更新 →
|
|
562
|
+
* 重新绑定所有已有的点击回调(适配器更新后原生对象可能被替换)
|
|
563
|
+
*/
|
|
564
|
+
updateOverlay(e, t) {
|
|
565
|
+
var u;
|
|
566
|
+
const i = this.getRecord(e), s = this.syncOverlayGeometry(i), r = this.mergeOptions(s, t), n = i.kind === "marker" ? this.normalizeMarkerOptions(r) : i.kind === "polyline" ? this.normalizePolylineOptions(r) : this.normalizePolygonOptions(r), l = i.native, h = this.adapter.updateOverlay(l, n, t), y = [...i.clickUnsubscribers.keys()];
|
|
567
|
+
(u = i.globalClickUnsubscribe) == null || u.call(i), i.clickUnsubscribers.forEach((c) => c()), i.clickUnsubscribers.clear(), i.native = h, i.options = n, i.globalClickUnsubscribe = this.bindGlobalOverlayClick(i, h);
|
|
568
|
+
for (const c of y)
|
|
569
|
+
i.clickUnsubscribers.set(c, this.bindOverlayClick(i, h, c));
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* 交互绘制核心实现
|
|
573
|
+
* 状态流转:ready → drawing-polyline/polygon → 绘制完成或取消后回到 ready
|
|
574
|
+
* - assertReadyOrDrawing 放行绘制中状态,由下方精确抛出 DRAW_IN_PROGRESS
|
|
575
|
+
* (避免 assertReady 把重复绘制误报为 MAP_NOT_READY)
|
|
576
|
+
* - 通过 settled 标志保证"完成回调"与"取消回调"只有先到者生效
|
|
577
|
+
* - 绘制完成后:标准化路径(折线至少 2 点 / 多边形至少 3 点)→
|
|
578
|
+
* 注册覆盖物 → 派发 draw 事件 → resolve 句柄
|
|
579
|
+
* - 注册异常时移除已生成的原生覆盖物并 resolve null(不 reject)
|
|
580
|
+
*/
|
|
581
|
+
startDrawing(e, t) {
|
|
582
|
+
if (this.assertReadyOrDrawing(), this.state === "drawing-polyline" || this.state === "drawing-polygon")
|
|
583
|
+
throw new o("DRAW_IN_PROGRESS", "A drawing operation is already active");
|
|
584
|
+
return this.stopEdit(), this.state = e === "polyline" ? "drawing-polyline" : "drawing-polygon", new Promise((i, s) => {
|
|
585
|
+
let r = !1;
|
|
586
|
+
const n = () => {
|
|
587
|
+
r || (r = !0, this.state = "ready", this.pendingDrawResolve = null, i(null));
|
|
588
|
+
};
|
|
589
|
+
this.pendingDrawResolve = n;
|
|
590
|
+
try {
|
|
591
|
+
this.adapter.startDraw(
|
|
592
|
+
e,
|
|
593
|
+
t,
|
|
594
|
+
(l, h) => {
|
|
595
|
+
if (!r) {
|
|
596
|
+
r = !0, this.pendingDrawResolve = null;
|
|
597
|
+
try {
|
|
598
|
+
const y = p(h, e === "polyline" ? 2 : 3), u = e === "polyline" ? { ...t, path: y, coordinateSystem: this.adapter.coordinateSystem } : { ...t, path: y, coordinateSystem: this.adapter.coordinateSystem }, c = this.registerOverlay(e, u, l);
|
|
599
|
+
this.state = "ready", this.emitDraw({ kind: e, overlay: c }), i(c);
|
|
600
|
+
} catch {
|
|
601
|
+
this.adapter.removeOverlay(l), this.state = "ready", i(null);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
},
|
|
605
|
+
n
|
|
606
|
+
);
|
|
607
|
+
} catch (l) {
|
|
608
|
+
r = !0, this.pendingDrawResolve = null, this.state = "ready", s(l);
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* 登记覆盖物到注册表
|
|
614
|
+
* id 优先使用调用方指定的,否则按类型自增生成;重复 id 视为配置错误抛异常
|
|
615
|
+
*/
|
|
616
|
+
registerOverlay(e, t, i) {
|
|
617
|
+
const s = t.id || this.nextId(e);
|
|
618
|
+
if (this.hasLayerId(s))
|
|
619
|
+
throw new o("INVALID_OPTIONS", `Layer id already exists: ${s}`);
|
|
620
|
+
const r = this.adapter.coordinateSystem, n = new I(this, s, e, r), l = {
|
|
621
|
+
id: s,
|
|
622
|
+
kind: e,
|
|
623
|
+
coordinateSystem: r,
|
|
624
|
+
options: { ...t, id: s, coordinateSystem: r },
|
|
625
|
+
native: i,
|
|
626
|
+
handle: n,
|
|
627
|
+
clickUnsubscribers: /* @__PURE__ */ new Map(),
|
|
628
|
+
globalClickUnsubscribe: null
|
|
629
|
+
};
|
|
630
|
+
return this.overlays.set(s, l), l.globalClickUnsubscribe = this.bindGlobalOverlayClick(l, i), n;
|
|
631
|
+
}
|
|
632
|
+
/** 将适配器点击事件补充为包含统一覆盖物实例的公开事件。 */
|
|
633
|
+
bindOverlayClick(e, t, i) {
|
|
634
|
+
return this.adapter.onOverlayClick(t, (s) => {
|
|
635
|
+
i({ ...s, overlay: e.handle });
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* 覆盖物点击 → 全局 click 事件的桥接监听
|
|
640
|
+
* 闭包直接持有 record/handle,规避跨 SDK 的原生对象引用匹配问题;
|
|
641
|
+
* 命中覆盖物时全局 click 只由此派发,onMapClick 里对命中情况做了跳过
|
|
642
|
+
*/
|
|
643
|
+
bindGlobalOverlayClick(e, t) {
|
|
644
|
+
return this.adapter.onOverlayClick(t, (i) => {
|
|
645
|
+
this.emitMapClick({ ...i, overlay: e.handle });
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
/** 将 SDK 原生对象中可能被编辑过的实时坐标同步到覆盖物记录。 */
|
|
649
|
+
syncOverlayGeometry(e) {
|
|
650
|
+
if (e.kind === "marker") {
|
|
651
|
+
const i = this.adapter.getPosition(e.native);
|
|
652
|
+
return i ? { ...e.options, position: i } : e.options;
|
|
653
|
+
}
|
|
654
|
+
const t = this.adapter.getPath(e.native);
|
|
655
|
+
return t ? e.kind === "polyline" ? { ...e.options, path: t } : { ...e.options, path: t } : e.options;
|
|
656
|
+
}
|
|
657
|
+
/** 标准化标记点配置:校验坐标、坐标系匹配与样式参数 */
|
|
658
|
+
normalizeMarkerOptions(e) {
|
|
659
|
+
const t = w(e.position, "marker.position"), i = m(e.coordinateSystem, this.options.provider);
|
|
660
|
+
return this.validateMarkerStyle(e.style), { ...e, position: t, coordinateSystem: i };
|
|
661
|
+
}
|
|
662
|
+
/** 标准化折线配置:路径至少需要 2 个有效点 */
|
|
663
|
+
normalizePolylineOptions(e) {
|
|
664
|
+
const t = p(e.path, 2), i = m(e.coordinateSystem, this.options.provider);
|
|
665
|
+
return this.validateLineStyle(e), { ...e, path: t, coordinateSystem: i };
|
|
666
|
+
}
|
|
667
|
+
/** 标准化多边形配置:路径至少需要 3 个有效点,fillOpacity 限定 0~1 */
|
|
668
|
+
normalizePolygonOptions(e) {
|
|
669
|
+
const t = p(e.path, 3), i = m(e.coordinateSystem, this.options.provider);
|
|
670
|
+
if (this.validateLineStyle(e), e.fillOpacity !== void 0 && (e.fillOpacity < 0 || e.fillOpacity > 1))
|
|
671
|
+
throw new o("INVALID_OPTIONS", "fillOpacity must be between 0 and 1");
|
|
672
|
+
return { ...e, path: t, coordinateSystem: i };
|
|
673
|
+
}
|
|
674
|
+
/** 标准化海量点图层数据和样式参数。 */
|
|
675
|
+
normalizeMassPointLayerOptions(e) {
|
|
676
|
+
if (!Array.isArray(e.points))
|
|
677
|
+
throw new o("INVALID_OPTIONS", "mass points must be an array");
|
|
678
|
+
const t = e.points.map((r, n) => ({
|
|
679
|
+
...r,
|
|
680
|
+
position: w(r.position, `massPoints[${n}].position`),
|
|
681
|
+
properties: r.properties ? { ...r.properties } : void 0
|
|
682
|
+
})), i = m(e.coordinateSystem, this.options.provider), s = e.style;
|
|
683
|
+
if ((s == null ? void 0 : s.size) !== void 0 && (!Number.isFinite(s.size) || s.size <= 0))
|
|
684
|
+
throw new o("INVALID_OPTIONS", "mass point size must be greater than 0");
|
|
685
|
+
if ((s == null ? void 0 : s.opacity) !== void 0 && (s.opacity < 0 || s.opacity > 1))
|
|
686
|
+
throw new o("INVALID_OPTIONS", "mass point opacity must be between 0 and 1");
|
|
687
|
+
if ((s == null ? void 0 : s.borderWidth) !== void 0 && (!Number.isFinite(s.borderWidth) || s.borderWidth < 0))
|
|
688
|
+
throw new o("INVALID_OPTIONS", "mass point borderWidth must be non-negative");
|
|
689
|
+
if (e.zIndex !== void 0 && !Number.isFinite(e.zIndex))
|
|
690
|
+
throw new o("INVALID_OPTIONS", "mass point zIndex must be finite");
|
|
691
|
+
if (e.minZoom !== void 0 && (!Number.isFinite(e.minZoom) || e.minZoom < 0))
|
|
692
|
+
throw new o("INVALID_OPTIONS", "mass point minZoom must be a non-negative number");
|
|
693
|
+
if (e.maxZoom !== void 0 && (!Number.isFinite(e.maxZoom) || e.maxZoom < 0))
|
|
694
|
+
throw new o("INVALID_OPTIONS", "mass point maxZoom must be a non-negative number");
|
|
695
|
+
if (e.minZoom !== void 0 && e.maxZoom !== void 0 && e.minZoom > e.maxZoom)
|
|
696
|
+
throw new o("INVALID_OPTIONS", "mass point minZoom cannot exceed maxZoom");
|
|
697
|
+
return { ...e, points: t, style: s ? { ...s } : void 0, coordinateSystem: i };
|
|
698
|
+
}
|
|
699
|
+
normalizePolylineLayerOptions(e) {
|
|
700
|
+
if (!Array.isArray(e.polylines))
|
|
701
|
+
throw new o("INVALID_OPTIONS", "polylines must be an array");
|
|
702
|
+
const t = e.polylines.map((s) => ({
|
|
703
|
+
...s,
|
|
704
|
+
path: p(s.path, 2),
|
|
705
|
+
properties: s.properties ? { ...s.properties } : void 0
|
|
706
|
+
})), i = m(e.coordinateSystem, this.options.provider);
|
|
707
|
+
return this.validateLineStyle(e.style || {}), this.validateBatchVectorLayerRange(e, "polyline layer"), { ...e, polylines: t, style: e.style ? { ...e.style } : void 0, coordinateSystem: i };
|
|
708
|
+
}
|
|
709
|
+
normalizePolygonLayerOptions(e) {
|
|
710
|
+
if (!Array.isArray(e.polygons))
|
|
711
|
+
throw new o("INVALID_OPTIONS", "polygons must be an array");
|
|
712
|
+
const t = e.polygons.map((r) => ({
|
|
713
|
+
...r,
|
|
714
|
+
path: p(r.path, 3),
|
|
715
|
+
properties: r.properties ? { ...r.properties } : void 0
|
|
716
|
+
})), i = m(e.coordinateSystem, this.options.provider), s = e.style || {};
|
|
717
|
+
if (this.validateLineStyle(s), s.fillOpacity !== void 0 && (s.fillOpacity < 0 || s.fillOpacity > 1))
|
|
718
|
+
throw new o("INVALID_OPTIONS", "polygon layer fillOpacity must be between 0 and 1");
|
|
719
|
+
return this.validateBatchVectorLayerRange(e, "polygon layer"), { ...e, polygons: t, style: e.style ? { ...e.style } : void 0, coordinateSystem: i };
|
|
720
|
+
}
|
|
721
|
+
validateBatchVectorLayerRange(e, t) {
|
|
722
|
+
if (e.zIndex !== void 0 && !Number.isFinite(e.zIndex))
|
|
723
|
+
throw new o("INVALID_OPTIONS", `${t} zIndex must be finite`);
|
|
724
|
+
if (e.minZoom !== void 0 && (!Number.isFinite(e.minZoom) || e.minZoom < 0))
|
|
725
|
+
throw new o("INVALID_OPTIONS", `${t} minZoom must be a non-negative number`);
|
|
726
|
+
if (e.maxZoom !== void 0 && (!Number.isFinite(e.maxZoom) || e.maxZoom < 0))
|
|
727
|
+
throw new o("INVALID_OPTIONS", `${t} maxZoom must be a non-negative number`);
|
|
728
|
+
if (e.minZoom !== void 0 && e.maxZoom !== void 0 && e.minZoom > e.maxZoom)
|
|
729
|
+
throw new o("INVALID_OPTIONS", `${t} minZoom cannot exceed maxZoom`);
|
|
730
|
+
}
|
|
731
|
+
/** 标准化呼吸点图层数据、样式和动画参数。 */
|
|
732
|
+
normalizeScatterLayerOptions(e) {
|
|
733
|
+
if (!Array.isArray(e.points))
|
|
734
|
+
throw new o("INVALID_OPTIONS", "scatter points must be an array");
|
|
735
|
+
const t = e.points.map((r, n) => ({
|
|
736
|
+
...r,
|
|
737
|
+
position: w(r.position, `scatterPoints[${n}].position`),
|
|
738
|
+
properties: r.properties ? { ...r.properties } : void 0
|
|
739
|
+
})), i = m(e.coordinateSystem, this.options.provider), s = e.style;
|
|
740
|
+
if ((s == null ? void 0 : s.size) !== void 0 && (!Number.isFinite(s.size) || s.size <= 0))
|
|
741
|
+
throw new o("INVALID_OPTIONS", "scatter size must be greater than 0");
|
|
742
|
+
if ((s == null ? void 0 : s.opacity) !== void 0 && (s.opacity < 0 || s.opacity > 1))
|
|
743
|
+
throw new o("INVALID_OPTIONS", "scatter opacity must be between 0 and 1");
|
|
744
|
+
if ((s == null ? void 0 : s.borderWidth) !== void 0 && (!Number.isFinite(s.borderWidth) || s.borderWidth < 0))
|
|
745
|
+
throw new o("INVALID_OPTIONS", "scatter borderWidth must be non-negative");
|
|
746
|
+
if ((s == null ? void 0 : s.duration) !== void 0 && (!Number.isFinite(s.duration) || s.duration <= 0))
|
|
747
|
+
throw new o("INVALID_OPTIONS", "scatter duration must be greater than 0");
|
|
748
|
+
if ((s == null ? void 0 : s.repeatDelay) !== void 0 && (!Number.isFinite(s.repeatDelay) || s.repeatDelay < 0))
|
|
749
|
+
throw new o("INVALID_OPTIONS", "scatter repeatDelay must be non-negative");
|
|
750
|
+
if (e.zIndex !== void 0 && !Number.isFinite(e.zIndex))
|
|
751
|
+
throw new o("INVALID_OPTIONS", "scatter zIndex must be finite");
|
|
752
|
+
if (e.minZoom !== void 0 && (!Number.isFinite(e.minZoom) || e.minZoom < 0))
|
|
753
|
+
throw new o("INVALID_OPTIONS", "scatter minZoom must be a non-negative number");
|
|
754
|
+
if (e.maxZoom !== void 0 && (!Number.isFinite(e.maxZoom) || e.maxZoom < 0))
|
|
755
|
+
throw new o("INVALID_OPTIONS", "scatter maxZoom must be a non-negative number");
|
|
756
|
+
if (e.minZoom !== void 0 && e.maxZoom !== void 0 && e.minZoom > e.maxZoom)
|
|
757
|
+
throw new o("INVALID_OPTIONS", "scatter minZoom cannot exceed maxZoom");
|
|
758
|
+
return { ...e, points: t, style: s ? { ...s } : void 0, coordinateSystem: i };
|
|
759
|
+
}
|
|
760
|
+
/** 校验标记样式:circle 模式校验半径/透明度/描边宽度;icon 模式校验宽高 */
|
|
761
|
+
validateMarkerStyle(e) {
|
|
762
|
+
if (e) {
|
|
763
|
+
if (e.kind === "circle") {
|
|
764
|
+
if (e.radius !== void 0 && e.radius <= 0)
|
|
765
|
+
throw new o("INVALID_OPTIONS", "marker radius must be greater than 0");
|
|
766
|
+
if (e.fillOpacity !== void 0 && (e.fillOpacity < 0 || e.fillOpacity > 1))
|
|
767
|
+
throw new o("INVALID_OPTIONS", "fillOpacity must be between 0 and 1");
|
|
768
|
+
if (e.strokeWeight !== void 0 && e.strokeWeight <= 0)
|
|
769
|
+
throw new o("INVALID_OPTIONS", "strokeWeight must be greater than 0");
|
|
770
|
+
} else if (e.width <= 0 || e.height <= 0)
|
|
771
|
+
throw new o("INVALID_OPTIONS", "icon width and height must be greater than 0");
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
/** 校验线样式:描边宽度必须大于 0,透明度必须在 0~1 之间 */
|
|
775
|
+
validateLineStyle(e) {
|
|
776
|
+
if (e.strokeWeight !== void 0 && e.strokeWeight <= 0)
|
|
777
|
+
throw new o("INVALID_OPTIONS", "strokeWeight must be greater than 0");
|
|
778
|
+
if (e.strokeOpacity !== void 0 && (e.strokeOpacity < 0 || e.strokeOpacity > 1))
|
|
779
|
+
throw new o("INVALID_OPTIONS", "strokeOpacity must be between 0 and 1");
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* 合并覆盖物新旧配置
|
|
783
|
+
* style 为嵌套对象,需单独浅合并,避免整体替换丢失未更新的样式字段
|
|
784
|
+
*/
|
|
785
|
+
mergeOptions(e, t) {
|
|
786
|
+
const i = { ...e, ...t };
|
|
787
|
+
return ("style" in e || "style" in t) && (i.style = { ...e.style, ...t.style }), i;
|
|
788
|
+
}
|
|
789
|
+
/** 按 provider 动态加载对应 SDK 适配器。 */
|
|
790
|
+
async createAdapter(e) {
|
|
791
|
+
if (e === "amap") {
|
|
792
|
+
const { AMapAdapter: i } = await import("./AMapAdapter-6257126f.js");
|
|
793
|
+
return new i();
|
|
794
|
+
}
|
|
795
|
+
if (e === "baidu") {
|
|
796
|
+
const { BMapAdapter: i } = await import("./BMapAdapter-eb942a66.js");
|
|
797
|
+
return new i();
|
|
798
|
+
}
|
|
799
|
+
const { ArcGISAdapter: t } = await import("./ArcGISAdapter-09b4e73f.js");
|
|
800
|
+
return new t();
|
|
801
|
+
}
|
|
802
|
+
isDestroyed() {
|
|
803
|
+
return this.state === "destroyed";
|
|
804
|
+
}
|
|
805
|
+
/** 构造参数校验:provider 必须受支持,center / zoom 必须合法 */
|
|
806
|
+
assertConstructorOptions() {
|
|
807
|
+
if (this.options.provider !== "amap" && this.options.provider !== "arcgis" && this.options.provider !== "baidu")
|
|
808
|
+
throw new o("INVALID_OPTIONS", `Unsupported provider: ${this.options.provider}`);
|
|
809
|
+
if (this.options.center && w(this.options.center, "center"), this.options.zoom !== void 0 && (!Number.isFinite(this.options.zoom) || this.options.zoom < 0))
|
|
810
|
+
throw new o("INVALID_OPTIONS", "zoom must be a non-negative number");
|
|
811
|
+
}
|
|
812
|
+
/** 断言地图处于 ready 状态:destroyed 报销毁错误,其余非 ready 报未初始化 */
|
|
813
|
+
assertReady() {
|
|
814
|
+
if (this.state === "destroyed")
|
|
815
|
+
throw new o("MAP_DESTROYED", "Map has been destroyed");
|
|
816
|
+
if (this.state !== "ready")
|
|
817
|
+
throw new o("MAP_NOT_READY", "Call init() before using the map");
|
|
818
|
+
}
|
|
819
|
+
/** 断言地图处于 ready 或绘制中状态(供绘制期间仍需使用的操作调用,如 removeOverlay / on) */
|
|
820
|
+
assertReadyOrDrawing() {
|
|
821
|
+
if (this.state === "destroyed")
|
|
822
|
+
throw new o("MAP_DESTROYED", "Map has been destroyed");
|
|
823
|
+
if (this.state !== "ready" && this.state !== "drawing-polyline" && this.state !== "drawing-polygon")
|
|
824
|
+
throw new o("MAP_NOT_READY", "Call init() before using the map");
|
|
825
|
+
}
|
|
826
|
+
/** 按 id 获取覆盖物记录,不存在时抛 OVERLAY_NOT_FOUND */
|
|
827
|
+
getRecord(e) {
|
|
828
|
+
const t = this.overlays.get(e);
|
|
829
|
+
if (!t)
|
|
830
|
+
throw new o("OVERLAY_NOT_FOUND", `Overlay not found: ${e}`);
|
|
831
|
+
return t;
|
|
832
|
+
}
|
|
833
|
+
/** 生成形如 "polyline-1" 的自增覆盖物 id */
|
|
834
|
+
nextId(e) {
|
|
835
|
+
return this.idSeed += 1, `${e}-${this.idSeed}`;
|
|
836
|
+
}
|
|
837
|
+
getMassPointLayerRecord(e) {
|
|
838
|
+
const t = this.massPointLayers.get(e);
|
|
839
|
+
if (!t)
|
|
840
|
+
throw new o("OVERLAY_NOT_FOUND", `Mass point layer not found: ${e}`);
|
|
841
|
+
return t;
|
|
842
|
+
}
|
|
843
|
+
getScatterLayerRecord(e) {
|
|
844
|
+
const t = this.scatterLayers.get(e);
|
|
845
|
+
if (!t)
|
|
846
|
+
throw new o("OVERLAY_NOT_FOUND", `Scatter layer not found: ${e}`);
|
|
847
|
+
return t;
|
|
848
|
+
}
|
|
849
|
+
getPolylineLayerRecord(e) {
|
|
850
|
+
const t = this.polylineLayers.get(e);
|
|
851
|
+
if (!t)
|
|
852
|
+
throw new o("OVERLAY_NOT_FOUND", `Polyline layer not found: ${e}`);
|
|
853
|
+
return t;
|
|
854
|
+
}
|
|
855
|
+
getPolygonLayerRecord(e) {
|
|
856
|
+
const t = this.polygonLayers.get(e);
|
|
857
|
+
if (!t)
|
|
858
|
+
throw new o("OVERLAY_NOT_FOUND", `Polygon layer not found: ${e}`);
|
|
859
|
+
return t;
|
|
860
|
+
}
|
|
861
|
+
hasLayerId(e) {
|
|
862
|
+
return this.overlays.has(e) || this.massPointLayers.has(e) || this.scatterLayers.has(e) || this.polylineLayers.has(e) || this.polygonLayers.has(e);
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* 派发地图点击事件
|
|
866
|
+
* 默认在绘制进行中时抑制点击(suppressClickWhileDrawing !== false),
|
|
867
|
+
* 单个监听器抛异常不影响其他监听器执行
|
|
868
|
+
*/
|
|
869
|
+
emitMapClick(e) {
|
|
870
|
+
this.options.suppressClickWhileDrawing !== !1 && (this.state === "drawing-polyline" || this.state === "drawing-polygon") || this.clickListeners.forEach((t) => {
|
|
871
|
+
try {
|
|
872
|
+
t(e);
|
|
873
|
+
} catch (i) {
|
|
874
|
+
console.error("Map click listener failed", i);
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
/** 派发绘制完成事件,单个监听器抛异常不影响其他监听器执行 */
|
|
879
|
+
emitDraw(e) {
|
|
880
|
+
this.drawListeners.forEach((t) => {
|
|
881
|
+
try {
|
|
882
|
+
t(e);
|
|
883
|
+
} catch (i) {
|
|
884
|
+
console.error("Draw listener failed", i);
|
|
885
|
+
}
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
export {
|
|
890
|
+
o as M,
|
|
891
|
+
A as U,
|
|
892
|
+
w as a
|
|
893
|
+
};
|