@lin1538001/unified-map 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +82 -2
  3. package/dist/chunks/AMapAdapter-76901841.js +581 -0
  4. package/dist/chunks/ArcGISAdapter-5e6881de.js +962 -0
  5. package/dist/chunks/BMapAdapter-0d882313.js +581 -0
  6. package/dist/chunks/color-128d7dff.js +38 -0
  7. package/dist/chunks/index-dd303ebf.js +1190 -0
  8. package/dist/chunks/mapLoader-06d6e155.js +226 -0
  9. package/dist/index.js +7 -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/InfoWindow.d.ts +38 -0
  13. package/dist/types/map/InfoWindow.d.ts.map +1 -0
  14. package/dist/types/map/UnifiedMap.d.ts +266 -0
  15. package/dist/types/map/UnifiedMap.d.ts.map +1 -0
  16. package/dist/types/map/adapters/AMapAdapter.d.ts +87 -0
  17. package/dist/types/map/adapters/AMapAdapter.d.ts.map +1 -0
  18. package/dist/types/map/adapters/ArcGISAdapter.d.ts +92 -0
  19. package/dist/types/map/adapters/ArcGISAdapter.d.ts.map +1 -0
  20. package/dist/types/map/adapters/BMapAdapter.d.ts +83 -0
  21. package/dist/types/map/adapters/BMapAdapter.d.ts.map +1 -0
  22. package/dist/types/map/adapters/MapAdapter.d.ts +46 -0
  23. package/dist/types/map/adapters/MapAdapter.d.ts.map +1 -0
  24. package/dist/types/map/adapters/color.d.ts +3 -0
  25. package/dist/types/map/adapters/color.d.ts.map +1 -0
  26. package/dist/types/map/coordinates.d.ts +29 -0
  27. package/dist/types/map/coordinates.d.ts.map +1 -0
  28. package/dist/types/map/errors.d.ts +8 -0
  29. package/dist/types/map/errors.d.ts.map +1 -0
  30. package/dist/types/map/index.d.ts +5 -0
  31. package/dist/types/map/index.d.ts.map +1 -0
  32. package/dist/types/map/types.d.ts +240 -0
  33. package/dist/types/map/types.d.ts.map +1 -0
  34. package/dist/types/utils/mapLoader.d.ts +49 -0
  35. package/dist/types/utils/mapLoader.d.ts.map +1 -0
  36. package/package.json +63 -4
