@jorgmoritz/gis-manager 0.1.52 → 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.52"};
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
 
@@ -3315,8 +3337,14 @@ var CameraFOVController = class {
3315
3337
  if (this.sliderEl) {
3316
3338
  this.sliderEl.removeEventListener("input", this.handleSliderChange);
3317
3339
  }
3318
- if (this.containerEl && !this.opts.container) {
3319
- this.containerEl.remove();
3340
+ if (this.containerEl) {
3341
+ if (!this.opts.container) {
3342
+ this.containerEl.remove();
3343
+ } else {
3344
+ while (this.containerEl.firstChild) {
3345
+ this.containerEl.removeChild(this.containerEl.firstChild);
3346
+ }
3347
+ }
3320
3348
  }
3321
3349
  this.onFOVChange.clear();
3322
3350
  }
@@ -9983,7 +10011,7 @@ var PolygonEditor = class {
9983
10011
  this.editHandles = positions.map(
9984
10012
  (p, i) => layer.entities.add({
9985
10013
  position: p,
9986
- 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 },
9987
10015
  properties: { _vertexIndex: i }
9988
10016
  })
9989
10017
  );
@@ -10065,29 +10093,120 @@ var PolygonEditor = class {
10065
10093
  return void 0;
10066
10094
  }
10067
10095
  };
10068
- 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) => {
10069
10133
  const handle = this.editHandles[index];
10070
10134
  if (handle && handle.point) {
10071
- handle.point.pixelSize = 10;
10072
- handle.point.color = C.Color.YELLOW;
10073
- handle.point.outlineColor = C.Color.RED;
10135
+ handle.point.pixelSize = 12;
10136
+ handle.point.color = point_color;
10137
+ handle.point.outlineColor = C.Color.BLACK;
10074
10138
  handle.point.outlineWidth = 2;
10075
10139
  }
10076
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
+ };
10077
10150
  const unhighlightHandle = (index) => {
10078
10151
  const handle = this.editHandles[index];
10079
10152
  if (handle && handle.point) {
10080
- handle.point.pixelSize = 7;
10153
+ handle.point.pixelSize = 12;
10081
10154
  handle.point.color = point_color;
10082
10155
  handle.point.outlineColor = C.Color.BLACK;
10083
- 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
+ }
10084
10199
  }
10200
+ return nearestIdx;
10085
10201
  };
