From 5221bb4832912e7e494b76e4fdf64eb0c98fce50 Mon Sep 17 00:00:00 2001
From: linwe <872216996@qq.com>
Date: Fri, 22 Nov 2024 17:12:59 +0800
Subject: [PATCH] 代码优化

---
 src/pages/layout/components/scomponents/layersControl.vue |  179 +++++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 142 insertions(+), 37 deletions(-)

diff --git a/src/pages/layout/components/scomponents/layersControl.vue b/src/pages/layout/components/scomponents/layersControl.vue
index 2294922..f9c83f5 100644
--- a/src/pages/layout/components/scomponents/layersControl.vue
+++ b/src/pages/layout/components/scomponents/layersControl.vue
@@ -2,7 +2,7 @@
  * @Author: shuishen 1109946754@qq.com
  * @Date: 2024-10-31 10:47:29
  * @LastEditors: shuishen 1109946754@qq.com
- * @LastEditTime: 2024-11-19 15:53:37
+ * @LastEditTime: 2024-11-22 15:37:11
  * @FilePath: \bigScreen\src\pages\layout\components\scomponents\layersControl.vue
  * @Description:
  *
@@ -74,10 +74,13 @@
 
 const { VITE_APP_BASE } = import.meta.env
 
-let indexPoint = ref(['1'])
+let indexPoint = ref(['5', '7', '1'])
 
 const treeRef = ref(null)
 const Cesium = DC.getLib('Cesium')