@@ -0,0 +1,581 @@
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 I } from "./mapLoader-06d6e155.js";
5
+ import { M as y, a as S } from "./index-dd303ebf.js";
6
+ import { t as V } from "./color-128d7dff.js";
7
+ import "vue";
8
+ class _ {
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, r, s, a, o, l, n;
26
+ if (!t.key)
27
+ throw new y("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
+ ), (r = (i = this.map).enableScrollWheelZoom) == null || r.call(i, !0), this.mapVglSdk = await I(), this.mapVglView = new this.mapVglSdk.View({ map: this.map });
38
+ } catch (h) {
39
+ throw (a = (s = this.mapVglView) == null ? void 0 : s.destroy) == null || a.call(s), 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 y("SDK_ERROR", "Failed to initialize Baidu Map", { cause: h });
40
+ }
41
+ }
42
+ destroy() {
43
+ var t, e, i, r, s, 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), (r = (i = d.layer) == null ? void 0 : i.clear) == null || r.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 = (s = this.mapVglView) == null ? void 0 : s.destroy) == null || a.call(s), 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 y("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 s, a, o, l;
78
+ const r = t;
79
+ if (!this.polylineLayers.has(r))
80
+ throw new y("OVERLAY_NOT_FOUND", "Polyline layer is no longer registered");
81
+ return ("style" in i || "zIndex" in i || "minZoom" in i || "maxZoom" in i) && ((a = (s = r.layer).setOptions) == null || a.call(s, this.toPolylineLayerStyle(e))), "polylines" in i && ((l = (o = r.layer).setData) == null || l.call(o, this.toPolylineLayerData(e))), "visible" in i && this.setMassPointLayerVisibility(r.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 y("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 s, a, o, l;
95
+ const r = t;
96
+ if (!this.polygonLayers.has(r))
97
+ throw new y("OVERLAY_NOT_FOUND", "Polygon layer is no longer registered");
98
+ return ("style" in i || "zIndex" in i || "minZoom" in i || "maxZoom" in i) && ((a = (s = r.layer).setOptions) == null || a.call(s, this.toPolygonLayerStyle(e))), "polygons" in i && ((l = (o = r.layer).setData) == null || l.call(o, this.toPolygonLayerData(e))), "visible" in i && this.setMassPointLayerVisibility(r.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 y("SDK_ERROR", "Baidu MapVGL is unavailable");
107
+ const e = this.createMassPointLayer(t);
108
+ return this.massPointLayers.add(e), e;
109
+ }
110
+ updateMassPoints(t, e) {
111
+ var s, a, o, l;
112
+ const i = t;
113
+ if (!this.massPointLayers.has(i))
114
+ throw new y("OVERLAY_NOT_FOUND", "Mass point layer is no longer registered");
115
+ const r = this.createMassPointLayer(e);
116
+ return (a = (s = this.mapVglView) == null ? void 0 : s.removeLayer) == null || a.call(s, i.layer), (l = (o = i.layer) == null ? void 0 : o.clear) == null || l.call(o), i.layer = r.layer, t;
117
+ }
118
+ removeMassPoints(t) {
119
+ var i, r, s, a;
120
+ const e = t;
121
+ this.massPointLayers.has(e) && ((r = (i = this.mapVglView) == null ? void 0 : i.removeLayer) == null || r.call(i, e.layer), (a = (s = e.layer) == null ? void 0 : s.clear) == null || a.call(s), this.massPointLayers.delete(e));
122
+ }
123
+ addScatterLayer(t) {
124
+ if (!this.mapVglView || !this.mapVglSdk)
125
+ throw new y("SDK_ERROR", "Baidu MapVGL is unavailable");
126
+ const e = this.createScatterLayer(t);
127
+ return this.scatterLayers.add(e), e;
128
+ }
129
+ updateScatterLayer(t, e) {
130
+ const i = t;
131
+ if (!this.scatterLayers.has(i))
132
+ throw new y("OVERLAY_NOT_FOUND", "Scatter layer is no longer registered");
133
+ const r = this.createScatterLayer(e);
134
+ return this.scatterLayers.add(r), this.destroyScatterLayer(i), this.scatterLayers.delete(i), r;
135
+ }
136
+ removeScatterLayer(t) {
137
+ const e = t;
138
+ this.scatterLayers.has(e) && (this.destroyScatterLayer(e), this.scatterLayers.delete(e));
139
+ }
140
+ updateOverlay(t, e, i) {
141
+ var o, l, n, h, m, g, d;
142
+ const r = this.overlayKinds.get(t);
143
+ if (!r)
144
+ throw new y("OVERLAY_NOT_FOUND", "Overlay is no longer registered");
145
+ if (r === "marker")
146
+ return this.removeOverlay(t), this.addMarker(e);
147
+ const s = t, a = e;
148
+ if ("path" in i && ((o = s.setPath) == null || o.call(s, a.path.map((c) => this.toPoint(c)))), (l = s.setStrokeColor) == null || l.call(s, a.strokeColor || "#3366ff"), (n = s.setStrokeWeight) == null || n.call(s, a.strokeWeight ?? (r === "polygon" ? 3 : 5)), (h = s.setStrokeOpacity) == null || h.call(s, a.strokeOpacity ?? 1), (m = s.setStrokeStyle) == null || m.call(s, a.strokeStyle || "solid"), r === "polygon") {
149
+ const c = e;
150
+ (g = s.setFillColor) == null || g.call(s, c.fillColor || "#3366ff"), (d = s.setFillOpacity) == null || d.call(s, c.fillOpacity ?? 0.3);
151
+ }
152
+ return t;
153
+ }
154
+ removeOverlay(t) {
155
+ var i, r;
156
+ const e = this.activeEdit;
157
+ e && e.native === t && this.finishEdit(e), (r = (i = this.map) == null ? void 0 : i.removeOverlay) == null || r.call(i, t), t && (typeof t == "object" || typeof t == "function") && this.overlayKinds.delete(t);
158
+ }
159
+ getPath(t) {
160
+ var i;
161
+ const e = (i = t == null ? void 0 : t.getPath) == null ? void 0 : i.call(t);
162
+ return Array.isArray(e) ? e.map((r) => S([r.lng, r.lat])) : null;
163
+ }
164
+ getPosition(t) {
165
+ var r, s;
166
+ const e = t, i = ((r = e == null ? void 0 : e.getPosition) == null ? void 0 : r.call(e)) || ((s = e == null ? void 0 : e.getCenter) == null ? void 0 : s.call(e));
167
+ return i ? S([i.lng, i.lat]) : null;
168
+ }
169
+ onMapClick(t) {
170
+ const e = (i) => {
171
+ const r = this.toClickEvent(i);
172
+ if (!r)
173
+ return;
174
+ const s = (i == null ? void 0 : i.overlay) || (i == null ? void 0 : i.target), a = s && s !== this.map && this.overlayKinds.has(s) ? s : void 0;
175
+ t(r, a);
176
+ };
177
+ return this.map.addEventListener("click", e), () => {
178
+ var i, r;
179
+ return (r = (i = this.map) == null ? void 0 : i.removeEventListener) == null ? void 0 : r.call(i, "click", e);
180
+ };
181
+ }
182
+ onOverlayClick(t, e) {
183
+ var s;
184
+ const i = t, r = (a) => {
185
+ const o = this.toClickEvent(a, t);
186
+ o && e(o);
187
+ };
188
+ return (s = i.addEventListener) == null || s.call(i, "click", r), () => {
189
+ var a;
190
+ return (a = i.removeEventListener) == null ? void 0 : a.call(i, "click", r);
191
+ };
192
+ }
193
+ startEdit(t, e, i) {
194
+ var a;
195
+ if (this.overlayKinds.get(t) !== e)
196
+ throw new y("INVALID_OPTIONS", "Only polyline and polygon overlays can be edited");
197
+ const r = t;
198
+ if (typeof r.enableEditing != "function")
199
+ throw new y("SDK_ERROR", `Baidu Map ${e} editing is unavailable`);
200
+ if (this.activeDraw)
201
+ throw new y("DRAW_IN_PROGRESS", "Cannot edit while drawing");
202
+ this.activeEdit && this.finishEdit(this.activeEdit);
203
+ const s = {
204
+ native: t,
205
+ handler: () => {
206
+ const o = this.getPath(t);
207
+ o && i(o);
208
+ },
209
+ onChange: i,
210
+ stopped: !1
211
+ };
212
+ return this.activeEdit = s, (a = r.addEventListener) == null || a.call(r, "lineupdate", s.handler), r.enableEditing(), () => this.finishEdit(s);
213
+ }
214
+ startDraw(t, e, i, r) {
215
+ var a;
216
+ if (this.activeDraw)
217
+ throw new y("DRAW_IN_PROGRESS", "A drawing operation is already active");
218
+ this.activeEdit && this.finishEdit(this.activeEdit);
219
+ const s = (a = window.BMapGLLib) == null ? void 0 : a.DrawingManager;
220
+ if (s) {
221
+ this.startDrawingManager(s, t, e, i, r);
222
+ return;
223
+ }
224
+ this.startManualDraw(t, e, i, r);
225
+ }
226
+ cancelDraw() {
227
+ const t = this.activeDraw;
228
+ !t || t.finished || (t.finished = !0, t.cleanup(!0), this.activeDraw === t && (this.activeDraw = null), t.onCancel());
229
+ }
230
+ setCenter(t) {
231
+ this.map.setCenter(this.toPoint(t));
232
+ }
233
+ getCenter() {
234
+ const t = this.map.getCenter();
235
+ return S([t.lng, t.lat]);
236
+ }
237
+ setZoom(t) {
238
+ this.map.setZoom(t);
239
+ }
240
+ getZoom() {
241
+ return this.map.getZoom();
242
+ }
243
+ fitView(t, e, i, r) {
244
+ if (t.length === 0)
245
+ return;
246
+ const s = t.map((n) => this.toPoint(n)), a = [i[0], i[3], i[1], i[2]], o = this.map.getViewport(s, { margins: a }), l = r === void 0 ? o.zoom : Math.min(o.zoom, r);
247
+ this.map.setViewport(
248
+ { center: o.center, zoom: l },
249
+ { enableAnimation: !e, margins: a, delay: 0 }
250
+ );
251
+ }
252
+ createInfoWindow(t, e, i) {
253
+ var o, l;
254
+ const r = new this.sdk.InfoWindow(t.content ?? "", {
255
+ ...t.size ? { width: t.size[0], height: t.size[1] } : {},
256
+ ...t.offset ? { offset: new this.sdk.Size(t.offset[0], t.offset[1]) } : {},
257
+ enableAutoPan: t.autoMove ?? !0,
258
+ enableCloseOnClick: t.closeWhenClickMap ?? !1
259
+ }), s = (n) => e(n), a = (n) => i(n);
260
+ return (o = r.addEventListener) == null || o.call(r, "open", s), (l = r.addEventListener) == null || l.call(r, "close", a), { value: r, openHandler: s, closeHandler: a };
261
+ }
262
+ openInfoWindow(t, e) {
263
+ this.map.openInfoWindow(t.value, this.toPoint(e));
264
+ }
265
+ closeInfoWindow(t) {
266
+ var e, i;
267
+ (i = (e = this.map).closeInfoWindow) == null || i.call(e);
268
+ }
269
+ destroyInfoWindow(t) {
270
+ var i, r, s, a, o, l, n, h;
271
+ const e = t;
272
+ (r = (i = e.value).removeEventListener) == null || r.call(i, "open", e.openHandler), (a = (s = e.value).removeEventListener) == null || a.call(s, "close", e.closeHandler), (l = (o = e.value).isOpen) != null && l.call(o) && ((h = (n = this.map) == null ? void 0 : n.closeInfoWindow) == null || h.call(n));
273
+ }
274
+ resolveContainer(t) {
275
+ if (typeof t == "string") {
276
+ if (!document.getElementById(t))
277
+ throw new y("INVALID_OPTIONS", `Container not found: ${t}`);
278
+ return t;
279
+ }
280
+ if (!t)
281
+ throw new y("INVALID_OPTIONS", "A map container is required");
282
+ return t;
283
+ }
284
+ toPoint(t) {
285
+ return new this.sdk.Point(t[0], t[1]);
286
+ }
287
+ toClickEvent(t, e) {
288
+ 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);
289
+ if (!i)
290
+ return null;
291
+ const r = S([i.lng, i.lat]);
292
+ return {
293
+ lnglat: { lng: r[0], lat: r[1] },
294
+ position: r,
295
+ coordinateSystem: this.coordinateSystem,
296
+ originalEvent: t
297
+ };
298
+ }
299
+ nativeAnchor(t) {
300
+ var r, s, a, o;
301
+ const e = t, i = ((r = e == null ? void 0 : e.getPosition) == null ? void 0 : r.call(e)) || ((s = e == null ? void 0 : e.getCenter) == null ? void 0 : s.call(e));
302
+ return i || ((o = (a = e == null ? void 0 : e.getPath) == null ? void 0 : a.call(e)) == null ? void 0 : o[0]) || null;
303
+ }
304
+ addNative(t, e) {
305
+ this.map.addOverlay(t), this.overlayKinds.set(t, e);
306
+ }
307
+ createMarker(t) {
308
+ const e = t.style || { kind: "circle" }, i = this.toPoint(t.position);
309
+ if (e.kind === "icon") {
310
+ 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 });
311
+ return new this.sdk.Marker(i, { icon: d, enableClicking: !0 });
312
+ }
313
+ const r = e.radius ?? 8, s = e.strokeWeight ?? 2, a = (r + s) * 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="${r}" fill="${e.fillColor || "#1677ff"}" fill-opacity="${e.fillOpacity ?? 0.8}" stroke="${e.strokeColor || "#ffffff"}" stroke-width="${s}"/></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, {
314
+ anchor: new this.sdk.Size(a / 2, a / 2),
315
+ imageSize: n
316
+ });
317
+ return new this.sdk.Marker(i, { icon: h, enableClicking: !0 });
318
+ }
319
+ createPolyline(t) {
320
+ return new this.sdk.Polyline(
321
+ t.path.map((e) => this.toPoint(e)),
322
+ this.toPolylineStyle(t)
323
+ );
324
+ }
325
+ createPolygon(t) {
326
+ return new this.sdk.Polygon(
327
+ t.path.map((e) => this.toPoint(e)),
328
+ this.toPolygonStyle(t)
329
+ );
330
+ }
331
+ toMassPointLayerStyle(t) {
332
+ const e = t.style || {};
333
+ if (e.icon) {
334
+ const i = e.icon.width ?? e.size ?? 20, r = e.icon.height ?? e.size ?? 20;
335
+ return {
336
+ icon: e.icon.url,
337
+ width: i,
338
+ height: r,
339
+ offset: e.icon.anchor === "bottom-center" ? [0, -r / 2] : [0, 0],
340
+ unit: e.unit === "meter" ? "m" : "px",
341
+ opacity: e.opacity ?? 1,
342
+ renderOrder: t.zIndex ?? 100,
343
+ minZoom: t.minZoom ?? 3,
344
+ maxZoom: t.maxZoom ?? 21
345
+ };
346
+ }
347
+ return {
348
+ color: V(e.color || "#ff1a0a", e.opacity ?? 0.85),
349
+ shape: "circle",
350
+ size: e.size ?? 10,
351
+ unit: e.unit === "meter" ? "m" : "px",
352
+ borderWidth: e.borderWidth ?? 0,
353
+ borderColor: e.borderColor || "#ffffff",
354
+ renderOrder: t.zIndex ?? 100,
355
+ minZoom: t.minZoom ?? 3,
356
+ maxZoom: t.maxZoom ?? 21
357
+ };
358
+ }
359
+ createMassPointLayer(t) {
360
+ var r;
361
+ const e = (r = t.style) != null && r.icon ? this.mapVglSdk.IconLayer : this.mapVglSdk.PointLayer, i = new e(this.toMassPointLayerStyle(t));
362
+ return this.mapVglView.addLayer(i), i.setData(this.toMassPointData(t)), this.setMassPointLayerVisibility(i, t.visible !== !1), { layer: i };
363
+ }
364
+ toPolylineLayerStyle(t) {
365
+ const e = t.style || {};
366
+ return {
367
+ color: V(e.strokeColor || "#3366ff", e.strokeOpacity ?? 1),
368
+ width: e.strokeWeight ?? 3,
369
+ // MapVGL 1.0.0-beta.188 会直接读取 dashArray[1]。显式传入
370
+ // undefined 会覆盖其默认值并导致整个图层解析失败。
371
+ ...e.strokeStyle === "dashed" ? { dashArray: [10, 10] } : {},
372
+ renderOrder: t.zIndex ?? 90,
373
+ minZoom: t.minZoom ?? 3,
374
+ maxZoom: t.maxZoom ?? 21
375
+ };
376
+ }
377
+ toPolygonLayerStyle(t) {
378
+ const e = t.style || {};
379
+ return {
380
+ fillColor: e.fillColor || "#3366ff",
381
+ fillOpacity: e.fillOpacity ?? 0.3,
382
+ lineColor: V(e.strokeColor || "#3366ff", e.strokeOpacity ?? 1),
383
+ lineWidth: e.strokeWeight ?? 2,
384
+ ...e.strokeStyle === "dashed" ? { dashArray: [10, 10] } : {},
385
+ renderOrder: t.zIndex ?? 80,
386
+ minZoom: t.minZoom ?? 3,
387
+ maxZoom: t.maxZoom ?? 21
388
+ };
389
+ }
390
+ toPolylineLayerData(t) {
391
+ return t.polylines.map((e) => ({
392
+ geometry: {
393
+ type: "LineString",
394
+ coordinates: e.path.map((i) => [i[0], i[1]])
395
+ },
396
+ properties: e.properties || {}
397
+ }));
398
+ }
399
+ toPolygonLayerData(t) {
400
+ return t.polygons.map((e) => ({
401
+ geometry: { type: "Polygon", coordinates: [this.closeRing(e.path)] },
402
+ properties: e.properties || {}
403
+ }));
404
+ }
405
+ destroyVectorLayer(t) {
406
+ var e, i, r, s;
407
+ (i = (e = this.mapVglView) == null ? void 0 : e.removeLayer) == null || i.call(e, t.layer), (s = (r = t.layer) == null ? void 0 : r.clear) == null || s.call(r);
408
+ }
409
+ closeRing(t) {
410
+ const e = t[0], i = t[t.length - 1], r = t.map((s) => [s[0], s[1]]);
411
+ return e[0] === i[0] && e[1] === i[1] ? r : [...r, [e[0], e[1]]];
412
+ }
413
+ createScatterLayer(t) {
414
+ var a;
415
+ const e = document.createElement("canvas");
416
+ e.width = 1, e.height = 1;
417
+ const i = new this.mapVglSdk.IconLayer(this.toScatterLayerStyle(t, e)), r = new Image(), s = {
418
+ layer: i,
419
+ frames: [],
420
+ image: r,
421
+ animationFrame: null,
422
+ startedAt: 0,
423
+ lastFrame: -1,
424
+ options: t,
425
+ disposed: !1
426
+ };
427
+ return this.mapVglView.addLayer(i), i.setData(this.toMassPointData(t)), this.setMassPointLayerVisibility(i, t.visible !== !1), r.onload = () => this.prepareScatterFrames(s), r.onerror = () => {
428
+ s.disposed || console.error(`Baidu scatter texture failed to load: ${r.src}`);
429
+ }, r.src = ((a = t.style) == null ? void 0 : a.texture) || "/breath_red.png", s;
430
+ }
431
+ prepareScatterFrames(t) {
432
+ if (t.disposed)
433
+ return;
434
+ const e = t.image.height, i = e > 0 ? Math.floor(t.image.width / e) : 0;
435
+ if (i === 0) {
436
+ console.error("Baidu scatter texture must be a horizontal sequence of square frames");
437
+ return;
438
+ }
439
+ t.frames = Array.from({ length: i }, (r, s) => {
440
+ const a = document.createElement("canvas");
441
+ a.width = e, a.height = e;
442
+ const o = a.getContext("2d");
443
+ return o == null || o.drawImage(
444
+ t.image,
445
+ s * e,
446
+ 0,
447
+ e,
448
+ e,
449
+ 0,
450
+ 0,
451
+ e,
452
+ e
453
+ ), a;
454
+ }), t.startedAt = performance.now(), t.options.visible !== !1 && this.animateScatterLayer(t);
455
+ }
456
+ animateScatterLayer(t) {
457
+ var r;
458
+ if (t.disposed || t.frames.length === 0)
459
+ return;
460
+ const e = Math.max(1, ((r = t.options.style) == null ? void 0 : r.duration) ?? 2e3), i = (s) => {
461
+ var l, n;
462
+ if (t.disposed)
463
+ return;
464
+ const a = (s - t.startedAt) % e / e, o = Math.min(
465
+ t.frames.length - 1,
466
+ Math.floor(a * t.frames.length)
467
+ );
468
+ o !== t.lastFrame && (t.lastFrame = o, (n = (l = t.layer).setOptions) == null || n.call(
469
+ l,
470
+ this.toScatterLayerStyle(t.options, t.frames[o])
471
+ )), t.animationFrame = window.requestAnimationFrame(i);
472
+ };
473
+ t.animationFrame = window.requestAnimationFrame(i);
474
+ }
475
+ destroyScatterLayer(t) {
476
+ var e, i, r, s;
477
+ 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), (s = (r = t.layer) == null ? void 0 : r.clear) == null || s.call(r);
478
+ }
479
+ toScatterLayerStyle(t, e) {
480
+ const i = t.style || {};
481
+ return {
482
+ icon: e,
483
+ width: i.size ?? 40,
484
+ height: i.size ?? 40,
485
+ unit: i.unit === "meter" ? "m" : "px",
486
+ opacity: i.opacity ?? 1,
487
+ renderOrder: t.zIndex ?? 120,
488
+ minZoom: t.minZoom ?? 3,
489
+ maxZoom: t.maxZoom ?? 21
490
+ };
491
+ }
492
+ toMassPointData(t) {
493
+ return t.points.map((e) => ({
494
+ geometry: { type: "Point", coordinates: e.position },
495
+ properties: e.properties || {}
496
+ }));
497
+ }
498
+ setMassPointLayerVisibility(t, e) {
499
+ var i, r, s, a;
500
+ e ? (r = (i = this.mapVglView) == null ? void 0 : i.showLayer) == null || r.call(i, t) : (a = (s = this.mapVglView) == null ? void 0 : s.hideLayer) == null || a.call(s, t);
501
+ }
502
+ toPolylineStyle(t) {
503
+ return {
504
+ strokeColor: t.strokeColor || "#3366ff",
505
+ strokeWeight: t.strokeWeight ?? 5,
506
+ strokeOpacity: t.strokeOpacity ?? 1,
507
+ strokeStyle: t.strokeStyle || "solid",
508
+ enableClicking: !0
509
+ };
510
+ }
511
+ toPolygonStyle(t) {
512
+ const e = t;
513
+ return {
514
+ ...this.toPolylineStyle(t),
515
+ strokeWeight: t.strokeWeight ?? 3,
516
+ fillColor: e.fillColor || "#3366ff",
517
+ fillOpacity: e.fillOpacity ?? 0.3
518
+ };
519
+ }
520
+ startDrawingManager(t, e, i, r, s) {
521
+ const a = new t(this.map, {
522
+ isOpen: !1,
523
+ enableDrawingTool: !1,
524
+ polylineOptions: this.toPolylineStyle(i),
525
+ polygonOptions: this.toPolygonStyle(i)
526
+ }), o = (n) => {
527
+ const h = this.activeDraw;
528
+ if (!h || h.finished)
529
+ return;
530
+ const m = (n == null ? void 0 : n.overlay) || n, g = this.getPath(m);
531
+ !m || !g || (h.finished = !0, h.cleanup(!1), this.overlayKinds.set(m, e), this.activeDraw === h && (this.activeDraw = null), r(m, g));
532
+ }, l = {
533
+ finished: !1,
534
+ onCancel: s,
535
+ cleanup: () => {
536
+ var n, h;
537
+ (n = a.removeEventListener) == null || n.call(a, "overlaycomplete", o), (h = a.close) == null || h.call(a);
538
+ }
539
+ };
540
+ this.activeDraw = l, a.addEventListener("overlaycomplete", o), a.setDrawingMode(e), a.open();
541
+ }
542
+ /** DrawingManager 不可用时的轻量后备:单击加点,双击完成。 */
543
+ startManualDraw(t, e, i, r) {
544
+ var g, d;
545
+ const s = [];
546
+ let a = null;
547
+ const o = t === "polyline" ? 2 : 3, l = (c) => {
548
+ var u;
549
+ const p = (c == null ? void 0 : c.latlng) || (c == null ? void 0 : c.latLng) || (c == null ? void 0 : c.point);
550
+ if (!p)
551
+ return;
552
+ const w = s[s.length - 1];
553
+ w && w.lng === p.lng && w.lat === p.lat || (s.push(p), !a && s.length >= o ? (a = t === "polyline" ? new this.sdk.Polyline(s.slice(), this.toPolylineStyle(e)) : new this.sdk.Polygon(s.slice(), this.toPolygonStyle(e)), this.map.addOverlay(a)) : (u = a == null ? void 0 : a.setPath) == null || u.call(a, s.slice()));
554
+ }, n = (c) => l(c), h = (c) => {
555
+ var w, u;
556
+ (u = (w = c == null ? void 0 : c.domEvent) == null ? void 0 : w.preventDefault) == null || u.call(w), l(c);
557
+ const p = this.activeDraw;
558
+ !p || p.finished || !a || s.length < o || (p.finished = !0, p.cleanup(!1), this.overlayKinds.set(a, t), this.activeDraw === p && (this.activeDraw = null), i(a, this.getPath(a) || []));
559
+ }, m = {
560
+ finished: !1,
561
+ onCancel: r,
562
+ cleanup: (c = !1) => {
563
+ var p, w, u, E, k, O, P, D;
564
+ (w = (p = this.map) == null ? void 0 : p.removeEventListener) == null || w.call(p, "click", n), (E = (u = this.map) == null ? void 0 : u.removeEventListener) == null || E.call(u, "dblclick", h), (O = (k = this.map) == null ? void 0 : k.enableDoubleClickZoom) == null || O.call(k), c && a && ((D = (P = this.map) == null ? void 0 : P.removeOverlay) == null || D.call(P, a));
565
+ }
566
+ };
567
+ this.activeDraw = m, (d = (g = this.map).disableDoubleClickZoom) == null || d.call(g), this.map.addEventListener("click", n), this.map.addEventListener("dblclick", h);
568
+ }
569
+ finishEdit(t) {
570
+ var r, s;
571
+ if (t.stopped)
572
+ return;
573
+ const e = this.getPath(t.native);
574
+ e && t.onChange(e), t.stopped = !0;
575
+ const i = t.native;
576
+ (r = i.removeEventListener) == null || r.call(i, "lineupdate", t.handler), (s = i.disableEditing) == null || s.call(i), this.activeEdit === t && (this.activeEdit = null);
577
+ }
578
+ }
579
+ export {
580
+ _ as BMapAdapter
581
+ };
@@ -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
+ };