10086
10202
  this.handler && this.handler.setInputAction(
10087
10203
  (movement) => {
10204
+ const screenPos = movement.position;
10205
+ const nearestVertexIdx = findNearestVertexByScreenDistance(screenPos);
10088
10206
  const picked = this.viewer.scene.pick?.(movement.position);
10089
10207
  const entity = picked?.id;
10090
- 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);
10091
10210
  if (this.draggingIndex === void 0) {
10092
10211
  if (typeof idx === "number") {
10093
10212
  this.draggingIndex = idx;
@@ -10121,7 +10240,7 @@ var PolygonEditor = class {
10121
10240
  positions.splice(insertIndex, 0, insertPoint);
10122
10241
  const newHandle = layer.entities.add({
10123
10242
  position: insertPoint,
10124
- 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 },
10125
10244
  properties: { _vertexIndex: insertIndex }
10126
10245
  });
10127
10246
  this.editHandles.splice(insertIndex, 0, newHandle);
@@ -10180,10 +10299,46 @@ var PolygonEditor = class {
10180
10299
  }
10181
10300
  this.insertPreviewHandle = void 0;
10182
10301
  }
10302
+ if (hoveredIndex !== void 0) {
10303
+ unhoverHandle(hoveredIndex);
10304
+ hoveredIndex = void 0;
10305
+ }
10183
10306
  return;
10184
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
+ }
10185
10341
  try {
10186
- const winPos = movement?.endPosition ?? movement?.position ?? movement;
10187
10342
  if (!winPos) return;
10188
10343
  const ST = this.CesiumNS.SceneTransforms;
10189
10344
  const threshold = 8;
@@ -12189,6 +12344,8 @@ var CZMLManager = class {
12189
12344
  __publicField(this, "currentSelectedEntity", null);
12190
12345
  __publicField(this, "activePolygonSession", null);
12191
12346
  __publicField(this, "polygonSessionCleanup");
12347
+ // 编辑模式标志
12348
+ __publicField(this, "editingMode", false);
12192
12349
  __publicField(this, "_polygonEditor");
12193
12350
  // Path manager composition
12194
12351
  __publicField(this, "_pathMgr");
@@ -12478,10 +12635,17 @@ var CZMLManager = class {
12478
12635
  bringDataSourceToTop(this.viewer, "other");
12479
12636
  }
12480
12637
  const session = this.polygonEditor.startDrawing(type, layer, (entity) => {
12638
+ this.exitEditingMode();
12481
12639
  this.cancelActivePolygonDrawing();
12482
12640
  onComplete?.(entity);
12483
12641
  });
12484
12642
  if (session && typeof session.stop === "function") {
12643
+ this.enterEditingMode();
12644
+ const originalStop = session.stop;
12645
+ session.stop = () => {
12646
+ this.exitEditingMode();
12647
+ originalStop();
12648
+ };
12485
12649
  this.activePolygonSession = session;
12486
12650
  } else {
12487
12651
  this.activePolygonSession = null;
@@ -12583,6 +12747,39 @@ var CZMLManager = class {
12583
12747
  bringDataSourceToTop(this.viewer, "other");
12584
12748
  return this.polygonEditor.startPointDrawing?.(layer, iconSvg, onComplete);
12585
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
+ }
12586
12783
  // New: start editing an existing polygon entity's vertices
12587
12784
  // Accepts: an Entity, or an id string, or undefined to use the last selected entity from state
12588
12785
  startPolygonEditing(entityOrId, onComplete) {
@@ -12624,7 +12821,20 @@ var CZMLManager = class {
12624
12821
  } else if (dataSource.name === "other") {
12625
12822
  bringDataSourceToTop(this.viewer, "other");
12626
12823
  }
12627
- 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;
12628
12838
  }
12629
12839
  ensurePolygonSessionHooks() {
12630
12840
  if (this.polygonSessionCleanup || typeof window === "undefined" || typeof document === "undefined") {
@@ -14163,6 +14373,8 @@ var MassPolygonManager = class {
14163
14373
  __publicField(this, "hoverHandler");
14164
14374
  __publicField(this, "clickHandler");
14165
14375
  __publicField(this, "rightClickHandler");
14376
+ // 交互禁用标志(编辑模式时禁用)
14377
+ __publicField(this, "interactionDisabled", false);
14166
14378
  // 悬停状态
14167
14379
  __publicField(this, "highlightedId");
14168
14380
  __publicField(this, "originalHighlightFillColor");
@@ -14251,12 +14463,35 @@ var MassPolygonManager = class {
14251
14463
  getLayerCollection() {
14252
14464
  return this.layerCollection;
14253
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
+ }
14254
14488
  /**
14255
14489
  * 批量创建多边形
14256
14490
  */
14257
14491
  create(polygons, options) {
14258
14492
  const C = this.CesiumNS;
14259
14493
  this.clear();
14494
+ globalState.registerMassPolygonManager(this);
14260
14495
  this.currentOptions = options ?? {};
14261
14496
  this.layerName = options?.layerName;
14262
14497
  if (options?.style) {
@@ -14450,6 +14685,7 @@ var MassPolygonManager = class {
14450
14685
  this.hoverHandler = new C.ScreenSpaceEventHandler(this.viewer.scene.canvas);
14451
14686
  this.hoverHandler.setInputAction(
14452
14687
  (movement) => {
14688
+ if (this.interactionDisabled) return;
14453
14689
  const now = Date.now();
14454
14690
  if (now - this.lastPickTime < this.pickThrottleMs) return;
14455
14691
  this.lastPickTime = now;
@@ -14491,6 +14727,7 @@ var MassPolygonManager = class {
14491
14727
  this.clickHandler = new C.ScreenSpaceEventHandler(this.viewer.scene.canvas);
14492
14728
  this.clickHandler.setInputAction(
14493
14729
  (movement) => {
14730
+ if (this.interactionDisabled) return;
14494
14731
  let polygonId = null;
14495
14732
  if (this.isClampToGround) {
14496
14733
  polygonId = this.pickPolygonByPosition(movement.position);
@@ -14533,6 +14770,7 @@ var MassPolygonManager = class {
14533
14770
  this.rightClickHandler = new C.ScreenSpaceEventHandler(this.viewer.scene.canvas);
14534
14771
  this.rightClickHandler.setInputAction(
14535
14772
  (movement) => {
14773
+ if (this.interactionDisabled) return;
14536
14774
  let polygonId = null;
14537
14775
  if (this.isClampToGround) {
14538
14776
  polygonId = this.pickPolygonByPosition(movement.position);
@@ -15313,6 +15551,7 @@ var MassPolygonManager = class {
15313
15551
  * 清除所有多边形
15314
15552
  */
15315
15553
  clear() {
15554
+ globalState.unregisterMassPolygonManager(this);
15316
15555
  if (this.hoverHandler) {
15317
15556
  this.hoverHandler.destroy();
15318
15557
  this.hoverHandler = void 0;
@@ -15332,6 +15571,7 @@ var MassPolygonManager = class {
15332
15571
  this.originalSelectFillColor = void 0;
15333
15572
  this.originalSelectOutlineColor = void 0;
15334
15573
  this.hoverLabel = void 0;
15574
+ this.interactionDisabled = false;
15335
15575
  this.highlightPrimitive = void 0;
15336
15576
  this.selectPrimitive = void 0;
15337
15577
  if (this.layerCollection && this.viewer?.scene?.primitives) {