@jorgmoritz/gis-manager 0.1.53 → 0.1.54

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/dist/index.cjs CHANGED
@@ -13,7 +13,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
13
13
  // package.json
14
14
  var package_default = {
15
15
  name: "@jorgmoritz/gis-manager",
16
- version: "0.1.53"};
16
+ version: "0.1.54"};
17
17
 
18
18
  // src/utils/version.ts
19
19
  var version = package_default.version;
@@ -2702,6 +2702,8 @@ var StateManager = class {
2702
2702
  __publicField(this, "editing", false);
2703
2703
  __publicField(this, "editingTarget");
2704
2704
  __publicField(this, "previousView");
2705
+ // MassPolygonManager 注册表(用于编辑模式隔离)
2706
+ __publicField(this, "massPolygonManagers", /* @__PURE__ */ new Set());
2705
2707
  // Emitters
2706
2708
  __publicField(this, "onSelectionChange", new Emitter());
2707
2709
  __publicField(this, "onEditingChange", new Emitter());
@@ -2752,6 +2754,26 @@ var StateManager = class {
2752
2754
  getPreviousCameraView() {
2753
2755
  return this.previousView;
2754
2756
  }
2757
+ // MassPolygonManager 注册管理
2758
+ /**
2759
+ * 注册 MassPolygonManager 实例
2760
+ * 用于编辑模式下统一管理所有图层的交互状态
2761
+ */
2762
+ registerMassPolygonManager(manager) {
2763
+ this.massPolygonManagers.add(manager);
2764
+ }
2765
+ /**
2766
+ * 注销 MassPolygonManager 实例
2767
+ */
2768
+ unregisterMassPolygonManager(manager) {
2769
+ this.massPolygonManagers.delete(manager);
2770
+ }
2771
+ /**
2772
+ * 获取所有已注册的 MassPolygonManager 实例
2773
+ */
2774
+ getAllMassPolygonManagers() {
2775
+ return Array.from(this.massPolygonManagers);
2776
+ }
2755
2777
  };
2756
2778
  var globalState = new StateManager();
2757
2779
 
@@ -9989,7 +10011,7 @@ var PolygonEditor = class {
9989
10011
  this.editHandles = positions.map(
9990
10012
  (p, i) => layer.entities.add({
9991
10013
  position: p,
9992
- point: { pixelSize: 7, color: point_color, outlineColor: C.Color.BLACK, outlineWidth: 1 },
10014
+ point: { pixelSize: 12, color: point_color, outlineColor: C.Color.BLACK, outlineWidth: 2 },
9993
10015
  properties: { _vertexIndex: i }
9994
10016
  })
9995
10017
  );
@@ -10071,29 +10093,120 @@ var PolygonEditor = class {
10071
10093
  return void 0;
10072
10094
  }
10073
10095
  };
10074
- const highlightHandle = (index) => {
10096
+ let hoveredIndex = void 0;
10097
+ const getHighlightColors = () => {
10098
+ if (layer.name === "inverter") {
10099
+ return {
10100
+ hoverColor: C.Color.fromCssColorString("rgba(150, 255, 150, 1)"),
10101
+ // 浅绿色
10102
+ hoverOutline: C.Color.fromCssColorString("rgba(0, 150, 0, 1)"),
10103
+ // 深绿色
10104
+ selectColor: C.Color.fromCssColorString("rgba(100, 255, 100, 1)"),
10105
+ // 亮绿色
10106
+ selectOutline: C.Color.fromCssColorString("rgba(0, 100, 0, 1)")
10107
+ // 深绿色
10108
+ };
10109
+ } else {
10110
+ return {
10111
+ hoverColor: C.Color.fromCssColorString("rgba(255, 150, 150, 1)"),
10112
+ // 浅红色
10113
+ hoverOutline: C.Color.fromCssColorString("rgba(200, 0, 0, 1)"),
10114
+ // 深红色
10115
+ selectColor: C.Color.fromCssColorString("rgba(255, 100, 100, 1)"),
10116
+ // 亮红色
10117
+ selectOutline: C.Color.fromCssColorString("rgba(150, 0, 0, 1)")
10118
+ // 深红色
10119
+ };
10120
+ }
10121
+ };
10122
+ const highlightColors = getHighlightColors();
10123
+ const hoverHandle = (index) => {
10124
+ const handle = this.editHandles[index];
10125
+ if (handle && handle.point) {
10126
+ handle.point.pixelSize = 18;
10127
+ handle.point.color = highlightColors.hoverColor;
10128
+ handle.point.outlineColor = highlightColors.hoverOutline;
10129
+ handle.point.outlineWidth = 3;
10130
+ }
10131
+ };
10132
+ const unhoverHandle = (index) => {
10075
10133
  const handle = this.editHandles[index];
10076
10134
  if (handle && handle.point) {
10077
- handle.point.pixelSize = 10;
10078
- handle.point.color = C.Color.YELLOW;
10079
- handle.point.outlineColor = C.Color.RED;
10135
+ handle.point.pixelSize = 12;
10136
+ handle.point.color = point_color;
10137
+ handle.point.outlineColor = C.Color.BLACK;
10080
10138
  handle.point.outlineWidth = 2;
10081
10139
  }
10082
10140
  };
10141
+ const highlightHandle = (index) => {
10142
+ const handle = this.editHandles[index];
10143
+ if (handle && handle.point) {
10144
+ handle.point.pixelSize = 16;
10145
+ handle.point.color = highlightColors.selectColor;
10146
+ handle.point.outlineColor = highlightColors.selectOutline;
10147
+ handle.point.outlineWidth = 3;
10148
+ }
10149
+ };
10083
10150
  const unhighlightHandle = (index) => {
10084
10151
  const handle = this.editHandles[index];
10085
10152
  if (handle && handle.point) {
10086
- handle.point.pixelSize = 7;
10153
+ handle.point.pixelSize = 12;
10087
10154
  handle.point.color = point_color;
10088
10155
  handle.point.outlineColor = C.Color.BLACK;
10089
- handle.point.outlineWidth = 1;
10156
+ handle.point.outlineWidth = 2;
10157
+ }
10158
+ };
10159
+ const VERTEX_PICK_RADIUS = 30;
10160
+ const findNearestVertexByScreenDistance = (screenPos) => {
10161
+ if (!screenPos || typeof screenPos.x !== "number" || typeof screenPos.y !== "number") {
10162
+ return void 0;
10163
+ }
10164
+ const scene = this.viewer.scene;
10165
+ const ST = this.CesiumNS.SceneTransforms;
10166
+ let nearestIdx;
10167
+ let nearestDist = VERTEX_PICK_RADIUS;
10168
+ for (let i = 0; i < positions.length; i++) {
10169
+ const worldPos = positions[i];
10170
+ if (!worldPos) continue;
10171
+ let screenCoord;
10172
+ try {
10173
+ screenCoord = ST.wgs84ToWindowCoordinates?.(scene, worldPos);
10174
+ } catch {
10175
+ }
10176
+ if (!screenCoord) {
10177
+ try {
10178
+ screenCoord = ST.worldToWindowCoordinates?.(scene, worldPos);
10179
+ } catch {
10180
+ }
10181
+ }
10182
+ if (!screenCoord && scene.cartesianToCanvasCoordinates) {
10183
+ try {
10184
+ const canvasCoord = scene.cartesianToCanvasCoordinates(worldPos);
10185
+ if (canvasCoord) {
10186
+ screenCoord = { x: canvasCoord.x, y: canvasCoord.y };
10187
+ }
10188
+ } catch {
10189
+ }
10190
+ }
10191
+ if (!screenCoord) continue;
10192
+ const dx = screenPos.x - screenCoord.x;
10193
+ const dy = screenPos.y - screenCoord.y;
10194
+ const dist = Math.sqrt(dx * dx + dy * dy);
10195
+ if (dist < nearestDist) {
10196
+ nearestDist = dist;
10197
+ nearestIdx = i;
10198
+ }
10090
10199
  }
10200
+ return nearestIdx;
10091
10201
  };
10092
10202
  this.handler && this.handler.setInputAction(
10093
10203
  (movement) => {
10204
+ const screenPos = movement.position;
10205
+ const nearestVertexIdx = findNearestVertexByScreenDistance(screenPos);
10094
10206
  const picked = this.viewer.scene.pick?.(movement.position);
10095
10207
  const entity = picked?.id;
10096
- const idx = entity?.properties?._vertexIndex?.getValue?.() ?? entity?.properties?._vertexIndex;
10208
+ const pickedIdx = entity?.properties?._vertexIndex?.getValue?.() ?? entity?.properties?._vertexIndex;
10209
+ const idx = nearestVertexIdx ?? (typeof pickedIdx === "number" ? pickedIdx : void 0);
10097
10210
  if (this.draggingIndex === void 0) {
10098
10211
  if (typeof idx === "number") {
10099
10212
  this.draggingIndex = idx;
@@ -10127,7 +10240,7 @@ var PolygonEditor = class {
10127
10240
  positions.splice(insertIndex, 0, insertPoint);
10128
10241
  const newHandle = layer.entities.add({
10129
10242
  position: insertPoint,
10130
- point: { pixelSize: 7, color: point_color, outlineColor: C.Color.BLACK, outlineWidth: 1 },
10243
+ point: { pixelSize: 12, color: point_color, outlineColor: C.Color.BLACK, outlineWidth: 2 },
10131
10244
  properties: { _vertexIndex: insertIndex }
10132
10245
  });
10133
10246
  this.editHandles.splice(insertIndex, 0, newHandle);
@@ -10186,10 +10299,46 @@ var PolygonEditor = class {
10186
10299
  }
10187
10300
  this.insertPreviewHandle = void 0;
10188
10301
  }
10302
+ if (hoveredIndex !== void 0) {
10303
+ unhoverHandle(hoveredIndex);
10304
+ hoveredIndex = void 0;
10305
+ }
10189
10306
  return;
10190
10307
  }
10308
+ const winPos = movement?.endPosition ?? movement?.position ?? movement;
10309
+ if (winPos) {
10310
+ const nearestVertexIdx = findNearestVertexByScreenDistance(winPos);
10311
+ if (nearestVertexIdx !== void 0) {
10312
+ if (hoveredIndex !== nearestVertexIdx) {
10313
+ if (hoveredIndex !== void 0) {
10314
+ unhoverHandle(hoveredIndex);
10315
+ }
10316
+ hoveredIndex = nearestVertexIdx;
10317
+ hoverHandle(hoveredIndex);
10318
+ }
10319
+ if (this.segmentHighlight) {
10320
+ try {
10321
+ layer.entities.remove(this.segmentHighlight);
10322
+ } catch {
10323
+ }
10324
+ this.segmentHighlight = void 0;
10325
+ }
10326
+ if (this.insertPreviewHandle) {
10327
+ try {
10328
+ layer.entities.remove(this.insertPreviewHandle);
10329
+ } catch {
10330
+ }
10331
+ this.insertPreviewHandle = void 0;
10332
+ }
10333
+ return;
10334
+ } else {
10335
+ if (hoveredIndex !== void 0) {
10336
+ unhoverHandle(hoveredIndex);
10337
+ hoveredIndex = void 0;
10338
+ }
10339
+ }
10340
+ }
10191
10341
  try {
10192
- const winPos = movement?.endPosition ?? movement?.position ?? movement;
10193
10342
  if (!winPos) return;
10194
10343
  const ST = this.CesiumNS.SceneTransforms;
10195
10344
  const threshold = 8;
@@ -12195,6 +12344,8 @@ var CZMLManager = class {
12195
12344
  __publicField(this, "currentSelectedEntity", null);
12196
12345
  __publicField(this, "activePolygonSession", null);
12197
12346
  __publicField(this, "polygonSessionCleanup");
12347
+ // 编辑模式标志
12348
+ __publicField(this, "editingMode", false);
12198
12349
  __publicField(this, "_polygonEditor");
12199
12350
  // Path manager composition
12200
12351
  __publicField(this, "_pathMgr");
@@ -12484,10 +12635,17 @@ var CZMLManager = class {
12484
12635
  bringDataSourceToTop(this.viewer, "other");
12485
12636
  }
12486
12637
  const session = this.polygonEditor.startDrawing(type, layer, (entity) => {
12638
+ this.exitEditingMode();
12487
12639
  this.cancelActivePolygonDrawing();
12488
12640
  onComplete?.(entity);
12489
12641
  });
12490
12642
  if (session && typeof session.stop === "function") {
12643
+ this.enterEditingMode();
12644
+ const originalStop = session.stop;
12645
+ session.stop = () => {
12646
+ this.exitEditingMode();
12647
+ originalStop();
12648
+ };
12491
12649
  this.activePolygonSession = session;
12492
12650
  } else {
12493
12651
  this.activePolygonSession = null;
@@ -12589,6 +12747,39 @@ var CZMLManager = class {
12589
12747
  bringDataSourceToTop(this.viewer, "other");
12590
12748
  return this.polygonEditor.startPointDrawing?.(layer, iconSvg, onComplete);
12591
12749
  }
12750
+ /**
12751
+ * 进入编辑模式:禁用所有 MassPolygonManager 的交互
12752
+ * 防止编辑多边形时其他图层响应鼠标事件
12753
+ */
12754
+ enterEditingMode() {
12755
+ if (this.editingMode) return;
12756
+ this.editingMode = true;
12757
+ const managers = globalState.getAllMassPolygonManagers?.();
12758
+ if (managers) {
12759
+ for (const manager of managers) {
12760
+ manager.disableInteraction();
12761
+ }
12762
+ }
12763
+ }
12764
+ /**
12765
+ * 退出编辑模式:恢复所有 MassPolygonManager 的交互
12766
+ */
12767
+ exitEditingMode() {
12768
+ if (!this.editingMode) return;
12769
+ this.editingMode = false;
12770
+ const managers = globalState.getAllMassPolygonManagers?.();
12771
+ if (managers) {
12772
+ for (const manager of managers) {
12773
+ manager.enableInteraction();
12774
+ }
12775
+ }
12776
+ }
12777
+ /**
12778
+ * 检查是否处于编辑模式
12779
+ */
12780
+ isInEditingMode() {
12781
+ return this.editingMode;
12782
+ }
12592
12783
  // New: start editing an existing polygon entity's vertices
12593
12784
  // Accepts: an Entity, or an id string, or undefined to use the last selected entity from state
12594
12785
  startPolygonEditing(entityOrId, onComplete) {
@@ -12630,7 +12821,20 @@ var CZMLManager = class {
12630
12821
  } else if (dataSource.name === "other") {
12631
12822
  bringDataSourceToTop(this.viewer, "other");
12632
12823
  }
12633
- return this.polygonEditor.startEditing(entity, dataSource, onComplete);
12824
+ this.enterEditingMode();
12825
+ const wrappedOnComplete = (editedEntity) => {
12826
+ this.exitEditingMode();
12827
+ onComplete?.(editedEntity);
12828
+ };
12829
+ const session = this.polygonEditor.startEditing(entity, dataSource, wrappedOnComplete);
12830
+ if (session) {
12831
+ const originalStop = session.stop;
12832
+ session.stop = () => {
12833
+ this.exitEditingMode();
12834
+ originalStop();
12835
+ };
12836
+ }
12837
+ return session;
12634
12838
  }
12635
12839
  ensurePolygonSessionHooks() {
12636
12840
  if (this.polygonSessionCleanup || typeof window === "undefined" || typeof document === "undefined") {
@@ -14169,6 +14373,8 @@ var MassPolygonManager = class {
14169
14373
  __publicField(this, "hoverHandler");
14170
14374
  __publicField(this, "clickHandler");
14171
14375
  __publicField(this, "rightClickHandler");
14376
+ // 交互禁用标志(编辑模式时禁用)
14377
+ __publicField(this, "interactionDisabled", false);
14172
14378
  // 悬停状态
14173
14379
  __publicField(this, "highlightedId");
14174
14380
  __publicField(this, "originalHighlightFillColor");
@@ -14257,12 +14463,35 @@ var MassPolygonManager = class {
14257
14463
  getLayerCollection() {
14258
14464
  return this.layerCollection;
14259
14465
  }
14466
+ /**
14467
+ * 禁用所有交互(hover/click/rightClick)
14468
+ * 用于编辑模式下隔离其他图层的交互
14469
+ */
14470
+ disableInteraction() {
14471
+ this.interactionDisabled = true;
14472
+ this.clearHighlight();
14473
+ this.hideLabel();
14474
+ }
14475
+ /**
14476
+ * 启用所有交互
14477
+ * 用于退出编辑模式后恢复交互
14478
+ */
14479
+ enableInteraction() {
14480
+ this.interactionDisabled = false;
14481
+ }
14482
+ /**
14483
+ * 检查交互是否被禁用
14484
+ */
14485
+ isInteractionDisabled() {
14486
+ return this.interactionDisabled;
14487
+ }
14260
14488
  /**
14261
14489
  * 批量创建多边形
14262
14490
  */
14263
14491
  create(polygons, options) {
14264
14492
  const C = this.CesiumNS;
14265
14493
  this.clear();
14494
+ globalState.registerMassPolygonManager(this);
14266
14495
  this.currentOptions = options ?? {};
14267
14496
  this.layerName = options?.layerName;
14268
14497
  if (options?.style) {
@@ -14456,6 +14685,7 @@ var MassPolygonManager = class {
14456
14685
  this.hoverHandler = new C.ScreenSpaceEventHandler(this.viewer.scene.canvas);
14457
14686
  this.hoverHandler.setInputAction(
14458
14687
  (movement) => {
14688
+ if (this.interactionDisabled) return;
14459
14689
  const now = Date.now();
14460
14690
  if (now - this.lastPickTime < this.pickThrottleMs) return;
14461
14691
  this.lastPickTime = now;
@@ -14497,6 +14727,7 @@ var MassPolygonManager = class {
14497
14727
  this.clickHandler = new C.ScreenSpaceEventHandler(this.viewer.scene.canvas);
14498
14728
  this.clickHandler.setInputAction(
14499
14729
  (movement) => {
14730
+ if (this.interactionDisabled) return;
14500
14731
  let polygonId = null;
14501
14732
  if (this.isClampToGround) {
14502
14733
  polygonId = this.pickPolygonByPosition(movement.position);
@@ -14539,6 +14770,7 @@ var MassPolygonManager = class {
14539
14770
  this.rightClickHandler = new C.ScreenSpaceEventHandler(this.viewer.scene.canvas);
14540
14771
  this.rightClickHandler.setInputAction(
14541
14772
  (movement) => {
14773
+ if (this.interactionDisabled) return;
14542
14774
  let polygonId = null;
14543
14775
  if (this.isClampToGround) {
14544
14776
  polygonId = this.pickPolygonByPosition(movement.position);
@@ -15319,6 +15551,7 @@ var MassPolygonManager = class {
15319
15551
  * 清除所有多边形
15320
15552
  */
15321
15553
  clear() {
15554
+ globalState.unregisterMassPolygonManager(this);
15322
15555
  if (this.hoverHandler) {
15323
15556
  this.hoverHandler.destroy();
15324
15557
  this.hoverHandler = void 0;
@@ -15338,6 +15571,7 @@ var MassPolygonManager = class {
15338
15571
  this.originalSelectFillColor = void 0;
15339
15572
  this.originalSelectOutlineColor = void 0;
15340
15573
  this.hoverLabel = void 0;
15574
+ this.interactionDisabled = false;
15341
15575
  this.highlightPrimitive = void 0;
15342
15576
  this.selectPrimitive = void 0;
15343
15577
  if (this.layerCollection && this.viewer?.scene?.primitives) {