From ddb76492b96539151ab1947660b3bcbd9e20e302 Mon Sep 17 00:00:00 2001
From: linwe <872216996@qq.com>
Date: Fri, 22 Nov 2024 15:38:03 +0800
Subject: [PATCH] 代码优化
---
src/pages/layout/components/scomponents/layersControl.vue | 518 +++++++++++++++++++++++++++++++++------------------------
1 files changed, 298 insertions(+), 220 deletions(-)
diff --git a/src/pages/layout/components/scomponents/layersControl.vue b/src/pages/layout/components/scomponents/layersControl.vue
index 071cf79..985d357 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-12 18:15:54
+ * @LastEditTime: 2024-11-19 15:53:37
* @FilePath: \bigScreen\src\pages\layout\components\scomponents\layersControl.vue
* @Description:
*
@@ -74,7 +74,7 @@
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')
@@ -90,6 +90,7 @@
const closePanoramaPopup = () => {
panoramaShow.value = false
}
+let addPupoLayers = {}
const data = [
{
@@ -106,6 +107,18 @@
url: VITE_APP_BASE + 'mx/tile_02/tileset.json',
label: 'tile_02'
},
+ {
+ url: VITE_APP_BASE + 'mx/tile_03/tileset.json',
+ label: 'tile_03'
+ },
+ {
+ url: VITE_APP_BASE + 'mx/tile_04/tileset.json',
+ label: 'tile_04'
+ },
+ {
+ url: VITE_APP_BASE + 'mx/tile_05/tileset.json',
+ label: 'tile_05'
+ },
],
layerName: 'hgyq'
},
@@ -120,6 +133,7 @@
size: 1000
},
backgroundIcon: VITE_APP_BASE + 'img/mapicon/qy.png',
+ className: 'qyfb-box',
showPanel: false,
layerName: 'qyfb'
},
@@ -138,7 +152,35 @@
type: 1,
size: 1000
},
- layerName: 'yjc'
+ backgroundIcon: VITE_APP_BASE + 'img/mapicon/yjc.png',
+ className: 'yjc-box',
+ showPanel: false,
+ layerName: 'yjc',
+ 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}" />
+ </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)
+ }
},
{
id: '3-2',
@@ -150,20 +192,83 @@
type: 2,
size: 1000
},
- layerName: 'fm'
+ backgroundIcon: VITE_APP_BASE + 'img/mapicon/ysf.png',
+ className: 'ysf-box',
+ showPanel: false,
+ layerName: 'fm',
+ 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)
+ }
},
{
id: '3-3',
label: '公共管网',
- type: 'layer',
- subType: 'labelPoint',
- method: getList,
- params: {
- type: 3,
- size: 1000
- },
- layerName: 'gggw'
+ children: [
+ // 给水管网、污水管网、燃气管网、雨水管网
+ {
+ id: '3-3-1',
+ label: '给水管网',
+ type: 'layer',
+ subType: 'geojsonPipe',
+ layerName: 'gsgw',
+ source: gsgw,
+ color: DC.Color.BLUE,
+ height: 65,
+ },
+ {
+ id: '3-3-2',
+ label: '污水管网',
+ type: 'layer',
+ subType: 'geojsonPipe',
+ layerName: 'wsgw',
+ source: wsgw,
+ color: DC.Color.BLACK,
+ height: 68,
+ },
+ {
+ id: '3-3-3',
+ label: '燃气管网',
+ type: 'layer',
+ subType: 'geojsonPipe',
+ layerName: 'rqgw',
+ source: rqgw,
+ color: DC.Color.RED,
+ height: 71,
+ },
+ {
+ id: '3-3-4',
+ label: '雨水管网',
+ type: 'layer',
+ subType: 'geojsonPipe',
+ layerName: 'ysgw',
+ source: ysgw,
+ color: DC.Color.CYAN,
+ height: 75,
+ },
+ ]
},
{
@@ -176,7 +281,32 @@
type: 4,
size: 1000
},
- layerName: 'wstsbz'
+ layerName: 'wstsbz',
+ 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)
+ }
},
{
@@ -189,7 +319,35 @@
type: 5,
size: 1000
},
- layerName: 'sk'
+ backgroundIcon: VITE_APP_BASE + 'img/mapicon/sk.png',
+ className: 'sk-box',
+ showPanel: false,
+ layerName: 'sk',
+ 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)
+ }
},
{
@@ -202,7 +360,35 @@
type: 6,
size: 1000
},
- layerName: 'yjb'
+ backgroundIcon: VITE_APP_BASE + 'img/mapicon/yjb.png',
+ className: 'yjb-box',
+ showPanel: false,
+ layerName: 'yjb',
+ 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)
+ }
},
{
@@ -215,7 +401,35 @@
type: 7,
size: 1000
},
- layerName: 'xfs'
+ backgroundIcon: VITE_APP_BASE + 'img/mapicon/xfs.png',
+ className: 'xfs-box',
+ showPanel: false,
+ layerName: 'xfs',
+ 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)
+ }
}
]
},
@@ -223,16 +437,40 @@
{
id: '4',
label: '风险源',
- type: 'layer',
- subType: 'labelPoint',
- method: getRiskList,
- params: {
- size: 1000
- },
- showParams: 'category',
- backgroundIcon: VITE_APP_BASE + 'img/mapicon/fxy.png',
- showPanel: false,
- layerName: 'fxy'
+ children: [
+ {
+ id: '4-1',
+ label: '一般',
+ type: 'layer',
+ subType: 'labelPoint',
+ method: getRiskList,
+ params: {
+ riskLevel: 1,
+ size: 1000
+ },
+ showParams: 'category',
+ className: 'fxy-ordinary',
+ backgroundIcon: VITE_APP_BASE + 'img/mapicon/fxy.png',
+ showPanel: false,
+ layerName: 'fxyOrdinary',
+ },
+ {
+ id: '4-2',
+ label: '较大',
+ type: 'layer',
+ subType: 'labelPoint',
+ method: getRiskList,
+ params: {
+ riskLevel: 2,
+ size: 1000
+ },
+ showParams: 'category',
+ className: 'fxy-larger',
+ backgroundIcon: VITE_APP_BASE + 'img/mapicon/fxy.png',
+ showPanel: false,
+ layerName: 'fxyLarger',
+ }
+ ]
},
{
@@ -242,55 +480,6 @@
subType: 'geojsonWall',
layerName: 'yqfw',
source: yqfw
- },
-
- {
- id: '6',
- label: '地下管网',
- children: [
- // 给水管网、污水管网、燃气管网、雨水管网
- {
- id: '6-1',
- label: '给水管网',
- type: 'layer',
- subType: 'geojsonPipe',
- layerName: 'gsgw',
- source: gsgw,
- color: DC.Color.BLUE,
- height: 5,
- },
- {
- id: '6-2',
- label: '污水管网',
- type: 'layer',
- subType: 'geojsonPipe',
- layerName: 'wsgw',
- source: wsgw,
- color: DC.Color.BLACK,
- height: 10,
- },
- {
- id: '6-3',
- label: '燃气管网',
- type: 'layer',
- subType: 'geojsonPipe',
- layerName: 'rqgw',
- source: rqgw,
- color: DC.Color.RED,
- height: 15,
- },
- {
- id: '6-4',
- label: '雨水管网',
- type: 'layer',
- subType: 'geojsonPipe',
- layerName: 'ysgw',
- source: ysgw,
- color: DC.Color.CYAN,
- height: 20,
- },
-
- ]
},
{
@@ -308,7 +497,6 @@
incident: (e) => {
const { attrParams } = e.overlay
panoramaTitle.value = attrParams.name
-
if (
attrParams.url.indexOf("http://vr.jxpskj.com:180") != -1
) {
@@ -317,7 +505,6 @@
"/panorama"
)
}
-
panoramaUrl.value = attrParams.url
panoramaShow.value = true
}
@@ -374,7 +561,7 @@
collectNodesWithFlag(data)
collectedNodes.value.forEach(item => {
- if (options.some(i => i.id == item.id)) {
+ if (options?.some(i => i.id == item.id)) {
// const Cesium = DC
if (item.subType == '3Dtile') {
@@ -389,7 +576,6 @@
} else {
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)
@@ -417,15 +603,16 @@
}
let divIcon = new DC.DivIcon(
- new DC.Position(i.lng, i.lat, 0),
- `<div class="public-map-popup">
+ new DC.Position(i.lng, i.lat, 64),
+ `<div class="public-map-popup ${item.className || ''}">
${iconEl}
</div>`
)
divIcon.attrParams = i
- let incident = () => { }
+ let incident = () => {
+ }
if (item.incident) incident = item.incident
@@ -450,7 +637,7 @@
wall.setStyle({
material: new DC.WallTrailMaterialProperty({
color: Cesium.Color.fromBytes(0, 123, 255, 180),
- speed: 10
+ speed: 8
})
})
addTileLayers[item.layerName].addOverlay(wall)
@@ -458,6 +645,9 @@
} else {
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)
@@ -465,7 +655,7 @@
function computeCircle(radius) {
var positions = []
- for (var i = 0; i < 1080; i++) {
+ for (var i = 0; i < 360; i++) {
var radians = DC.Math.toRadians(i)
positions.push({
x: radius * Math.cos(radians),
@@ -478,7 +668,7 @@
item.source.features.forEach(i => {
let polylineVolume = new DC.PolylineVolume(
i.geometry.coordinates.map(d => [d[0], d[1], item.height].join(',')).join(';'),
- computeCircle(0.3)
+ computeCircle(2)
)
polylineVolume.setStyle({
@@ -532,7 +722,7 @@
const restHandleCheckChange = (key) => {
let checkIds = treeRef.value?.getCheckedKeys()
- if (checkIds.some(i => i == key)) {
+ if (checkIds && checkIds.some(i => i == key)) {
return
}
@@ -543,156 +733,42 @@
const restHandleDelChange = (key) => {
let checkIds = treeRef.value?.getCheckedKeys()
- if (!checkIds.some(i => i == key)) {
+ console.log(checkIds, key)
+
+ if (checkIds && !checkIds.some(i => i == key)) {
return
}
- treeRef.value?.setCheckedKeys(checkIds.filter(i => i != key))
+ treeRef.value?.setCheckedKeys(checkIds.filter(i => i.indexOf(key)))
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)))
})
-const sharedData = computed(() => pointStore.sharedData);
-//
-watch(sharedData, (newValue) => {
- let companyInfo = JSON.parse(localStorage.getItem('companyInfo'))
+// const sharedData = computed(() => pointStore.sharedData);
+// watch(sharedData, (newValue) => {
+// });
- if (newValue === '1') {
- // 处理切换了应急空间页面,把图标隐藏
- if (indexPoint.value.includes('3')) {
- let allList = data.filter(i => indexPoint.value.includes(i.id))
- let temp = indexPoint.value.filter(ie => ie != '3')
- // console.log(temp, '***************************************')
- let checkList = data.filter(i => temp.includes(i.id))
- treeRef.value?.setCheckedNodes(checkList)
- handleCheckChangeTwo(allList, companyInfo.id)
- }
- return
- }
- // 处理切换到应急空间页面,把图标显示
- console.log('sharedData changed to:', newValue);
- // 获取缓存里面的企业id
- indexPoint.value.includes(newValue) ? '' : indexPoint.value.push(newValue)
- let checkList = data.filter(i => indexPoint.value.includes(i.id))
- treeRef.value?.setCheckedNodes(checkList)
- handleCheckChangeTwo(checkList, companyInfo.id)
-});
-
-const handleCheckChangeTwo = (data, firmId) => {
- let options = treeRef.value?.getCheckedNodes()
- // console.log(options, "*************222222***********")
- collectedNodes.value = []
- collectNodesWithFlag(data)
- collectedNodes.value.forEach(item => {
- let layerName = item.layerName + '_' + firmId
- console.log(layerName, "**************************************")
- if (options.some(i => i.id == item.id)) {
- if (item.subType == 'labelPoint') {
- if (!addTileLayers[layerName]) {
- addTileLayers[layerName] = new DC.HtmlLayer(addTileLayers[layerName])
- window.$viewer.addLayer(addTileLayers[layerName])
- let params = { ...item.params }
- params.firmId = firmId
- item.method(params).then(res => {
- let data = res.data.data.records
- data.filter(i => i.lng && i.lng != '' && i.lat && i.lat != '').forEach(i => {
- let iconEl = ''
- if ('showPanel' in item && item.showPanel == false) {
- if (item.backgroundIcon) {
- iconEl = `
- <div class="map-name">${i[item.showParams] || i.name}</div>
- <div class="map-icon">
- <img src="${item.backgroundIcon}">
- </div>
- `
- }
- } else {
- iconEl = `<div class="marsBlueGradientPnl">
- <div>${i[item.showParams] || i.name}</div>
- </div>`
- }
- let divIcon = new DC.DivIcon(
- new DC.Position(i.lng, i.lat, 0),
- `<div class="public-map-popup">
- ${iconEl}
- </div>`
- )
- addTileLayers[layerName].addOverlay(divIcon)
- })
- })
- } else {
- addTileLayers[layerName].show = true
- }
- }
- } else {
- if (addTileLayers[layerName]) {
- if (item.subType == 'labelPoint') {
- addTileLayers[layerName].show = false
- }
- }
- }
+// 销毁
+function destroy() {
+ let arr = Object.keys(addPupoLayers)
+ arr.filter(i => i != 'hgyq').forEach(i => {
+ addPupoLayers[i] && window.$viewer.removeLayer(addPupoLayers[i])
})
+ addPupoLayers = {}
}
-// const handleCheckChangeTwo = (data, firmId) => {
-// let options = treeRef.value?.getCheckedNodes()
-// console.log(options, "*************222222***********")
-// collectedNodes.value = []
-// collectNodesWithFlag(data)
-// collectedNodes.value.forEach(item => {
-// if (options.some(i => i.id == item.id)) {
-
-// if (item.subType == 'labelPoint') {
-// if (!addTileLayers[item.layerName]) {
-// addTileLayers[item.layerName] = new DC.HtmlLayer(addTileLayers[item.layerName])
-// window.$viewer.addLayer(addTileLayers[item.layerName])
-// let params = { ...item.params }
-// params.firmId = firmId
-// item.method(params).then(res => {
-// let data = res.data.data.records
-// data.filter(i => i.lng && i.lng != '' && i.lat && i.lat != '').forEach(i => {
-// let iconEl = ''
-// if ('showPanel' in item && item.showPanel == false) {
-// if (item.backgroundIcon) {
-// iconEl = `
-// <div class="map-name">${i[item.showParams] || i.name}</div>
-// <div class="map-icon">
-// <img src="${item.backgroundIcon}">
-// </div>
-// `
-// }
-// } else {
-// iconEl = `<div class="marsBlueGradientPnl">
-// <div>${i[item.showParams] || i.name}</div>
-// </div>`
-// }
-// let divIcon = new DC.DivIcon(
-// new DC.Position(i.lng, i.lat, 0),
-// `<div class="public-map-popup">
-// ${iconEl}
-// </div>`
-// )
-// addTileLayers[item.layerName].addOverlay(divIcon)
-// })
-// })
-// } else {
-// addTileLayers[item.layerName].show = true
-// }
-// }
-// } else {
-// if (addTileLayers[item.layerName]) {
-// if (item.subType == 'labelPoint') {
-// addTileLayers[item.layerName].show = false
-// }
-// }
-// }
-// })
-// }
onUnmounted(() => {
tileLayers && window.$viewer.removeLayer(tileLayers)
@@ -700,6 +776,8 @@
arr.filter(i => i != 'hgyq').forEach(i => {
addTileLayers[i] && window.$viewer.removeLayer(addTileLayers[i])
})
+ // 弹窗销毁
+ destroy()
EventBus.off('restHandleCheckChange', restHandleCheckChange)
EventBus.off('restHandleDelChange', restHandleDelChange)
--
Gitblit v1.9.3