From aec00ecc093be803860c8675cbe1c4c776a7cb4e Mon Sep 17 00:00:00 2001
From: GuLiMmo <2820890765@qq.com>
Date: Tue, 19 Mar 2024 17:49:21 +0800
Subject: [PATCH] update: 新建航线、事件编辑、kmz文件问题修改

---
 src/hooks/use-cesium-tsa.ts |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/hooks/use-cesium-tsa.ts b/src/hooks/use-cesium-tsa.ts
index bc22c3b..a25ff3b 100644
--- a/src/hooks/use-cesium-tsa.ts
+++ b/src/hooks/use-cesium-tsa.ts
@@ -184,7 +184,7 @@
       }
     })
   }
-  // 添加点击事件
+  // 添加左键点击事件
   let leftClickHandler: Cesium.ScreenSpaceEventHandler
   const addClickEvent = (sid: string, cb: Function) => {
     if (leftClickHandler) {
@@ -198,9 +198,25 @@
       }
     }, Cesium.ScreenSpaceEventType.LEFT_CLICK)
   }
-  // 移除事件
+  // 移除左键事件
   const removeClickEvent = () => {
     leftClickHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
+  }
+
+  let rightClickHandler: Cesium.ScreenSpaceEventHandler
+  const addRightClick = (sid: string, cb: Function) => {
+    if (leftClickHandler) {
+      removeRightClickEvent()
+    }
+    rightClickHandler = new Cesium.ScreenSpaceEventHandler(viewer?.scene.canvas)
+    rightClickHandler.setInputAction(function (click: { position: Cesium.Cartesian2 }) {
+      const pick = viewer?.scene.pick(click.position)
+      cb(click, pick, viewer, handler)
+    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK)
+  }
+  // 移除右键事件
+  const removeRightClickEvent = () => {
+    rightClickHandler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK)
   }
 
   // 添加线段
@@ -356,6 +372,8 @@
     loadGeoJson,
     removeAllDataSource,
     addClickEvent,
-    removeClickEvent
+    removeClickEvent,
+    addRightClick,
+    removeRightClickEvent
   }
 }

--
Gitblit v1.9.3