@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.
Files changed (34) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +82 -2
  3. package/dist/chunks/AMapAdapter-6257126f.js +528 -0
  4. package/dist/chunks/ArcGISAdapter-09b4e73f.js +863 -0
  5. package/dist/chunks/BMapAdapter-eb942a66.js +530 -0
  6. package/dist/chunks/color-128d7dff.js +38 -0
  7. package/dist/chunks/index-5b75eace.js +893 -0
  8. package/dist/chunks/mapLoader-06d6e155.js +226 -0
  9. package/dist/index.js +6 -0
  10. package/dist/types/index.d.ts +2 -0
  11. package/dist/types/index.d.ts.map +1 -0
  12. package/dist/types/map/UnifiedMap.d.ts +240 -0
  13. package/dist/types/map/UnifiedMap.d.ts.map +1 -0
  14. package/dist/types/map/adapters/AMapAdapter.d.ts +82 -0
  15. package/dist/types/map/adapters/AMapAdapter.d.ts.map +1 -0
  16. package/dist/types/map/adapters/ArcGISAdapter.d.ts +85 -0
  17. package/dist/types/map/adapters/ArcGISAdapter.d.ts.map +1 -0
  18. package/dist/types/map/adapters/BMapAdapter.d.ts +77 -0
  19. package/dist/types/map/adapters/BMapAdapter.d.ts.map +1 -0
  20. package/dist/types/map/adapters/MapAdapter.d.ts +40 -0
  21. package/dist/types/map/adapters/MapAdapter.d.ts.map +1 -0
  22. package/dist/types/map/adapters/color.d.ts +3 -0
  23. package/dist/types/map/adapters/color.d.ts.map +1 -0
  24. package/dist/types/map/coordinates.d.ts +29 -0
  25. package/dist/types/map/coordinates.d.ts.map +1 -0
  26. package/dist/types/map/errors.d.ts +8 -0
  27. package/dist/types/map/errors.d.ts.map +1 -0
  28. package/dist/types/map/index.d.ts +4 -0
  29. package/dist/types/map/index.d.ts.map +1 -0
  30. package/dist/types/map/types.d.ts +204 -0
  31. package/dist/types/map/types.d.ts.map +1 -0
  32. package/dist/types/utils/mapLoader.d.ts +49 -0
  33. package/dist/types/utils/mapLoader.d.ts.map +1 -0
  34. package/package.json +63 -4
