@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,863 @@
1
+ var E = Object.defineProperty;
2
+ var R = (g, e, t) => e in g ? E(g, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : g[e] = t;
3
+ var h = (g, e, t) => (R(g, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import "@arcgis/core/assets/esri/themes/light/main.css";
5
+ import p from "@arcgis/core/Graphic";
6
+ import L from "@arcgis/core/geometry/Point";
7
+ import O from "@arcgis/core/geometry/Polygon";
8
+ import I from "@arcgis/core/geometry/Polyline";
9
+ import { xyToLngLat as T } from "@arcgis/core/geometry/support/webMercatorUtils";
10
+ import k from "@arcgis/core/layers/FeatureLayer";
11
+ import A from "@arcgis/core/symbols/PictureMarkerSymbol";
12
+ import D from "@arcgis/core/symbols/CIMSymbol";
13
+ import V from "@arcgis/core/symbols/SimpleFillSymbol";
14
+ import b from "@arcgis/core/symbols/SimpleLineSymbol";
15
+ import P from "@arcgis/core/symbols/SimpleMarkerSymbol";
16
+ import w from "@arcgis/core/renderers/SimpleRenderer";
17
+ import x from "@arcgis/core/widgets/Sketch/SketchViewModel";
18
+ import F from "@arcgis/core/Map";
19
+ import G from "@arcgis/core/views/MapView";
20
+ import W from "@arcgis/core/layers/GraphicsLayer";
21
+ import { M as c, a as v } from "./index-5b75eace.js";
22
+ import { a as d } from "./color-128d7dff.js";
23
+ import "vue";
24
+ class N {
25
+ constructor() {
26
+ this.map = null, this.mapView = null, this.graphicsLayer = null, this.clickHandler = null, this.Graphic = p, this.Point = L, this.Polyline = I, this.Polygon = O, this.SimpleMarkerSymbol = P, this.SimpleLineSymbol = b, this.SimpleFillSymbol = V, this.SketchViewModel = x;
27
+ }
28
+ /**
29
+ * 创建地图
30
+ * @param {string|HTMLElement} container - 地图容器
31
+ * @param {Object} options - 地图配置
32
+ * @returns {Promise<Object>} 地图实例
33
+ */
34
+ async createMap(e, t = {}) {
35
+ const {
36
+ center: i = [116.404, 39.915],
37
+ zoom: r = 15,
38
+ basemap: a = null,
39
+ // 默认空白底图
40
+ enableClick: s = !0
41
+ } = t, o = typeof e == "string" ? e : e.id;
42
+ if (!o)
43
+ throw new Error("地图容器必须有id属性");
44
+ return this.map = new F({
45
+ basemap: a
46
+ // null 表示空白底图
47
+ }), this.mapView = new G({
48
+ container: o,
49
+ map: this.map,
50
+ center: i,
51
+ zoom: r
52
+ }), this.graphicsLayer = new W({
53
+ elevationInfo: { mode: "on-the-ground" }
54
+ // ✅ 确保图形贴地显示
55
+ }), this.map.add(this.graphicsLayer), s && console.warn('⚠️ ArcGIS 自动点击打点已禁用,请使用 MapManager.on("click") 事件'), await this.mapView.when(), console.log("地图创建成功(ArcGIS 4.x)"), {
56
+ map: this.map,
57
+ mapView: this.mapView,
58
+ graphicsLayer: this.graphicsLayer
59
+ };
60
+ }
61
+ /**
62
+ * 添加点标记
63
+ * @param {Object|number[]} point - ArcGIS Point对象或坐标数组 [lng, lat]
64
+ * @param {Object} options - 标记样式配置
65
+ */
66
+ addPoint(e, t = {}) {
67
+ if (!this.mapView || !this.graphicsLayer)
68
+ throw new Error("地图未初始化,请先调用createMap");
69
+ let i;
70
+ e.longitude !== void 0 && e.latitude !== void 0 ? i = e : Array.isArray(e) ? i = new L({
71
+ longitude: e[0],
72
+ latitude: e[1]
73
+ }) : i = new L(e);
74
+ const r = new P({
75
+ color: t.color || "red",
76
+ size: t.size || 12,
77
+ outline: {
78
+ color: t.outlineColor || "white",
79
+ width: t.outlineWidth || 2
80
+ }
81
+ }), a = new p({
82
+ geometry: i,
83
+ symbol: r,
84
+ attributes: t.attributes || {}
85
+ });
86
+ return this.graphicsLayer.add(a), console.log("添加点标记:", i.longitude, i.latitude), a;
87
+ }
88
+ /**
89
+ * 添加线段
90
+ * @param {Array<Array<number>>} points - 经纬度坐标数组 [[lng1, lat1], [lng2, lat2], ...]
91
+ * @param {Object} options - 线段样式配置
92
+ * @param {string} options.color - 线段颜色(十六进制或颜色名称)
93
+ * @param {number} options.width - 线宽(像素)
94
+ * @param {number} options.opacity - 透明度 (0-1)
95
+ * @returns {Graphic} 线段Graphic对象
96
+ */
97
+ addPolyline(e, t = {}) {
98
+ if (!this.mapView || !this.graphicsLayer)
99
+ throw new Error("地图未初始化,请先调用createMap");
100
+ const i = (o) => {
101
+ if (Array.isArray(o))
102
+ return o;
103
+ let l = o || "#3366FF";
104
+ l = l.replace("#", "");
105
+ const n = parseInt(l.substring(0, 2), 16), f = parseInt(l.substring(2, 4), 16), u = parseInt(l.substring(4, 6), 16);
106
+ return [n, f, u];
107
+ }, r = new I({
108
+ paths: [e.map((o) => [o[0], o[1]])]
109
+ // ArcGIS Polyline paths 格式
110
+ }), a = new b({
111
+ color: i(t.color),
112
+ width: t.width || 5,
113
+ style: "solid"
114
+ });
115
+ if (t.opacity && t.opacity < 1) {
116
+ const o = i(t.color);
117
+ a.color = [...o, t.opacity];
118
+ }
119
+ const s = new p({
120
+ geometry: r,
121
+ symbol: a,
122
+ attributes: t.attributes || {}
123
+ });
124
+ return this.graphicsLayer.add(s), console.log("添加线段:", e.length, "个点"), s;
125
+ }
126
+ /**
127
+ * 添加圆形标记(用于绘制节点)
128
+ * @param {Array<number>} lnglat - [lng, lat]
129
+ * @param {Object} options - 标记样式配置
130
+ * @param {string} options.color - 标记颜色(十六进制)
131
+ * @param {number} options.radius - 标记半径(像素)
132
+ * @param {string} options.strokeColor - 边框颜色(十六进制)
133
+ * @param {number} options.strokeWidth - 边框宽度(像素)
134
+ * @returns {Graphic} 标记Graphic对象
135
+ */
136
+ addCircleMarker(e, t = {}) {
137
+ if (!this.mapView || !this.graphicsLayer)
138
+ throw new Error("地图未初始化,请先调用createMap");
139
+ const i = this.SimpleMarkerSymbol, r = this.Graphic, a = this.Point, s = (m) => {
140
+ if (Array.isArray(m))
141
+ return m;
142
+ let y = m || "#FF0000";
143
+ y = y.replace("#", "");
144
+ const _ = parseInt(y.substring(0, 2), 16), M = parseInt(y.substring(2, 4), 16), C = parseInt(y.substring(4, 6), 16);
145
+ return [_, M, C];
146
+ }, o = s(t.color || "#FF0000"), l = t.radius || 4, n = s(t.strokeColor || "#FFFFFF"), f = t.strokeWidth || 2, u = new a({
147
+ longitude: e[0],
148
+ latitude: e[1]
149
+ }), z = new i({
150
+ style: "circle",
151
+ color: o,
152
+ size: l,
153
+ outline: {
154
+ color: n,
155
+ width: f
156
+ }
157
+ }), S = new r({
158
+ geometry: u,
159
+ symbol: z
160
+ });
161
+ return this.graphicsLayer.add(S), S;
162
+ }
163
+ /**
164
+ * ✅ 新增:添加多边形(用于绘制和编辑)
165
+ * @param {Array<Array<number>>} points - 多边形顶点数组 [[lng, lat], [lng, lat], ...]
166
+ * @param {Object} options - 多边形样式配置
167
+ * @param {string} options.fillColor - 填充颜色(十六进制)
168
+ * @param {number} options.fillOpacity - 填充透明度(0-1)
169
+ * @param {string} options.strokeColor - 边框颜色(十六进制)
170
+ * @param {number} options.strokeWidth - 边框宽度(像素)
171
+ * @returns {Graphic} 多边形Graphic对象
172
+ */
173
+ addPolygon(e, t = {}) {
174
+ if (!this.mapView || !this.graphicsLayer)
175
+ throw new Error("地图未初始化,请先调用createMap");
176
+ const i = this.Polygon, r = this.SimpleFillSymbol, a = this.Graphic, s = (m) => {
177
+ if (Array.isArray(m))
178
+ return m;
179
+ let y = m || "#3366FF";
180
+ y = y.replace("#", "");
181
+ const _ = parseInt(y.substring(0, 2), 16), M = parseInt(y.substring(2, 4), 16), C = parseInt(y.substring(4, 6), 16);
182
+ return [_, M, C];
183
+ }, o = s(t.fillColor || "#3366FF"), l = t.fillOpacity || 0.3, n = s(t.strokeColor || "#3366FF"), f = t.strokeWidth || 5, u = new i({
184
+ rings: [e.map((m) => [m[0], m[1]])]
185
+ // ArcGIS 使用 rings 属性
186
+ }), z = new r({
187
+ color: [...o, l],
188
+ // ✅ RGBA 格式(支持透明度)
189
+ outline: {
190
+ color: n,
191
+ width: f
192
+ }
193
+ }), S = new a({
194
+ geometry: u,
195
+ symbol: z
196
+ });
197
+ return this.graphicsLayer.add(S), console.log("添加多边形:", e.length, "个顶点"), S;
198
+ }
199
+ /**
200
+ * 清除所有点标记
201
+ */
202
+ clearPoints() {
203
+ this.graphicsLayer && this.graphicsLayer.removeAll();
204
+ }
205
+ /**
206
+ * 设置地图中心
207
+ * @param {number[]} center - [lng, lat]
208
+ */
209
+ setCenter(e) {
210
+ this.mapView && (this.mapView.center = e);
211
+ }
212
+ /**
213
+ * 设置缩放级别
214
+ * @param {number} zoom
215
+ */
216
+ setZoom(e) {
217
+ this.mapView && (this.mapView.zoom = e);
218
+ }
219
+ /**
220
+ * 销毁地图
221
+ */
222
+ destroy() {
223
+ this.mapView && (this.mapView.destroy(), this.mapView = null, this.map = null, this.graphicsLayer = null);
224
+ }
225
+ }
226
+ class ce {
227
+ constructor() {
228
+ h(this, "coordinateSystem", "wgs84");
229
+ h(this, "loader", new N());
230
+ h(this, "mapView", null);
231
+ h(this, "graphicsLayer", null);
232
+ h(this, "sketchViewModel", null);
233
+ h(this, "mapClickHandles", /* @__PURE__ */ new Set());
234
+ h(this, "overlayClickCallbacks", /* @__PURE__ */ new Map());
235
+ h(this, "hitTestHandle", null);
236
+ h(this, "activeDraw", null);
237
+ h(this, "activeEdit", null);
238
+ h(this, "overlayKinds", /* @__PURE__ */ new WeakMap());
239
+ h(this, "massPointLayers", /* @__PURE__ */ new Set());
240
+ h(this, "scatterLayers", /* @__PURE__ */ new Set());
241
+ h(this, "polylineLayers", /* @__PURE__ */ new Set());
242
+ h(this, "polygonLayers", /* @__PURE__ */ new Set());
243
+ }
244
+ async init(e) {
245
+ const t = this.resolveContainer(e.container);
246
+ try {
247
+ const i = await this.loader.createMap(t, {
248
+ center: e.center || [116.397428, 39.90923],
249
+ zoom: e.zoom ?? 12,
250
+ basemap: e.basemap || "osm",
251
+ useTianditu: !1,
252
+ enableClick: !1
253
+ });
254
+ this.mapView = i.mapView, this.graphicsLayer = i.graphicsLayer;
255
+ } catch (i) {
256
+ throw this.mapView = null, this.graphicsLayer = null, new c("SDK_ERROR", "Failed to initialize ArcGIS", { cause: i });
257
+ }
258
+ }
259
+ destroy() {
260
+ var e;
261
+ this.activeEdit && this.finishEdit(this.activeEdit, !1), this.cancelDraw();
262
+ for (const t of this.mapClickHandles)
263
+ t.remove();
264
+ this.mapClickHandles.clear(), (e = this.hitTestHandle) == null || e.remove(), this.hitTestHandle = null, this.overlayClickCallbacks.clear(), this.resetSketchViewModel();
265
+ for (const t of [...this.massPointLayers])
266
+ this.destroyMassPointLayer(t);
267
+ this.massPointLayers.clear();
268
+ for (const t of [...this.scatterLayers])
269
+ this.destroyScatterLayer(t);
270
+ this.scatterLayers.clear();
271
+ for (const t of [...this.polylineLayers])
272
+ this.destroyVectorLayer(t);
273
+ this.polylineLayers.clear();
274
+ for (const t of [...this.polygonLayers])
275
+ this.destroyVectorLayer(t);
276
+ this.polygonLayers.clear(), this.loader.destroy(), this.mapView = null, this.graphicsLayer = null;
277
+ }
278
+ addMarker(e) {
279
+ const t = this.createMarker(e);
280
+ return this.graphicsLayer.add(t), this.remember(t, "marker"), t;
281
+ }
282
+ addPolyline(e) {
283
+ const t = this.createPolyline(e);
284
+ return this.graphicsLayer.add(t), this.remember(t, "polyline"), t;
285
+ }
286
+ addPolygon(e) {
287
+ const t = this.createPolygon(e);
288
+ return this.graphicsLayer.add(t), this.remember(t, "polygon"), t;
289
+ }
290
+ addPolylineLayer(e) {
291
+ const t = this.createPolylineLayer(e);
292
+ return this.addVisualizationLayer(t), this.polylineLayers.add(t), this.reorderVisualizationLayers(), t;
293
+ }
294
+ updatePolylineLayer(e, t, i) {
295
+ const r = e;
296
+ if (!this.polylineLayers.has(r))
297
+ throw new c("OVERLAY_NOT_FOUND", "Polyline layer is no longer registered");
298
+ return "polylines" in i ? (this.replaceVisualizationLayer(r, this.createPolylineLayer(t)), e) : (r.layer.renderer = new w({ symbol: this.createPolylineLayerSymbol(t) }), this.updateVisualizationLayerOptions(r, t, 90), e);
299
+ }
300
+ removePolylineLayer(e) {
301
+ const t = e;
302
+ this.polylineLayers.has(t) && (this.destroyVectorLayer(t), this.polylineLayers.delete(t));
303
+ }
304
+ addPolygonLayer(e) {
305
+ const t = this.createPolygonLayer(e);
306
+ return this.addVisualizationLayer(t), this.polygonLayers.add(t), this.reorderVisualizationLayers(), t;
307
+ }
308
+ updatePolygonLayer(e, t, i) {
309
+ const r = e;
310
+ if (!this.polygonLayers.has(r))
311
+ throw new c("OVERLAY_NOT_FOUND", "Polygon layer is no longer registered");
312
+ return "polygons" in i ? (this.replaceVisualizationLayer(r, this.createPolygonLayer(t)), e) : (r.layer.renderer = new w({ symbol: this.createPolygonLayerSymbol(t) }), this.updateVisualizationLayerOptions(r, t, 80), e);
313
+ }
314
+ removePolygonLayer(e) {
315
+ const t = e;
316
+ this.polygonLayers.has(t) && (this.destroyVectorLayer(t), this.polygonLayers.delete(t));
317
+ }
318
+ addMassPoints(e) {
319
+ var a;
320
+ const t = this.createMassPointLayer(e), i = (a = this.mapView) == null ? void 0 : a.map;
321
+ if (!i)
322
+ throw new c("SDK_ERROR", "ArcGIS map is unavailable");
323
+ const r = i.layers.indexOf(this.graphicsLayer);
324
+ return r >= 0 ? i.add(t.layer, r) : i.add(t.layer), this.massPointLayers.add(t), this.reorderVisualizationLayers(), t;
325
+ }
326
+ updateMassPoints(e, t, i) {
327
+ var n;
328
+ const r = e;
329
+ if (!this.massPointLayers.has(r))
330
+ throw new c("OVERLAY_NOT_FOUND", "Mass point layer is no longer registered");
331
+ const a = (n = this.mapView) == null ? void 0 : n.map;
332
+ if (!a)
333
+ throw new c("SDK_ERROR", "ArcGIS map is unavailable");
334
+ if (!("points" in i))
335
+ return r.layer.renderer = new w({ symbol: this.createMassPointSymbol(t) }), r.layer.visible = t.visible !== !1, r.layer.minScale = this.zoomToScale(t.minZoom ?? 3), r.layer.maxScale = this.zoomToScale(t.maxZoom ?? 21), r.zIndex = t.zIndex ?? 100, this.reorderVisualizationLayers(), e;
336
+ const s = this.createMassPointLayer(t), o = r.layer, l = a.layers.indexOf(o);
337
+ return a.remove(o), l >= 0 ? a.add(s.layer, l) : a.add(s.layer), o.destroy(), r.layer = s.layer, r.zIndex = s.zIndex, this.reorderVisualizationLayers(), e;
338
+ }
339
+ removeMassPoints(e) {
340
+ const t = e;
341
+ this.massPointLayers.has(t) && (this.destroyMassPointLayer(t), this.massPointLayers.delete(t));
342
+ }
343
+ addScatterLayer(e) {
344
+ var a;
345
+ const t = (a = this.mapView) == null ? void 0 : a.map;
346
+ if (!t)
347
+ throw new c("SDK_ERROR", "ArcGIS map is unavailable");
348
+ const i = this.createScatterLayer(e), r = t.layers.indexOf(this.graphicsLayer);
349
+ return r >= 0 ? t.add(i.layer, r) : t.add(i.layer), this.scatterLayers.add(i), this.reorderVisualizationLayers(), i;
350
+ }
351
+ updateScatterLayer(e, t, i) {
352
+ var n;
353
+ const r = e;
354
+ if (!this.scatterLayers.has(r))
355
+ throw new c("OVERLAY_NOT_FOUND", "Scatter layer is no longer registered");
356
+ const a = (n = this.mapView) == null ? void 0 : n.map;
357
+ if (!a)
358
+ throw new c("SDK_ERROR", "ArcGIS map is unavailable");
359
+ if (!("points" in i))
360
+ return r.layer.renderer = new w({ symbol: this.createScatterSymbol(t) }), r.layer.visible = t.visible !== !1, r.layer.minScale = this.zoomToScale(t.minZoom ?? 3), r.layer.maxScale = this.zoomToScale(t.maxZoom ?? 21), r.zIndex = t.zIndex ?? 120, this.reorderVisualizationLayers(), e;
361
+ const s = this.createScatterLayer(t), o = r.layer, l = a.layers.indexOf(o);
362
+ return a.remove(o), l >= 0 ? a.add(s.layer, l) : a.add(s.layer), o.destroy(), r.layer = s.layer, r.zIndex = s.zIndex, this.reorderVisualizationLayers(), e;
363
+ }
364
+ removeScatterLayer(e) {
365
+ const t = e;
366
+ this.scatterLayers.has(t) && (this.destroyScatterLayer(t), this.scatterLayers.delete(t));
367
+ }
368
+ updateOverlay(e, t, i) {
369
+ const r = this.overlayKinds.get(e);
370
+ if (!r)
371
+ throw new c("OVERLAY_NOT_FOUND", "Overlay is no longer registered");
372
+ const a = e, s = r === "marker" ? this.createMarker(t) : r === "polyline" ? this.createPolyline(t) : this.createPolygon(t);
373
+ return a.symbol = s.symbol, (r === "marker" && "position" in i || r !== "marker" && "path" in i) && (a.geometry = s.geometry), e;
374
+ }
375
+ removeOverlay(e) {
376
+ var i;
377
+ const t = this.activeEdit;
378
+ t && t.native === e && this.finishEdit(t, !1), (i = this.graphicsLayer) == null || i.remove(e), this.overlayClickCallbacks.delete(e), e && (typeof e == "object" || typeof e == "function") && this.overlayKinds.delete(e);
379
+ }
380
+ getPath(e) {
381
+ var a, s;
382
+ const t = e == null ? void 0 : e.geometry, i = ((a = t == null ? void 0 : t.paths) == null ? void 0 : a[0]) || ((s = t == null ? void 0 : t.rings) == null ? void 0 : s[0]);
383
+ if (!i)
384
+ return null;
385
+ const r = i.map((o) => this.toLngLat(o[0], o[1], t.spatialReference));
386
+ if (t.type === "polygon" && r.length > 1) {
387
+ const o = r[0], l = r[r.length - 1];
388
+ o[0] === l[0] && o[1] === l[1] && r.pop();
389
+ }
390
+ return r;
391
+ }
392
+ getPosition(e) {
393
+ const t = e == null ? void 0 : e.geometry;
394
+ return !t || t.type !== "point" ? null : this.toLngLat(t.x, t.y, t.spatialReference);
395
+ }
396
+ onMapClick(e) {
397
+ let t = !0;
398
+ const i = this.mapView.on("click", (r) => {
399
+ if (!r.mapPoint)
400
+ return;
401
+ const a = this.toLngLat(
402
+ r.mapPoint.x,
403
+ r.mapPoint.y,
404
+ r.mapPoint.spatialReference
405
+ ), s = {
406
+ lnglat: { lng: a[0], lat: a[1] },
407
+ position: a,
408
+ coordinateSystem: this.coordinateSystem,
409
+ originalEvent: r
410
+ };
411
+ this.mapView.hitTest(r).then((o) => {
412
+ var n;
413
+ if (!t)
414
+ return;
415
+ const l = (n = o.results) == null ? void 0 : n.find((f) => {
416
+ const u = f == null ? void 0 : f.graphic;
417
+ return u && this.overlayKinds.has(u);
418
+ });
419
+ e(s, l == null ? void 0 : l.graphic);
420
+ }).catch((o) => {
421
+ t && (console.error("ArcGIS hitTest failed", o), e(s));
422
+ });
423
+ });
424
+ return this.mapClickHandles.add(i), () => {
425
+ t = !1, i.remove(), this.mapClickHandles.delete(i);
426
+ };
427
+ }
428
+ onOverlayClick(e, t) {
429
+ let i = this.overlayClickCallbacks.get(e);
430
+ return i || (i = /* @__PURE__ */ new Set(), this.overlayClickCallbacks.set(e, i)), i.add(t), this.ensureHitTestListener(), () => {
431
+ var a;
432
+ const r = this.overlayClickCallbacks.get(e);
433
+ r == null || r.delete(t), r && r.size === 0 && this.overlayClickCallbacks.delete(e), this.overlayClickCallbacks.size === 0 && ((a = this.hitTestHandle) == null || a.remove(), this.hitTestHandle = null);
434
+ };
435
+ }
436
+ startEdit(e, t, i) {
437
+ if (this.overlayKinds.get(e) !== t)
438
+ throw new c("INVALID_OPTIONS", "Only polyline and polygon overlays can be edited");
439
+ this.activeDraw && this.cancelDraw(), this.activeEdit && this.finishEdit(this.activeEdit, !0);
440
+ const r = this.getSketchViewModel(), a = { id: Symbol("arcgis-edit"), native: e, sketch: r, handle: null, onChange: i, finished: !1 }, s = r.on("update", (o) => {
441
+ var n;
442
+ if (a.finished || !((n = o.graphics) != null && n.includes(e)))
443
+ return;
444
+ const l = this.getPath(e);
445
+ l && a.onChange(l), (o.state === "complete" || o.state === "cancel") && this.finishEdit(a, !1);
446
+ });
447
+ a.handle = s, this.activeEdit = a;
448
+ try {
449
+ r.update([e], { tool: "reshape" }).catch((o) => {
450
+ a.finished || this.finishEdit(a, !1), console.error(`ArcGIS ${t} editing failed`, o);
451
+ });
452
+ } catch (o) {
453
+ throw this.finishEdit(a, !1), new c("SDK_ERROR", `Failed to start ArcGIS ${t} editing`, { cause: o });
454
+ }
455
+ return () => this.finishEdit(a, !0);
456
+ }
457
+ startDraw(e, t, i, r) {
458
+ if (this.activeDraw)
459
+ throw new c("DRAW_IN_PROGRESS", "A drawing operation is already active");
460
+ this.activeEdit && this.finishEdit(this.activeEdit, !0), this.resetSketchViewModel();
461
+ const a = this.getSketchViewModel();
462
+ this.applyDrawStyle(a, e, t);
463
+ const s = { id: Symbol("arcgis-draw"), sketch: a, handle: null, onCancel: r, finished: !1 }, o = a.on("create", (l) => {
464
+ if (s.finished)
465
+ return;
466
+ if (l.state === "cancel") {
467
+ this.finishDraw(s), r();
468
+ return;
469
+ }
470
+ if (l.state !== "complete" || !l.graphic)
471
+ return;
472
+ this.remember(l.graphic, e);
473
+ const n = this.getPath(l.graphic) || [];
474
+ this.finishDraw(s), i(l.graphic, n);
475
+ });
476
+ s.handle = o, this.activeDraw = s;
477
+ try {
478
+ a.create(e, { mode: "click" }).catch((l) => {
479
+ s.finished || (this.finishDraw(s), s.onCancel()), console.error("ArcGIS drawing failed", l);
480
+ });
481
+ } catch (l) {
482
+ throw this.finishDraw(s), new c("SDK_ERROR", "Failed to start ArcGIS drawing", { cause: l });
483
+ }
484
+ }
485
+ cancelDraw() {
486
+ const e = this.activeDraw;
487
+ e && (e.sketch.cancel(), e.finished || (this.finishDraw(e), e.onCancel()));
488
+ }
489
+ setCenter(e) {
490
+ this.mapView.center = e;
491
+ }
492
+ getCenter() {
493
+ const e = this.mapView.center;
494
+ return v([e.longitude, e.latitude]);
495
+ }
496
+ setZoom(e) {
497
+ this.mapView.zoom = e;
498
+ }
499
+ getZoom() {
500
+ return this.mapView.zoom;
501
+ }
502
+ resolveContainer(e) {
503
+ if (typeof e == "string") {
504
+ if (!document.getElementById(e))
505
+ throw new c("INVALID_OPTIONS", `Container not found: ${e}`);
506
+ return e;
507
+ }
508
+ if (!e)
509
+ throw new c("INVALID_OPTIONS", "A map container is required");
510
+ return e.id || (e.id = `unified-map-${Math.random().toString(36).slice(2)}`), e.id;
511
+ }
512
+ remember(e, t) {
513
+ this.overlayKinds.set(e, t);
514
+ }
515
+ createMarker(e) {
516
+ const t = e.style || { kind: "circle" }, i = new L({ longitude: e.position[0], latitude: e.position[1] }), r = t.kind === "icon" ? new A({
517
+ url: t.url,
518
+ width: t.width,
519
+ height: t.height,
520
+ yoffset: t.anchor === "bottom-center" ? t.height / 2 : 0
521
+ }) : new P({
522
+ style: "circle",
523
+ size: (t.radius ?? 8) * 2,
524
+ color: d(t.fillColor || "#1677ff", t.fillOpacity ?? 0.8),
525
+ outline: {
526
+ color: d(t.strokeColor || "#ffffff"),
527
+ width: t.strokeWeight ?? 2
528
+ }
529
+ });
530
+ return new p({ geometry: i, symbol: r });
531
+ }
532
+ createPolyline(e) {
533
+ return new p({
534
+ geometry: new I({ paths: [e.path.map((t) => [t[0], t[1]])], spatialReference: { wkid: 4326 } }),
535
+ symbol: new b({
536
+ color: d(e.strokeColor || "#3366ff", e.strokeOpacity ?? 1),
537
+ width: e.strokeWeight ?? 5,
538
+ style: e.strokeStyle === "dashed" ? "dash" : "solid"
539
+ })
540
+ });
541
+ }
542
+ createPolygon(e) {
543
+ const t = e.path.map((i) => [i[0], i[1]]);
544
+ return t.length > 0 && (t[0][0] !== t[t.length - 1][0] || t[0][1] !== t[t.length - 1][1]) && t.push(t[0]), new p({
545
+ geometry: new O({ rings: [t], spatialReference: { wkid: 4326 } }),
546
+ symbol: new V({
547
+ color: d(e.fillColor || "#3366ff", e.fillOpacity ?? 0.3),
548
+ outline: {
549
+ color: d(e.strokeColor || "#3366ff", e.strokeOpacity ?? 1),
550
+ width: e.strokeWeight ?? 3,
551
+ style: e.strokeStyle === "dashed" ? "dash" : "solid"
552
+ }
553
+ })
554
+ });
555
+ }
556
+ createMassPointLayer(e) {
557
+ const t = e.points.map((r, a) => new p({
558
+ geometry: new L({
559
+ longitude: r.position[0],
560
+ latitude: r.position[1],
561
+ spatialReference: { wkid: 4326 }
562
+ }),
563
+ attributes: {
564
+ ...r.properties || {},
565
+ __unified_object_id: a + 1
566
+ }
567
+ })), i = new k({
568
+ ...e.id ? { id: e.id, title: e.id } : {},
569
+ source: t,
570
+ fields: [{
571
+ name: "__unified_object_id",
572
+ alias: "Object ID",
573
+ type: "oid"
574
+ }],
575
+ objectIdField: "__unified_object_id",
576
+ geometryType: "point",
577
+ spatialReference: { wkid: 4326 },
578
+ renderer: new w({ symbol: this.createMassPointSymbol(e) }),
579
+ popupEnabled: !1,
580
+ visible: e.visible !== !1,
581
+ // ArcGIS 使用比例尺分母:minScale 是最远可见范围(较大的数),
582
+ // maxScale 是最近可见范围(较小的数),方向与 zoom 数值相反。
583
+ minScale: this.zoomToScale(e.minZoom ?? 3),
584
+ maxScale: this.zoomToScale(e.maxZoom ?? 21)
585
+ });
586
+ return i.load().catch((r) => {
587
+ console.error("ArcGIS mass point layer failed to load", r);
588
+ }), { layer: i, zIndex: e.zIndex ?? 100 };
589
+ }
590
+ createPolylineLayer(e) {
591
+ const t = e.polylines.map((r, a) => new p({
592
+ geometry: new I({
593
+ paths: [r.path.map((s) => [s[0], s[1]])],
594
+ spatialReference: { wkid: 4326 }
595
+ }),
596
+ attributes: {
597
+ ...r.properties || {},
598
+ __unified_polyline_id: a + 1
599
+ }
600
+ })), i = new k({
601
+ ...e.id ? { id: e.id, title: e.id } : {},
602
+ source: t,
603
+ fields: [{ name: "__unified_polyline_id", alias: "Object ID", type: "oid" }],
604
+ objectIdField: "__unified_polyline_id",
605
+ geometryType: "polyline",
606
+ spatialReference: { wkid: 4326 },
607
+ renderer: new w({ symbol: this.createPolylineLayerSymbol(e) }),
608
+ popupEnabled: !1,
609
+ visible: e.visible !== !1,
610
+ minScale: this.zoomToScale(e.minZoom ?? 3),
611
+ maxScale: this.zoomToScale(e.maxZoom ?? 21)
612
+ });
613
+ return i.load().catch((r) => console.error("ArcGIS polyline layer failed to load", r)), { layer: i, zIndex: e.zIndex ?? 90 };
614
+ }
615
+ createPolylineLayerSymbol(e) {
616
+ const t = e.style || {};
617
+ return new b({
618
+ color: d(t.strokeColor || "#3366ff", t.strokeOpacity ?? 1),
619
+ width: t.strokeWeight ?? 3,
620
+ style: t.strokeStyle === "dashed" ? "dash" : "solid"
621
+ });
622
+ }
623
+ createPolygonLayer(e) {
624
+ const t = e.polygons.map((r, a) => new p({
625
+ geometry: new O({
626
+ rings: [this.closeRing(r.path).map(([s, o]) => [s, o])],
627
+ spatialReference: { wkid: 4326 }
628
+ }),
629
+ attributes: {
630
+ ...r.properties || {},
631
+ __unified_polygon_id: a + 1
632
+ }
633
+ })), i = new k({
634
+ ...e.id ? { id: e.id, title: e.id } : {},
635
+ source: t,
636
+ fields: [{ name: "__unified_polygon_id", alias: "Object ID", type: "oid" }],
637
+ objectIdField: "__unified_polygon_id",
638
+ geometryType: "polygon",
639
+ spatialReference: { wkid: 4326 },
640
+ renderer: new w({ symbol: this.createPolygonLayerSymbol(e) }),
641
+ popupEnabled: !1,
642
+ visible: e.visible !== !1,
643
+ minScale: this.zoomToScale(e.minZoom ?? 3),
644
+ maxScale: this.zoomToScale(e.maxZoom ?? 21)
645
+ });
646
+ return i.load().catch((r) => console.error("ArcGIS polygon layer failed to load", r)), { layer: i, zIndex: e.zIndex ?? 80 };
647
+ }
648
+ createPolygonLayerSymbol(e) {
649
+ const t = e.style || {};
650
+ return new V({
651
+ color: d(t.fillColor || "#3366ff", t.fillOpacity ?? 0.3),
652
+ outline: {
653
+ color: d(t.strokeColor || "#3366ff", t.strokeOpacity ?? 1),
654
+ width: t.strokeWeight ?? 2,
655
+ style: t.strokeStyle === "dashed" ? "dash" : "solid"
656
+ }
657
+ });
658
+ }
659
+ createMassPointSymbol(e) {
660
+ const t = e.style || {};
661
+ return new P({
662
+ style: "circle",
663
+ size: t.size ?? 10,
664
+ color: d(t.color || "#1677ff", t.opacity ?? 0.85),
665
+ outline: {
666
+ color: d(t.borderColor || "#ffffff"),
667
+ width: t.borderWidth ?? 0
668
+ }
669
+ });
670
+ }
671
+ createScatterLayer(e) {
672
+ const t = e.points.map((r, a) => new p({
673
+ geometry: new L({
674
+ longitude: r.position[0],
675
+ latitude: r.position[1],
676
+ spatialReference: { wkid: 4326 }
677
+ }),
678
+ attributes: {
679
+ ...r.properties || {},
680
+ __unified_scatter_id: a + 1
681
+ }
682
+ })), i = new k({
683
+ ...e.id ? { id: e.id, title: e.id } : {},
684
+ source: t,
685
+ fields: [{ name: "__unified_scatter_id", alias: "Object ID", type: "oid" }],
686
+ objectIdField: "__unified_scatter_id",
687
+ geometryType: "point",
688
+ spatialReference: { wkid: 4326 },
689
+ renderer: new w({ symbol: this.createScatterSymbol(e) }),
690
+ popupEnabled: !1,
691
+ visible: e.visible !== !1,
692
+ minScale: this.zoomToScale(e.minZoom ?? 3),
693
+ maxScale: this.zoomToScale(e.maxZoom ?? 21)
694
+ });
695
+ return i.load().catch((r) => {
696
+ console.error("ArcGIS scatter layer failed to load", r);
697
+ }), { layer: i, zIndex: e.zIndex ?? 120 };
698
+ }
699
+ createScatterSymbol(e) {
700
+ const t = e.style || {}, i = t.size ?? 40, r = (t.duration ?? 2e3) / 1e3, a = (t.repeatDelay ?? 0) / 1e3, s = {
701
+ type: "CIMAnimatedSymbolProperties",
702
+ playAnimation: !0,
703
+ randomizeStartTime: t.randomizeStartTime ?? !1,
704
+ repeatType: "Loop",
705
+ repeatDelay: a,
706
+ duration: r
707
+ };
708
+ return new D({
709
+ data: {
710
+ type: "CIMSymbolReference",
711
+ symbol: {
712
+ type: "CIMPointSymbol",
713
+ symbolLayers: [{
714
+ type: "CIMPictureMarker",
715
+ enable: !0,
716
+ size: i,
717
+ scaleX: 1,
718
+ tintColor: [255, 255, 255, Math.round((t.opacity ?? 1) * 255)],
719
+ url: "/breath_red_apng.png",
720
+ animatedSymbolProperties: s
721
+ }]
722
+ }
723
+ }
724
+ });
725
+ }
726
+ destroyMassPointLayer(e) {
727
+ var t, i;
728
+ (i = (t = this.mapView) == null ? void 0 : t.map) == null || i.remove(e.layer), e.layer.destroy();
729
+ }
730
+ destroyScatterLayer(e) {
731
+ var t, i;
732
+ (i = (t = this.mapView) == null ? void 0 : t.map) == null || i.remove(e.layer), e.layer.destroy();
733
+ }
734
+ addVisualizationLayer(e) {
735
+ var r;
736
+ const t = (r = this.mapView) == null ? void 0 : r.map;
737
+ if (!t)
738
+ throw new c("SDK_ERROR", "ArcGIS map is unavailable");
739
+ const i = t.layers.indexOf(this.graphicsLayer);
740
+ i >= 0 ? t.add(e.layer, i) : t.add(e.layer);
741
+ }
742
+ updateVisualizationLayerOptions(e, t, i) {
743
+ e.layer.visible = t.visible !== !1, e.layer.minScale = this.zoomToScale(t.minZoom ?? 3), e.layer.maxScale = this.zoomToScale(t.maxZoom ?? 21), e.zIndex = t.zIndex ?? i, this.reorderVisualizationLayers();
744
+ }
745
+ replaceVisualizationLayer(e, t) {
746
+ var s;
747
+ const i = (s = this.mapView) == null ? void 0 : s.map;
748
+ if (!i)
749
+ throw new c("SDK_ERROR", "ArcGIS map is unavailable");
750
+ const r = e.layer, a = i.layers.indexOf(r);
751
+ i.remove(r), a >= 0 ? i.add(t.layer, a) : i.add(t.layer), r.destroy(), e.layer = t.layer, e.zIndex = t.zIndex, this.reorderVisualizationLayers();
752
+ }
753
+ destroyVectorLayer(e) {
754
+ var t, i;
755
+ (i = (t = this.mapView) == null ? void 0 : t.map) == null || i.remove(e.layer), e.layer.destroy();
756
+ }
757
+ closeRing(e) {
758
+ const t = e[0], i = e[e.length - 1], r = e.map((s) => [s[0], s[1]]);
759
+ (t[0] !== i[0] || t[1] !== i[1]) && r.push([t[0], t[1]]);
760
+ let a = 0;
761
+ for (let s = 0; s < r.length - 1; s += 1)
762
+ a += r[s][0] * r[s + 1][1] - r[s + 1][0] * r[s][1];
763
+ return a > 0 ? [...r].reverse() : r;
764
+ }
765
+ reorderVisualizationLayers() {
766
+ var s;
767
+ const e = (s = this.mapView) == null ? void 0 : s.map, t = [
768
+ ...this.polygonLayers,
769
+ ...this.polylineLayers,
770
+ ...this.massPointLayers,
771
+ ...this.scatterLayers
772
+ ];
773
+ if (!e || t.length === 0)
774
+ return;
775
+ const i = t.sort((o, l) => o.zIndex - l.zIndex), r = i.map((o) => e.layers.indexOf(o.layer)).filter((o) => o >= 0);
776
+ if (r.length === 0)
777
+ return;
778
+ const a = Math.min(...r);
779
+ i.forEach((o, l) => e.reorder(o.layer, a + l));
780
+ }
781
+ /** 将 Web 地图 zoom 映射为 ArcGIS 比例尺分母,用于保持统一缩放范围语义。 */
782
+ zoomToScale(e) {
783
+ return 591657527591555e-6 / Math.pow(2, e);
784
+ }
785
+ getSketchViewModel() {
786
+ return this.sketchViewModel || (this.sketchViewModel = new x({
787
+ view: this.mapView,
788
+ layer: this.graphicsLayer,
789
+ updateOnGraphicClick: !1,
790
+ // UnifiedMap 的一次 draw* 调用只对应一个覆盖物;完成后由调用方决定
791
+ // 是否再次绘制。显式指定 single,避免 SDK 配置变化后自动复用旧会话。
792
+ creationMode: "single"
793
+ })), this.sketchViewModel;
794
+ }
795
+ /**
796
+ * 释放当前 SketchViewModel,但保留外部 GraphicsLayer 及其中已完成的图形。
797
+ * 绘制与编辑操作复用同一图层,不复用 SDK 内部工具会话。
798
+ */
799
+ resetSketchViewModel() {
800
+ var t;
801
+ const e = this.sketchViewModel;
802
+ e && (e.state === "active" && e.cancel(), (t = e.destroy) == null || t.call(e), this.sketchViewModel === e && (this.sketchViewModel = null));
803
+ }
804
+ applyDrawStyle(e, t, i) {
805
+ if (t === "polyline") {
806
+ e.polylineSymbol = new b({
807
+ color: d(i.strokeColor || "#3366ff", i.strokeOpacity ?? 1),
808
+ width: i.strokeWeight ?? 5,
809
+ style: i.strokeStyle === "dashed" ? "dash" : "solid"
810
+ });
811
+ return;
812
+ }
813
+ const r = i;
814
+ e.polygonSymbol = new V({
815
+ color: d(r.fillColor || "#3366ff", r.fillOpacity ?? 0.3),
816
+ outline: {
817
+ color: d(i.strokeColor || "#3366ff", i.strokeOpacity ?? 1),
818
+ width: i.strokeWeight ?? 3,
819
+ style: i.strokeStyle === "dashed" ? "dash" : "solid"
820
+ }
821
+ });
822
+ }
823
+ finishDraw(e) {
824
+ var t, i;
825
+ e.finished || (e.finished = !0, (t = e.handle) == null || t.remove(), ((i = this.activeDraw) == null ? void 0 : i.id) === e.id && (this.activeDraw = null));
826
+ }
827
+ finishEdit(e, t) {
828
+ var r, a;
829
+ if (e.finished)
830
+ return;
831
+ const i = this.getPath(e.native);
832
+ i && e.onChange(i), e.finished = !0, (r = e.handle) == null || r.remove(), t && e.sketch.state === "active" ? e.sketch.complete() : !t && e.sketch.state === "active" && e.sketch.cancel(), ((a = this.activeEdit) == null ? void 0 : a.id) === e.id && (this.activeEdit = null);
833
+ }
834
+ toLngLat(e, t, i) {
835
+ const r = i == null ? void 0 : i.wkid, s = (i == null ? void 0 : i.isWebMercator) || r === 3857 || r === 102100 || r === 102113 ? T(e, t) : [e, t];
836
+ return v(s);
837
+ }
838
+ ensureHitTestListener() {
839
+ this.hitTestHandle || (this.hitTestHandle = this.mapView.on("click", (e) => {
840
+ this.mapView.hitTest(e).then((t) => {
841
+ var o;
842
+ const i = (o = t.results) == null ? void 0 : o.find((l) => this.overlayClickCallbacks.has(l.graphic));
843
+ if (!i)
844
+ return;
845
+ const r = this.overlayClickCallbacks.get(i.graphic);
846
+ if (!r || !e.mapPoint)
847
+ return;
848
+ const a = this.toLngLat(e.mapPoint.x, e.mapPoint.y, e.mapPoint.spatialReference), s = {
849
+ lnglat: { lng: a[0], lat: a[1] },
850
+ position: a,
851
+ coordinateSystem: this.coordinateSystem,
852
+ originalEvent: e
853
+ };
854
+ r.forEach((l) => l(s));
855
+ }).catch((t) => {
856
+ console.error("ArcGIS hitTest failed", t);
857
+ });
858
+ }));
859
+ }
860
+ }
861
+ export {
862
+ ce as ArcGISAdapter
863
+ };