+
+console.log(Cesium, 45646465)
+
 const treeProps = {
   indent: 16,
   showLabelLine: true,
@@ -166,7 +169,8 @@
           addPupoLayers[attrParams.name] = new DC.HtmlLayer(attrParams.name)
           window.$viewer.addLayer(addPupoLayers[attrParams.name])
           let iconEl = `<div class="marsBlueGradientPnl">
-                  <img src="${attrParams.imageUrl}" width="160" height="160" />
+            <div>${attrParams.fullName}</div>      
+            <img src="${attrParams.imageUrl}" />
                 </div>`
           let divIcon = new DC.DivIcon(
             new DC.Position(attrParams.lng, attrParams.lat, 64),
@@ -205,6 +209,7 @@
           addPupoLayers[attrParams.name] = new DC.HtmlLayer(attrParams.name)
           window.$viewer.addLayer(addPupoLayers[attrParams.name])
           let iconEl = `<div class="marsBlueGradientPnl">
+                  <div>${attrParams.fullName}</div>
                   <img src="${attrParams.imageUrl}" width="160" height="160" />
                 </div>`
           let divIcon = new DC.DivIcon(
@@ -290,6 +295,7 @@
           addPupoLayers[attrParams.name] = new DC.HtmlLayer(attrParams.name)
           window.$viewer.addLayer(addPupoLayers[attrParams.name])
           let iconEl = `<div class="marsBlueGradientPnl">
+                  <div>${attrParams.fullName}</div>
                   <img src="${attrParams.imageUrl}" width="160" height="160" />
                 </div>`
           let divIcon = new DC.DivIcon(
@@ -330,6 +336,7 @@
           addPupoLayers[attrParams.name] = new DC.HtmlLayer(attrParams.name)
           window.$viewer.addLayer(addPupoLayers[attrParams.name])
           let iconEl = `<div class="marsBlueGradientPnl">
+                   <div>${attrParams.fullName}</div>
                   <img src="${attrParams.imageUrl}" width="160" height="160" />
                 </div>`
           let divIcon = new DC.DivIcon(
@@ -370,6 +377,7 @@
           addPupoLayers[attrParams.name] = new DC.HtmlLayer(attrParams.name)
           window.$viewer.addLayer(addPupoLayers[attrParams.name])
           let iconEl = `<div class="marsBlueGradientPnl">
+                  <div>${attrParams.fullName}</div>
                   <img src="${attrParams.imageUrl}" width="160" height="160" />
                 </div>`
           let divIcon = new DC.DivIcon(
@@ -410,6 +418,7 @@
           addPupoLayers[attrParams.name] = new DC.HtmlLayer(attrParams.name)
           window.$viewer.addLayer(addPupoLayers[attrParams.name])
           let iconEl = `<div class="marsBlueGradientPnl">
+                  <div>${attrParams.fullName}</div>
                   <img src="${attrParams.imageUrl}" width="160" height="160" />
                 </div>`
           let divIcon = new DC.DivIcon(
@@ -447,6 +456,28 @@
         backgroundIcon: VITE_APP_BASE + 'img/mapicon/fxy.png',
         showPanel: false,
         layerName: 'fxyOrdinary',
+        incident: (e) => {
+          const { attrParams } = e.overlay
+          // 删除
+          destroy()
+          addPupoLayers[attrParams.name] = new DC.HtmlLayer(attrParams.name)
+          window.$viewer.addLayer(addPupoLayers[attrParams.name])
+          let iconEl = `<div class="marsBlueGradientPnl">
+            <li>${attrParams.firmName || ''}</li>
+            <li>${attrParams.riskLevelName || ''}</li>
+            </div>`
+          let divIcon = new DC.DivIcon(
+            new DC.Position(attrParams.lng, attrParams.lat, 64),
+            `<div class="public-map-popup-three">
+                    ${iconEl}
+                  </div>`
+          )
+          let incident = () => {
+            destroy()
+          }
+          divIcon.on(DC.MouseEventType.CLICK, incident)
+          addPupoLayers[attrParams.name].addOverlay(divIcon)
+        }
       },
       {
         id: '4-2',
@@ -463,6 +494,51 @@
         backgroundIcon: VITE_APP_BASE + 'img/mapicon/fxy.png',
         showPanel: false,
         layerName: 'fxyLarger',
+        incident: (e) => {
+          const { attrParams } = e.overlay
+          // 删除
+          destroy()
+          // if (!attrParams.imageUrl) {
+          //   return
+          // }
+          // addPupoLayers[attrParams.name] = new DC.HtmlLayer(attrParams.name)
+          // window.$viewer.addLayer(addPupoLayers[attrParams.name])
+          // let iconEl = `<div class="marsBlueGradientPnl">
+          //         <div>${attrParams.fullName}</div>
+          //         <img src="${attrParams.imageUrl}" width="160" height="160" />
+          //       </div>`
+          // let divIcon = new DC.DivIcon(
+          //   new DC.Position(attrParams.lng, attrParams.lat, 64),
+          //   `<div class="public-map-popup-two">
+          //           ${iconEl}
+          //         </div>`
+          // )
+          // let incident = () => {
+          //   destroy()
+          // }
+          // divIcon.on(DC.MouseEventType.CLICK, incident)
+          // addPupoLayers[attrParams.name].addOverlay(divIcon)
+
+          // 删除
+          destroy()
+          addPupoLayers[attrParams.name] = new DC.HtmlLayer(attrParams.name)
+          window.$viewer.addLayer(addPupoLayers[attrParams.name])
+          let iconEl = `<div class="marsBlueGradientPnl">
+            <li>${attrParams.firmName || ''}</li>
+            <li>${attrParams.riskLevelName || ''}</li>
+            </div>`
+          let divIcon = new DC.DivIcon(
+            new DC.Position(attrParams.lng, attrParams.lat, 64),
+            `<div class="public-map-popup-three">
+                    ${iconEl}
+                  </div>`
+          )
+          let incident = () => {
+            destroy()
+          }
+          divIcon.on(DC.MouseEventType.CLICK, incident)
+          addPupoLayers[attrParams.name].addOverlay(divIcon)
+        }
       }
     ]
   },
@@ -545,9 +621,9 @@
   }
 }
 
-let addTileLayers = {}
-let tileLayers = new DC.TilesetLayer('tileLayers')
-window.$viewer.addLayer(tileLayers)
+window.addTileLayers = {}
+window.tileLayers = new DC.TilesetLayer('tileLayers')
+window.$viewer.addLayer(window.tileLayers)
 
 const handleCheckChange = (data) => {
   let options = treeRef.value?.getCheckedNodes()
@@ -559,22 +635,40 @@
 
       //  const Cesium  = DC
       if (item.subType == '3Dtile') {
-        if (!addTileLayers[item.layerName]) {
-          addTileLayers[item.layerName] = item.urlData.map(i => {
-            let tile = new DC.Tileset(i.url)
+        if (!window.addTileLayers[item.layerName]) {
+          // window.addTileLayers[item.layerName] = []
+          // let tile = window.$viewer.delegate.scene.primitives.add(new Cesium.Cesium3DTileset({
+          //   url: '/zhyq/mx/tile_01/tileset.json',
+          // }))
 
-            tileLayers.addOverlay(tile)
+          // console.log(tile, new Cesium.Cesium3DTileset({
+          //   url: '/zhyq/mx/tile_01/tileset.json',
+          // }), 121323)
+          // item.urlData.forEach(i => {
+
+          // })
+
+
+
+          window.addTileLayers[item.layerName] = item.urlData.map(i => {
+            let tile = new DC.Tileset(i.url, {
+              maximumMemoryUsage: 1024 * 1024 * 1024,
+              maximumScreenSpaceError: 48,
+              skipLevels: 5,
+              skipLevelOfDetail: true,
+              skipScreenSpaceErrorFactor: 128
+            })
+
+            window.tileLayers.addOverlay(tile)
             return tile
           })
-
         } else {
-          addTileLayers[item.layerName].forEach(i => i.show = true)
+          window.addTileLayers[item.layerName].forEach(i => i.show = true)
         }
-        window.$viewer.flyTo(addTileLayers[item.layerName][0])
       } else if (item.subType == 'labelPoint') {
-        if (!addTileLayers[item.layerName]) {
-          addTileLayers[item.layerName] = new DC.HtmlLayer(item.layerName)
-          window.$viewer.addLayer(addTileLayers[item.layerName])
+        if (!window.addTileLayers[item.layerName]) {
+          window.addTileLayers[item.layerName] = new DC.HtmlLayer(item.layerName)
+          window.$viewer.addLayer(window.addTileLayers[item.layerName])
 
           item.method(item.params).then(res => {
             let data = res.data.data.records
@@ -613,16 +707,16 @@
 
               divIcon.on(DC.MouseEventType.CLICK, incident)
 
-              addTileLayers[item.layerName].addOverlay(divIcon)
+              window.addTileLayers[item.layerName].addOverlay(divIcon)
             })
           })
         } else {
-          addTileLayers[item.layerName].show = true
+          window.addTileLayers[item.layerName].show = true
         }
       } else if (item.subType == 'geojsonWall') {
-        if (!addTileLayers[item.layerName]) {
-          addTileLayers[item.layerName] = new DC.VectorLayer(item.layerName)
-          window.$viewer.addLayer(addTileLayers[item.layerName])
+        if (!window.addTileLayers[item.layerName]) {
+          window.addTileLayers[item.layerName] = new DC.VectorLayer(item.layerName)
+          window.$viewer.addLayer(window.addTileLayers[item.layerName])
 
           item.source.features.forEach(i => {
             let wall = new DC.Wall(
@@ -632,18 +726,21 @@
             wall.setStyle({
               material: new DC.WallTrailMaterialProperty({
                 color: Cesium.Color.fromBytes(0, 123, 255, 180),
-                speed: 10
+                speed: 8
               })
             })
-            addTileLayers[item.layerName].addOverlay(wall)
+            window.addTileLayers[item.layerName].addOverlay(wall)
           })
         } else {
-          addTileLayers[item.layerName].show = true
+          window.addTileLayers[item.layerName].show = true
         }
+        // 飞到园区范围
+        window.$viewer.flyTo(addTileLayers[item.layerName])
+        // console.log('flyToyqfw********2222222222*******************************', addTileLayers[item.layerName])
       } else if (item.subType == 'geojsonPipe') {
-        if (!addTileLayers[item.layerName]) {
-          addTileLayers[item.layerName] = new DC.VectorLayer(item.layerName)
-          window.$viewer.addLayer(addTileLayers[item.layerName])
+        if (!window.addTileLayers[item.layerName]) {
+          window.addTileLayers[item.layerName] = new DC.VectorLayer(item.layerName)
+          window.$viewer.addLayer(window.addTileLayers[item.layerName])
 
           function computeCircle(radius) {
             var positions = []
@@ -666,22 +763,22 @@
             polylineVolume.setStyle({
               material: item.color
             })
-            addTileLayers[item.layerName].addOverlay(polylineVolume)
+            window.addTileLayers[item.layerName].addOverlay(polylineVolume)
           })
         } else {
-          addTileLayers[item.layerName].show = true
+          window.addTileLayers[item.layerName].show = true
         }
       }
     } else {
-      if (addTileLayers[item.layerName]) {
+      if (window.addTileLayers[item.layerName]) {
         if (item.subType == '3Dtile') {
-          addTileLayers[item.layerName].forEach(i => i.show = false)
+          window.addTileLayers[item.layerName].forEach(i => i.show = false)
         } else if (item.subType == 'labelPoint') {
-          addTileLayers[item.layerName].show = false
+          window.addTileLayers[item.layerName].show = false
         } else if (item.subType == 'geojsonWall') {
-          addTileLayers[item.layerName].show = false
+          window.addTileLayers[item.layerName].show = false
         } else if (item.subType == 'geojsonPipe') {
-          addTileLayers[item.layerName].show = false
+          window.addTileLayers[item.layerName].show = false
         }
       }
     }
@@ -735,8 +832,15 @@
   handleCheckChange([findObjectById(data, key)])
 }
 
+// 飞到园区范围
+const flyToyqfw = () => {
+  console.log('flyToyqfw***************************************', addTileLayers['yqfw'])
+  window.$viewer.flyTo(addTileLayers['yqfw'])
+}
+
 EventBus.on('restHandleCheckChange', restHandleCheckChange)
 EventBus.on('restHandleDelChange', restHandleDelChange)
+EventBus.on('flyToyqfw', flyToyqfw)
 
 onMounted(() => {
   handleCheckChange(data.filter(i => indexPoint.value.includes(i.id)))
@@ -756,10 +860,11 @@
 }
 
 onUnmounted(() => {
-  tileLayers && window.$viewer.removeLayer(tileLayers)
-  let arr = Object.keys(addTileLayers)
+  window.tileLayers && window.$viewer.removeLayer(window.tileLayers)
+  delete window.tileLayers
+  let arr = Object.keys(window.addTileLayers)
   arr.filter(i => i != 'hgyq').forEach(i => {
-    addTileLayers[i] && window.$viewer.removeLayer(addTileLayers[i])
+    addTileLwindow.addTileLayersayers[i] && window.$viewer.removeLayer(window.addTileLayers[i])
   })
   // 弹窗销毁
   destroy()

--
Gitblit v1.9.3