@@ -0,0 +1,530 @@
1
+ var M = Object.defineProperty;
2
+ var b = (L, t, e) => t in L ? M(L, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : L[t] = e;
3
+ var f = (L, t, e) => (b(L, typeof t != "symbol" ? t + "" : t, e), e);
4
+ import { b as C, c as R } from "./mapLoader-06d6e155.js";
5
+ import { M as c, a as S } from "./index-5b75eace.js";
6
+ import { t as V } from "./color-128d7dff.js";
7
+ import "vue";
8
+ class z {
9
+ constructor() {
10
+ f(this, "coordinateSystem", "bd09");
11
+ f(this, "sdk", null);
12
+ f(this, "mapVglSdk", null);
13
+ f(this, "mapVglView", null);
14
+ f(this, "map", null);
15
+ f(this, "containerElement", null);
16
+ f(this, "activeDraw", null);
17
+ f(this, "activeEdit", null);
18
+ f(this, "overlayKinds", /* @__PURE__ */ new WeakMap());
19
+ f(this, "massPointLayers", /* @__PURE__ */ new Set());
20
+ f(this, "scatterLayers", /* @__PURE__ */ new Set());
21
+ f(this, "polylineLayers", /* @__PURE__ */ new Set());
22
+ f(this, "polygonLayers", /* @__PURE__ */ new Set());
23
+ }
24
+ async init(t) {
25
+ var i, s, r, a, o, l, n;
26
+ if (!t.key)
27
+ throw new c("SDK_ERROR", "Baidu Map requires an AK");
28
+ const e = this.resolveContainer(t.container);
29
+ this.containerElement = typeof e == "string" ? document.getElementById(e) : e;
30
+ try {
31
+ this.sdk = await C(t.key), this.map = new this.sdk.Map(e, {
32
+ // 百度 GL 默认将线面覆盖物绘制在底图文字下方;绘制态和完成态都需置顶。
33
+ overlayTop: !0
34
+ }), this.map.centerAndZoom(
35
+ this.toPoint(t.center || [116.410316, 39.916699]),
36
+ t.zoom ?? 12
37
+ ), (s = (i = this.map).enableScrollWheelZoom) == null || s.call(i, !0), this.mapVglSdk = await R(), this.mapVglView = new this.mapVglSdk.View({ map: this.map });
38
+ } catch (h) {
39
+ throw (a = (r = this.mapVglView) == null ? void 0 : r.destroy) == null || a.call(r), this.mapVglView = null, this.mapVglSdk = null, (l = (o = this.map) == null ? void 0 : o.destroy) == null || l.call(o), (n = this.containerElement) == null || n.replaceChildren(), this.containerElement = null, this.sdk = null, this.map = null, new c("SDK_ERROR", "Failed to initialize Baidu Map", { cause: h });
40
+ }
41
+ }
42
+ destroy() {
43
+ var t, e, i, s, r, a, o, l, n, h, m, g;
44
+ this.activeEdit && this.finishEdit(this.activeEdit), this.cancelDraw();
45
+ for (const d of [...this.massPointLayers])
46
+ (e = (t = this.mapVglView) == null ? void 0 : t.removeLayer) == null || e.call(t, d.layer), (s = (i = d.layer) == null ? void 0 : i.clear) == null || s.call(i);
47
+ this.massPointLayers.clear();
48
+ for (const d of [...this.scatterLayers])
49
+ this.destroyScatterLayer(d);
50
+ this.scatterLayers.clear();
51
+ for (const d of [...this.polylineLayers])
52
+ this.destroyVectorLayer(d);
53
+ this.polylineLayers.clear();
54
+ for (const d of [...this.polygonLayers])
55
+ this.destroyVectorLayer(d);
56
+ this.polygonLayers.clear(), (a = (r = this.mapVglView) == null ? void 0 : r.destroy) == null || a.call(r), this.mapVglView = null, this.mapVglSdk = null, (l = (o = this.map) == null ? void 0 : o.clearOverlays) == null || l.call(o), typeof ((n = this.map) == null ? void 0 : n.destroy) == "function" ? this.map.destroy() : (m = (h = this.map) == null ? void 0 : h.dispose) == null || m.call(h), this.map = null, this.sdk = null, (g = this.containerElement) == null || g.replaceChildren(), this.containerElement = null;
57
+ }
58
+ addMarker(t) {
59
+ const e = this.createMarker(t);
60
+ return this.addNative(e, "marker"), e;
61
+ }
62
+ addPolyline(t) {
63
+ const e = this.createPolyline(t);
64
+ return this.addNative(e, "polyline"), e;
65
+ }
66
+ addPolygon(t) {
67
+ const e = this.createPolygon(t);
68
+ return this.addNative(e, "polygon"), e;
69
+ }
70
+ addPolylineLayer(t) {
71
+ if (!this.mapVglView || !this.mapVglSdk)
72
+ throw new c("SDK_ERROR", "Baidu MapVGL is unavailable");
73
+ const e = new this.mapVglSdk.LineLayer(this.toPolylineLayerStyle(t)), i = { layer: e };
74
+ return this.mapVglView.addLayer(e), e.setData(this.toPolylineLayerData(t)), this.setMassPointLayerVisibility(e, t.visible !== !1), this.polylineLayers.add(i), i;
75
+ }
76
+ updatePolylineLayer(t, e, i) {
77
+ var r, a, o, l;
78
+ const s = t;
79
+ if (!this.polylineLayers.has(s))
80
+ throw new c("OVERLAY_NOT_FOUND", "Polyline layer is no longer registered");
81
+ return ("style" in i || "zIndex" in i || "minZoom" in i || "maxZoom" in i) && ((a = (r = s.layer).setOptions) == null || a.call(r, this.toPolylineLayerStyle(e))), "polylines" in i && ((l = (o = s.layer).setData) == null || l.call(o, this.toPolylineLayerData(e))), "visible" in i && this.setMassPointLayerVisibility(s.layer, e.visible !== !1), t;
82
+ }
83
+ removePolylineLayer(t) {
84
+ const e = t;
85
+ this.polylineLayers.has(e) && (this.destroyVectorLayer(e), this.polylineLayers.delete(e));
86
+ }
87
+ addPolygonLayer(t) {
88
+ if (!this.mapVglView || !this.mapVglSdk)
89
+ throw new c("SDK_ERROR", "Baidu MapVGL is unavailable");
90
+ const e = new this.mapVglSdk.PolygonLayer(this.toPolygonLayerStyle(t)), i = { layer: e };
91
+ return this.mapVglView.addLayer(e), e.setData(this.toPolygonLayerData(t)), this.setMassPointLayerVisibility(e, t.visible !== !1), this.polygonLayers.add(i), i;
92
+ }
93
+ updatePolygonLayer(t, e, i) {
94
+ var r, a, o, l;
95
+ const s = t;
96
+ if (!this.polygonLayers.has(s))
97
+ throw new c("OVERLAY_NOT_FOUND", "Polygon layer is no longer registered");
98
+ return ("style" in i || "zIndex" in i || "minZoom" in i || "maxZoom" in i) && ((a = (r = s.layer).setOptions) == null || a.call(r, this.toPolygonLayerStyle(e))), "polygons" in i && ((l = (o = s.layer).setData) == null || l.call(o, this.toPolygonLayerData(e))), "visible" in i && this.setMassPointLayerVisibility(s.layer, e.visible !== !1), t;
99
+ }
100
+ removePolygonLayer(t) {
101
+ const e = t;
102
+ this.polygonLayers.has(e) && (this.destroyVectorLayer(e), this.polygonLayers.delete(e));
103
+ }
104
+ addMassPoints(t) {
105
+ if (!this.mapVglView || !this.mapVglSdk)
106
+ throw new c("SDK_ERROR", "Baidu MapVGL is unavailable");
107
+ const e = new this.mapVglSdk.PointLayer(this.toMassPointLayerStyle(t)), i = { layer: e };
108
+ return this.mapVglView.addLayer(e), e.setData(this.toMassPointData(t)), this.setMassPointLayerVisibility(e, t.visible !== !1), this.massPointLayers.add(i), i;
109
+ }
110
+ updateMassPoints(t, e) {
111
+ var s, r, a, o;
112
+ const i = t;
113
+ if (!this.massPointLayers.has(i))
114
+ throw new c("OVERLAY_NOT_FOUND", "Mass point layer is no longer registered");
115
+ return (r = (s = i.layer).setOptions) == null || r.call(s, this.toMassPointLayerStyle(e)), (o = (a = i.layer).setData) == null || o.call(a, this.toMassPointData(e)), this.setMassPointLayerVisibility(i.layer, e.visible !== !1), t;
116
+ }
117
+ removeMassPoints(t) {
118
+ var i, s, r, a;
119
+ const e = t;
120
+ this.massPointLayers.has(e) && ((s = (i = this.mapVglView) == null ? void 0 : i.removeLayer) == null || s.call(i, e.layer), (a = (r = e.layer) == null ? void 0 : r.clear) == null || a.call(r), this.massPointLayers.delete(e));
121
+ }
122
+ addScatterLayer(t) {
123
+ if (!this.mapVglView || !this.mapVglSdk)
124
+ throw new c("SDK_ERROR", "Baidu MapVGL is unavailable");
125
+ const e = this.createScatterLayer(t);
126
+ return this.scatterLayers.add(e), e;
127
+ }
128
+ updateScatterLayer(t, e) {
129
+ const i = t;
130
+ if (!this.scatterLayers.has(i))
131
+ throw new c("OVERLAY_NOT_FOUND", "Scatter layer is no longer registered");
132
+ const s = this.createScatterLayer(e);
133
+ return this.scatterLayers.add(s), this.destroyScatterLayer(i), this.scatterLayers.delete(i), s;
134
+ }
135
+ removeScatterLayer(t) {
136
+ const e = t;
137
+ this.scatterLayers.has(e) && (this.destroyScatterLayer(e), this.scatterLayers.delete(e));
138
+ }
139
+ updateOverlay(t, e, i) {
140
+ var o, l, n, h, m, g, d;
141
+ const s = this.overlayKinds.get(t);
142
+ if (!s)
143
+ throw new c("OVERLAY_NOT_FOUND", "Overlay is no longer registered");
144
+ if (s === "marker")
145
+ return this.removeOverlay(t), this.addMarker(e);
146
+ const r = t, a = e;
147
+ if ("path" in i && ((o = r.setPath) == null || o.call(r, a.path.map((y) => this.toPoint(y)))), (l = r.setStrokeColor) == null || l.call(r, a.strokeColor || "#3366ff"), (n = r.setStrokeWeight) == null || n.call(r, a.strokeWeight ?? (s === "polygon" ? 3 : 5)), (h = r.setStrokeOpacity) == null || h.call(r, a.strokeOpacity ?? 1), (m = r.setStrokeStyle) == null || m.call(r, a.strokeStyle || "solid"), s === "polygon") {
148
+ const y = e;
149
+ (g = r.setFillColor) == null || g.call(r, y.fillColor || "#3366ff"), (d = r.setFillOpacity) == null || d.call(r, y.fillOpacity ?? 0.3);
150
+ }
151
+ return t;
152
+ }
153
+ removeOverlay(t) {
154
+ var i, s;
155
+ const e = this.activeEdit;
156
+ e && e.native === t && this.finishEdit(e), (s = (i = this.map) == null ? void 0 : i.removeOverlay) == null || s.call(i, t), t && (typeof t == "object" || typeof t == "function") && this.overlayKinds.delete(t);
157
+ }
158
+ getPath(t) {
159
+ var i;
160
+ const e = (i = t == null ? void 0 : t.getPath) == null ? void 0 : i.call(t);
161
+ return Array.isArray(e) ? e.map((s) => S([s.lng, s.lat])) : null;
162
+ }
163
+ getPosition(t) {
164
+ var s, r;
165
+ const e = t, i = ((s = e == null ? void 0 : e.getPosition) == null ? void 0 : s.call(e)) || ((r = e == null ? void 0 : e.getCenter) == null ? void 0 : r.call(e));
166
+ return i ? S([i.lng, i.lat]) : null;
167
+ }
168
+ onMapClick(t) {
169
+ const e = (i) => {
170
+ const s = this.toClickEvent(i);
171
+ if (!s)
172
+ return;
173
+ const r = (i == null ? void 0 : i.overlay) || (i == null ? void 0 : i.target), a = r && r !== this.map && this.overlayKinds.has(r) ? r : void 0;
174
+ t(s, a);
175
+ };
176
+ return this.map.addEventListener("click", e), () => {
177
+ var i, s;
178
+ return (s = (i = this.map) == null ? void 0 : i.removeEventListener) == null ? void 0 : s.call(i, "click", e);
179
+ };
180
+ }
181
+ onOverlayClick(t, e) {
182
+ var r;
183
+ const i = t, s = (a) => {
184
+ const o = this.toClickEvent(a, t);
185
+ o && e(o);
186
+ };
187
+ return (r = i.addEventListener) == null || r.call(i, "click", s), () => {
188
+ var a;
189
+ return (a = i.removeEventListener) == null ? void 0 : a.call(i, "click", s);
190
+ };
191
+ }
192
+ startEdit(t, e, i) {
193
+ var a;
194
+ if (this.overlayKinds.get(t) !== e)
195
+ throw new c("INVALID_OPTIONS", "Only polyline and polygon overlays can be edited");
196
+ const s = t;
197
+ if (typeof s.enableEditing != "function")
198
+ throw new c("SDK_ERROR", `Baidu Map ${e} editing is unavailable`);
199
+ if (this.activeDraw)
200
+ throw new c("DRAW_IN_PROGRESS", "Cannot edit while drawing");
201
+ this.activeEdit && this.finishEdit(this.activeEdit);
202
+ const r = {
203
+ native: t,
204
+ handler: () => {
205
+ const o = this.getPath(t);
206
+ o && i(o);
207
+ },
208
+ onChange: i,
209
+ stopped: !1
210
+ };
211
+ return this.activeEdit = r, (a = s.addEventListener) == null || a.call(s, "lineupdate", r.handler), s.enableEditing(), () => this.finishEdit(r);
212
+ }
213
+ startDraw(t, e, i, s) {
214
+ var a;
215
+ if (this.activeDraw)
216
+ throw new c("DRAW_IN_PROGRESS", "A drawing operation is already active");
217
+ this.activeEdit && this.finishEdit(this.activeEdit);
218
+ const r = (a = window.BMapGLLib) == null ? void 0 : a.DrawingManager;
219
+ if (r) {
220
+ this.startDrawingManager(r, t, e, i, s);
221
+ return;
222
+ }
223
+ this.startManualDraw(t, e, i, s);
224
+ }
225
+ cancelDraw() {
226
+ const t = this.activeDraw;
227
+ !t || t.finished || (t.finished = !0, t.cleanup(!0), this.activeDraw === t && (this.activeDraw = null), t.onCancel());
228
+ }
229
+ setCenter(t) {
230
+ this.map.setCenter(this.toPoint(t));
231
+ }
232
+ getCenter() {
233
+ const t = this.map.getCenter();
234
+ return S([t.lng, t.lat]);
235
+ }
236
+ setZoom(t) {
237
+ this.map.setZoom(t);
238
+ }
239
+ getZoom() {
240
+ return this.map.getZoom();
241
+ }
242
+ resolveContainer(t) {
243
+ if (typeof t == "string") {
244
+ if (!document.getElementById(t))
245
+ throw new c("INVALID_OPTIONS", `Container not found: ${t}`);
246
+ return t;
247
+ }
248
+ if (!t)
249
+ throw new c("INVALID_OPTIONS", "A map container is required");
250
+ return t;
251
+ }
252
+ toPoint(t) {
253
+ return new this.sdk.Point(t[0], t[1]);
254
+ }
255
+ toClickEvent(t, e) {
256
+ const i = (t == null ? void 0 : t.latlng) || (t == null ? void 0 : t.latLng) || (t == null ? void 0 : t.point) || (e ? this.nativeAnchor(e) : null);
257
+ if (!i)
258
+ return null;
259
+ const s = S([i.lng, i.lat]);
260
+ return {
261
+ lnglat: { lng: s[0], lat: s[1] },
262
+ position: s,
263
+ coordinateSystem: this.coordinateSystem,
264
+ originalEvent: t
265
+ };
266
+ }
267
+ nativeAnchor(t) {
268
+ var s, r, a, o;
269
+ const e = t, i = ((s = e == null ? void 0 : e.getPosition) == null ? void 0 : s.call(e)) || ((r = e == null ? void 0 : e.getCenter) == null ? void 0 : r.call(e));
270
+ return i || ((o = (a = e == null ? void 0 : e.getPath) == null ? void 0 : a.call(e)) == null ? void 0 : o[0]) || null;
271
+ }
272
+ addNative(t, e) {
273
+ this.map.addOverlay(t), this.overlayKinds.set(t, e);
274
+ }
275
+ createMarker(t) {
276
+ const e = t.style || { kind: "circle" }, i = this.toPoint(t.position);
277
+ if (e.kind === "icon") {
278
+ const m = new this.sdk.Size(e.width, e.height), g = e.anchor === "bottom-center" ? new this.sdk.Size(e.width / 2, e.height) : new this.sdk.Size(e.width / 2, e.height / 2), d = new this.sdk.Icon(e.url, m, { anchor: g, imageSize: m });
279
+ return new this.sdk.Marker(i, { icon: d, enableClicking: !0 });
280
+ }
281
+ const s = e.radius ?? 8, r = e.strokeWeight ?? 2, a = (s + r) * 2, o = `<svg xmlns="http://www.w3.org/2000/svg" width="${a}" height="${a}" viewBox="0 0 ${a} ${a}"><circle cx="${a / 2}" cy="${a / 2}" r="${s}" fill="${e.fillColor || "#1677ff"}" fill-opacity="${e.fillOpacity ?? 0.8}" stroke="${e.strokeColor || "#ffffff"}" stroke-width="${r}"/></svg>`, l = `data:image/svg+xml;charset=UTF-8,${encodeURIComponent(o)}`, n = new this.sdk.Size(a, a), h = new this.sdk.Icon(l, n, {
282
+ anchor: new this.sdk.Size(a / 2, a / 2),
283
+ imageSize: n
284
+ });
285
+ return new this.sdk.Marker(i, { icon: h, enableClicking: !0 });
286
+ }
287
+ createPolyline(t) {
288
+ return new this.sdk.Polyline(
289
+ t.path.map((e) => this.toPoint(e)),
290
+ this.toPolylineStyle(t)
291
+ );
292
+ }
293
+ createPolygon(t) {
294
+ return new this.sdk.Polygon(
295
+ t.path.map((e) => this.toPoint(e)),
296
+ this.toPolygonStyle(t)
297
+ );
298
+ }
299
+ toMassPointLayerStyle(t) {
300
+ const e = t.style || {};
301
+ return {
302
+ color: V(e.color || "#ff1a0a", e.opacity ?? 0.85),
303
+ shape: "circle",
304
+ size: e.size ?? 10,
305
+ unit: e.unit === "meter" ? "m" : "px",
306
+ borderWidth: e.borderWidth ?? 0,
307
+ borderColor: e.borderColor || "#ffffff",
308
+ renderOrder: t.zIndex ?? 100,
309
+ minZoom: t.minZoom ?? 3,
310
+ maxZoom: t.maxZoom ?? 21
311
+ };
312
+ }
313
+ toPolylineLayerStyle(t) {
314
+ const e = t.style || {};
315
+ return {
316
+ color: V(e.strokeColor || "#3366ff", e.strokeOpacity ?? 1),
317
+ width: e.strokeWeight ?? 3,
318
+ // MapVGL 1.0.0-beta.188 会直接读取 dashArray[1]。显式传入
319
+ // undefined 会覆盖其默认值并导致整个图层解析失败。
320
+ ...e.strokeStyle === "dashed" ? { dashArray: [10, 10] } : {},
321
+ renderOrder: t.zIndex ?? 90,
322
+ minZoom: t.minZoom ?? 3,
323
+ maxZoom: t.maxZoom ?? 21
324
+ };
325
+ }
326
+ toPolygonLayerStyle(t) {
327
+ const e = t.style || {};
328
+ return {
329
+ fillColor: e.fillColor || "#3366ff",
330
+ fillOpacity: e.fillOpacity ?? 0.3,
331
+ lineColor: V(e.strokeColor || "#3366ff", e.strokeOpacity ?? 1),
332
+ lineWidth: e.strokeWeight ?? 2,
333
+ ...e.strokeStyle === "dashed" ? { dashArray: [10, 10] } : {},
334
+ renderOrder: t.zIndex ?? 80,
335
+ minZoom: t.minZoom ?? 3,
336
+ maxZoom: t.maxZoom ?? 21
337
+ };
338
+ }
339
+ toPolylineLayerData(t) {
340
+ return t.polylines.map((e) => ({
341
+ geometry: {
342
+ type: "LineString",
343
+ coordinates: e.path.map((i) => [i[0], i[1]])
344
+ },
345
+ properties: e.properties || {}
346
+ }));
347
+ }
348
+ toPolygonLayerData(t) {
349
+ return t.polygons.map((e) => ({
350
+ geometry: { type: "Polygon", coordinates: [this.closeRing(e.path)] },
351
+ properties: e.properties || {}
352
+ }));
353
+ }
354
+ destroyVectorLayer(t) {
355
+ var e, i, s, r;
356
+ (i = (e = this.mapVglView) == null ? void 0 : e.removeLayer) == null || i.call(e, t.layer), (r = (s = t.layer) == null ? void 0 : s.clear) == null || r.call(s);
357
+ }
358
+ closeRing(t) {
359
+ const e = t[0], i = t[t.length - 1], s = t.map((r) => [r[0], r[1]]);
360
+ return e[0] === i[0] && e[1] === i[1] ? s : [...s, [e[0], e[1]]];
361
+ }
362
+ createScatterLayer(t) {
363
+ var a;
364
+ const e = document.createElement("canvas");
365
+ e.width = 1, e.height = 1;
366
+ const i = new this.mapVglSdk.IconLayer(this.toScatterLayerStyle(t, e)), s = new Image(), r = {
367
+ layer: i,
368
+ frames: [],
369
+ image: s,
370
+ animationFrame: null,
371
+ startedAt: 0,
372
+ lastFrame: -1,
373
+ options: t,
374
+ disposed: !1
375
+ };
376
+ return this.mapVglView.addLayer(i), i.setData(this.toMassPointData(t)), this.setMassPointLayerVisibility(i, t.visible !== !1), s.onload = () => this.prepareScatterFrames(r), s.onerror = () => {
377
+ r.disposed || console.error(`Baidu scatter texture failed to load: ${s.src}`);
378
+ }, s.src = ((a = t.style) == null ? void 0 : a.texture) || "/breath_red.png", r;
379
+ }
380
+ prepareScatterFrames(t) {
381
+ if (t.disposed)
382
+ return;
383
+ const e = t.image.height, i = e > 0 ? Math.floor(t.image.width / e) : 0;
384
+ if (i === 0) {
385
+ console.error("Baidu scatter texture must be a horizontal sequence of square frames");
386
+ return;
387
+ }
388
+ t.frames = Array.from({ length: i }, (s, r) => {
389
+ const a = document.createElement("canvas");
390
+ a.width = e, a.height = e;
391
+ const o = a.getContext("2d");
392
+ return o == null || o.drawImage(
393
+ t.image,
394
+ r * e,
395
+ 0,
396
+ e,
397
+ e,
398
+ 0,
399
+ 0,
400
+ e,
401
+ e
402
+ ), a;
403
+ }), t.startedAt = performance.now(), t.options.visible !== !1 && this.animateScatterLayer(t);
404
+ }
405
+ animateScatterLayer(t) {
406
+ var s;
407
+ if (t.disposed || t.frames.length === 0)
408
+ return;
409
+ const e = Math.max(1, ((s = t.options.style) == null ? void 0 : s.duration) ?? 2e3), i = (r) => {
410
+ var l, n;
411
+ if (t.disposed)
412
+ return;
413
+ const a = (r - t.startedAt) % e / e, o = Math.min(
414
+ t.frames.length - 1,
415
+ Math.floor(a * t.frames.length)
416
+ );
417
+ o !== t.lastFrame && (t.lastFrame = o, (n = (l = t.layer).setOptions) == null || n.call(
418
+ l,
419
+ this.toScatterLayerStyle(t.options, t.frames[o])
420
+ )), t.animationFrame = window.requestAnimationFrame(i);
421
+ };
422
+ t.animationFrame = window.requestAnimationFrame(i);
423
+ }
424
+ destroyScatterLayer(t) {
425
+ var e, i, s, r;
426
+ t.disposed = !0, t.animationFrame !== null && window.cancelAnimationFrame(t.animationFrame), t.animationFrame = null, t.image.onload = null, t.image.onerror = null, t.frames.length = 0, (i = (e = this.mapVglView) == null ? void 0 : e.removeLayer) == null || i.call(e, t.layer), (r = (s = t.layer) == null ? void 0 : s.clear) == null || r.call(s);
427
+ }
428
+ toScatterLayerStyle(t, e) {
429
+ const i = t.style || {};
430
+ return {
431
+ icon: e,
432
+ width: i.size ?? 40,
433
+ height: i.size ?? 40,
434
+ unit: i.unit === "meter" ? "m" : "px",
435
+ opacity: i.opacity ?? 1,
436
+ renderOrder: t.zIndex ?? 120,
437
+ minZoom: t.minZoom ?? 3,
438
+ maxZoom: t.maxZoom ?? 21
439
+ };
440
+ }
441
+ toMassPointData(t) {
442
+ return t.points.map((e) => ({
443
+ geometry: { type: "Point", coordinates: e.position },
444
+ properties: e.properties || {}
445
+ }));
446
+ }
447
+ setMassPointLayerVisibility(t, e) {
448
+ var i, s, r, a;
449
+ e ? (s = (i = this.mapVglView) == null ? void 0 : i.showLayer) == null || s.call(i, t) : (a = (r = this.mapVglView) == null ? void 0 : r.hideLayer) == null || a.call(r, t);
450
+ }
451
+ toPolylineStyle(t) {
452
+ return {
453
+ strokeColor: t.strokeColor || "#3366ff",
454
+ strokeWeight: t.strokeWeight ?? 5,
455
+ strokeOpacity: t.strokeOpacity ?? 1,
456
+ strokeStyle: t.strokeStyle || "solid",
457
+ enableClicking: !0
458
+ };
459
+ }
460
+ toPolygonStyle(t) {
461
+ const e = t;
462
+ return {
463
+ ...this.toPolylineStyle(t),
464
+ strokeWeight: t.strokeWeight ?? 3,
465
+ fillColor: e.fillColor || "#3366ff",
466
+ fillOpacity: e.fillOpacity ?? 0.3
467
+ };
468
+ }
469
+ startDrawingManager(t, e, i, s, r) {
470
+ const a = new t(this.map, {
471
+ isOpen: !1,
472
+ enableDrawingTool: !1,
473
+ polylineOptions: this.toPolylineStyle(i),
474
+ polygonOptions: this.toPolygonStyle(i)
475
+ }), o = (n) => {
476
+ const h = this.activeDraw;
477
+ if (!h || h.finished)
478
+ return;
479
+ const m = (n == null ? void 0 : n.overlay) || n, g = this.getPath(m);
480
+ !m || !g || (h.finished = !0, h.cleanup(!1), this.overlayKinds.set(m, e), this.activeDraw === h && (this.activeDraw = null), s(m, g));
481
+ }, l = {
482
+ finished: !1,
483
+ onCancel: r,
484
+ cleanup: () => {
485
+ var n, h;
486
+ (n = a.removeEventListener) == null || n.call(a, "overlaycomplete", o), (h = a.close) == null || h.call(a);
487
+ }
488
+ };
489
+ this.activeDraw = l, a.addEventListener("overlaycomplete", o), a.setDrawingMode(e), a.open();
490
+ }
491
+ /** DrawingManager 不可用时的轻量后备:单击加点,双击完成。 */
492
+ startManualDraw(t, e, i, s) {
493
+ var g, d;
494
+ const r = [];
495
+ let a = null;
496
+ const o = t === "polyline" ? 2 : 3, l = (y) => {
497
+ var w;
498
+ const p = (y == null ? void 0 : y.latlng) || (y == null ? void 0 : y.latLng) || (y == null ? void 0 : y.point);
499
+ if (!p)
500
+ return;
501
+ const u = r[r.length - 1];
502
+ u && u.lng === p.lng && u.lat === p.lat || (r.push(p), !a && r.length >= o ? (a = t === "polyline" ? new this.sdk.Polyline(r.slice(), this.toPolylineStyle(e)) : new this.sdk.Polygon(r.slice(), this.toPolygonStyle(e)), this.map.addOverlay(a)) : (w = a == null ? void 0 : a.setPath) == null || w.call(a, r.slice()));
503
+ }, n = (y) => l(y), h = (y) => {
504
+ var u, w;
505
+ (w = (u = y == null ? void 0 : y.domEvent) == null ? void 0 : u.preventDefault) == null || w.call(u), l(y);
506
+ const p = this.activeDraw;
507
+ !p || p.finished || !a || r.length < o || (p.finished = !0, p.cleanup(!1), this.overlayKinds.set(a, t), this.activeDraw === p && (this.activeDraw = null), i(a, this.getPath(a) || []));
508
+ }, m = {
509
+ finished: !1,
510
+ onCancel: s,
511
+ cleanup: (y = !1) => {
512
+ var p, u, w, O, P, E, k, D;
513
+ (u = (p = this.map) == null ? void 0 : p.removeEventListener) == null || u.call(p, "click", n), (O = (w = this.map) == null ? void 0 : w.removeEventListener) == null || O.call(w, "dblclick", h), (E = (P = this.map) == null ? void 0 : P.enableDoubleClickZoom) == null || E.call(P), y && a && ((D = (k = this.map) == null ? void 0 : k.removeOverlay) == null || D.call(k, a));
514
+ }
515
+ };
516
+ this.activeDraw = m, (d = (g = this.map).disableDoubleClickZoom) == null || d.call(g), this.map.addEventListener("click", n), this.map.addEventListener("dblclick", h);
517
+ }
518
+ finishEdit(t) {
519
+ var s, r;
520
+ if (t.stopped)
521
+ return;
522
+ const e = this.getPath(t.native);
523
+ e && t.onChange(e), t.stopped = !0;
524
+ const i = t.native;
525
+ (s = i.removeEventListener) == null || s.call(i, "lineupdate", t.handler), (r = i.disableEditing) == null || r.call(i), this.activeEdit === t && (this.activeEdit = null);
526
+ }
527
+ }
528
+ export {
529
+ z as BMapAdapter
530
+ };
@@ -0,0 +1,38 @@
1
+ const b = {
2
+ black: [0, 0, 0],
3
+ blue: [0, 0, 255],
4
+ gray: [128, 128, 128],
5
+ green: [0, 128, 0],
6
+ red: [255, 0, 0],
7
+ transparent: [0, 0, 0],
8
+ white: [255, 255, 255],
9
+ yellow: [255, 255, 0]
10
+ };
11
+ function m(o, l = 1) {
12
+ const n = (o || "#3366ff").trim().toLowerCase();
13
+ let a = b[n], r = l;
14
+ const s = n.match(/^#([\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i);
15
+ if (s) {
16
+ const t = s[1], e = t.length <= 4 ? t.split("").map((i) => i + i).join("") : t;
17
+ a = [
18
+ parseInt(e.slice(0, 2), 16),
19
+ parseInt(e.slice(2, 4), 16),
20
+ parseInt(e.slice(4, 6), 16)
21
+ ], e.length === 8 && (r *= parseInt(e.slice(6, 8), 16) / 255);
22
+ }
23
+ const c = n.match(/^rgba?\(([^)]+)\)$/);
24
+ if (c) {
25
+ const t = c[1].split(",").map((e) => Number.parseFloat(e.trim()));
26
+ t.length >= 3 && t.every((e, i) => i > 2 || Number.isFinite(e)) && (a = [t[0], t[1], t[2]], t.length === 4 && Number.isFinite(t[3]) && (r *= t[3]));
27
+ }
28
+ const [p, f, g] = a || [51, 102, 255];
29
+ return [p, f, g, Math.max(0, Math.min(1, r))];
30
+ }
31
+ function u(o, l = 1) {
32
+ const [n, a, r, s] = m(o, l);
33
+ return `rgba(${n}, ${a}, ${r}, ${s})`;
34
+ }
35
+ export {
36
+ m as a,
37
+ u as t
38
+ };