From 0c070817accc40e6c8a2a1479fe2a9ee6f2f5d3e Mon Sep 17 00:00:00 2001
From: husq <931347610@qq.com>
Date: Fri, 08 Sep 2023 10:00:04 +0800
Subject: [PATCH] 修改基本功能、添加进入项目详情

---
 src/components/cesiumMap/cesium.vue |   63 +++++++++++++++++++------------
 1 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/src/components/cesiumMap/cesium.vue b/src/components/cesiumMap/cesium.vue
index 132f6d9..7f9175d 100644
--- a/src/components/cesiumMap/cesium.vue
+++ b/src/components/cesiumMap/cesium.vue
@@ -2,14 +2,14 @@
  * @Author: 胡思旗 931347610@qq.com
  * @Date: 2023-08-22 17:50:30
  * @LastEditors: husq 931347610@qq.com
- * @LastEditTime: 2023-09-05 17:28:28
+ * @LastEditTime: 2023-09-07 16:45:18
  * @FilePath: \Cloud-API-Demo-Web\src\components\cesiumMap\cesium.vue
  * @Description:
  *
  * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved.
 -->
 <template>
-  <div class="height-100 width-100 cesium" id="cesiumContainer" @click="getCoordinate"></div>
+  <div class="height-100 width-100 cesium" id="cesiumContainer"></div>
   <div v-if="centerConfig.type && !centerConfig.latitude" class="pointLongitude">在地图上点击绘制项目中心点</div>
 </template>
 
@@ -82,31 +82,16 @@
   })
   viewer.value?.imageryLayers.addImageryProvider(annotation)
 }
-// 获取地图点击坐标
-const getCoordinate = () => {
-  if (!centerConfig.value.type) return
-  let longitude: number, latitude: number
-  viewer.value?.screenSpaceEventHandler.setInputAction((e: any) => {
-    const cartesian = viewer.value?.camera.pickEllipsoid(e.position, viewer.value?.scene.globe.ellipsoid)
-    if (cartesian) {
-      const cartographic = Cesium.Cartographic.fromCartesian(cartesian)
-      longitude = Cesium.Math.toDegrees(cartographic.longitude)
-      latitude = Cesium.Math.toDegrees(cartographic.latitude)
-      const data = {
-        longitude,
-        latitude,
-      }
-      store.commit('SET_CENTER_CONFIG_LATITUDE', data)
-    }
-    Point(longitude, latitude)
-  }, Cesium.ScreenSpaceEventType.LEFT_CLICK)
-}
 const Point = (longitude: number, latitude: number) => {
+  // 移除地图所有点 重新绘制
+  viewer.value?.entities.removeAll()
   const entity = viewer.value?.entities.add({
     position: Cesium.Cartesian3.fromDegrees(longitude, latitude),
     point: {
-      pixelSize: 10,
-      color: Cesium.Color.YELLOW
+      pixelSize: 24,
+      color: Cesium.Color.GREEN,
+      outlineColor: Cesium.Color.WHITE,
+      outlineWidth: 2,
     }
   })
   // // 将相机定位到标记点的位置
@@ -117,13 +102,43 @@
 }
 // 设置项目中所有的项目中心坐标
 watch(() => store.state.map.pointList, (newVal, oldVal) => {
-  if (newVal && newVal.length > 0) {
+  if (newVal) {
     pointCenter(viewer.value, newVal)
     clickPoint(viewer.value, newVal)
   }
 }, {
   deep: true
 })
+// 点击地图生成项目中心点
+watch(() => store.state.map.centerConfig.type, (newVal) => {
+  const handler = new Cesium.ScreenSpaceEventHandler(viewer.value?.scene.canvas)
+  console.log(newVal, 'newVal')
+  if (newVal === false) {
+    viewer.value?.entities.removeAll()
+    console.log('===false===')
+    handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
+  } else {
+    console.log('===true===')
+    handler.setInputAction(function (e: any) {
+      const cartesian = viewer.value?.camera.pickEllipsoid(e.position, viewer.value?.scene.globe.ellipsoid)
+      if (cartesian) {
+        const cartographic = Cesium.Cartographic.fromCartesian(cartesian)
+        const longitude = Cesium.Math.toDegrees(cartographic.longitude)
+        const latitude = Cesium.Math.toDegrees(cartographic.latitude)
+        const data = {
+          longitude,
+          latitude,
+        }
+        store.commit('SET_CENTER_CONFIG_LATITUDE', data)
+        console.log(data, 'data')
+        Point(longitude, latitude)
+      }
+    }, Cesium.ScreenSpaceEventType.LEFT_CLICK
+    )
+  }
+}, {
+  deep: true
+})
 onMounted(() => {
   init()
 })

--
Gitblit v1.9.3