diff --git a/src/hooks/web/useProject.tsx b/src/hooks/web/useProject.tsx index baf305d..c92ebe7 100644 --- a/src/hooks/web/useProject.tsx +++ b/src/hooks/web/useProject.tsx @@ -1,8 +1,10 @@ import { reactive } from "vue"; import * as SyCim from "sy-cesium-sdk"; import { LayerTypeEnum } from "@/enums/projectEnum"; +import { queryLayersByPos } from "@/utils/mapUtils"; import axios from "axios"; import { throttle } from "lodash-es"; +import { useProjectStore } from "@/store/modules/project"; const clustering = reactive({ enabled: true, pixelRange: 200, @@ -272,19 +274,30 @@ const baseLayerActions: Record = { }; export function useLayer() { - const mouseMoveEvent = throttle((e: any) => { - const winPos = e.windowPosition; - const target = viewer.scene.pick(winPos); - console.log(target); + const viewerClickEvent = throttle((e: any) => { + if (!e.wgs84SurfacePosition) return; + const projectStore = useProjectStore(); + const selectLayers: any = projectStore.selectedLayers; + // .filter((item: any) => item.isNeedCluster === "1"); + queryLayersByPos(e.wgs84SurfacePosition, selectLayers, (res: any) => { + if (res?.attributes?.showCode) { + const { showCode, showName, scale } = res?.attributes; + window.$bus.$emit("open-water-dialog", { + code: showCode, + name: showName, + scale + }); + } + }); }, 500); - const addMouseMove = () => { - window.viewer?.on(SyCim.MouseEventType.MOUSE_MOVE, mouseMoveEvent, window.viewer); + const addViewerClick = () => { + window.viewer?.on(SyCim.MouseEventType.CLICK, viewerClickEvent, window.viewer); }; - const removeMouseMove = () => { - window.viewer?.off(SyCim.MouseEventType.MOUSE_MOVE, mouseMoveEvent, window.viewer); + const removeViewerClick = () => { + window.viewer?.off(SyCim.MouseEventType.CLICK, viewerClickEvent, window.viewer); }; const addLayer = async (layerData: any) => { - // removeMouseMove(); + removeViewerClick(); const { layerType, url, id, isNeedCluster } = layerData; let action = null; // 超图 S3M图层 @@ -308,93 +321,93 @@ export function useLayer() { } if (!layerType || !(action = layerActions[layerType as string])) return; let layer: any = await action(layerData); - if (isNeedCluster === "1") { - let baseUrl = import.meta.env.VITE_BASE_URL; - const data = await getFeatures(layerData); - if (data?.features?.[0]?.geometry?.type === 'Point') { - let layerConfig = {}; - switch (layerData.nameCn) { - case "水库点": - layerConfig = { - isUniqueRender: true, - field: "ENG_SCAL", - fieldOptions: [ - { name: "1.0", attr: "image", value: "reservoir_big.png" }, - { name: "2.0", attr: "image", value: "reservoir_big.png" }, - { name: "3.0", attr: "image", value: "reservoir_normal.png" }, - { name: "4.0", attr: "image", value: "reservoir_small.png" }, - { name: "5.0", attr: "image", value: "reservoir_small.png" }, - ], - width: 24, - height: 24, - image: "reservoir_big.png", - }; - break; - case "水闸": - layerConfig = { - isUniqueRender: true, - field: "ENG_SCAL", - fieldOptions: [ - { name: "1.0", attr: "image", value: "sluice_big.png" }, - { name: "2.0", attr: "image", value: "sluice_big.png" }, - { name: "3.0", attr: "image", value: "sluice_middle.png" }, - { name: "4.0", attr: "image", value: "sluice_small.png" }, - { name: "5.0", attr: "image", value: "sluice_small.png" }, - ], - image: "sluice_middle.png", - }; - break; - } - layer = new SyCim.ClusterWfsLayer(layerData.id, { - data, - symbol: { - type: "billboardP", - imageProxy: `${baseUrl}/img/map/`, // 图片代理 - style: { - clampToGround: true, - image: "reservoir_small.png", - ...layerConfig, - }, - clustering: { - enabled: clustering.enabled, - pixelRange: clustering.pixelRange, - minimumClusterSize: clustering.minimumClusterSize, - clusterEvent: undefined, - clusterColors: undefined, // 聚合点颜色 - getImage: undefined, // 获取聚合图片的函数 - }, - }, - }); - layer.bindPopup( - (e: any) => { - const graphic = e.graphic; - if (graphic) { - const attr = graphic?.attr; - const code = attr?.RES_CODE ?? attr?.WAGA_CODE; - const name = attr?.RES_NAME ?? attr?.WAGA_NAME; - const scale = attr?.ENG_SCAL ?? attr?.WAGA_TYPE; - if (attr?.RES_CODE) { - window.$bus.$emit("open-water-dialog", { - code, - name, - scale - }); - return ""; - } else { - return `
-
水闸名称:${name}
-
水闸编码:${code}
-
水闸位置:${attr.WAGA_LOC}
-
`; - } - } - }, - { - closeButton: true, - }, - ); - } - } + // if (isNeedCluster === "1") { + // let baseUrl = import.meta.env.VITE_BASE_URL; + // const data = await getFeatures(layerData); + // if (data?.features?.[0]?.geometry?.type === 'Point') { + // let layerConfig = {}; + // switch (layerData.nameCn) { + // case "水库点": + // layerConfig = { + // isUniqueRender: true, + // field: "ENG_SCAL", + // fieldOptions: [ + // { name: "1.0", attr: "image", value: "reservoir_big.png" }, + // { name: "2.0", attr: "image", value: "reservoir_big.png" }, + // { name: "3.0", attr: "image", value: "reservoir_normal.png" }, + // { name: "4.0", attr: "image", value: "reservoir_small.png" }, + // { name: "5.0", attr: "image", value: "reservoir_small.png" }, + // ], + // width: 24, + // height: 24, + // image: "reservoir_big.png", + // }; + // break; + // case "水闸": + // layerConfig = { + // isUniqueRender: true, + // field: "ENG_SCAL", + // fieldOptions: [ + // { name: "1.0", attr: "image", value: "sluice_big.png" }, + // { name: "2.0", attr: "image", value: "sluice_big.png" }, + // { name: "3.0", attr: "image", value: "sluice_middle.png" }, + // { name: "4.0", attr: "image", value: "sluice_small.png" }, + // { name: "5.0", attr: "image", value: "sluice_small.png" }, + // ], + // image: "sluice_middle.png", + // }; + // break; + // } + // layer = new SyCim.ClusterWfsLayer(layerData.id, { + // data, + // symbol: { + // type: "billboardP", + // imageProxy: `${baseUrl}/img/map/`, // 图片代理 + // style: { + // clampToGround: true, + // image: "reservoir_small.png", + // ...layerConfig, + // }, + // clustering: { + // enabled: clustering.enabled, + // pixelRange: clustering.pixelRange, + // minimumClusterSize: clustering.minimumClusterSize, + // clusterEvent: undefined, + // clusterColors: undefined, // 聚合点颜色 + // getImage: undefined, // 获取聚合图片的函数 + // }, + // }, + // }); + // layer.bindPopup( + // (e: any) => { + // const graphic = e.graphic; + // if (graphic) { + // const attr = graphic?.attr; + // const code = attr?.RES_CODE ?? attr?.WAGA_CODE; + // const name = attr?.RES_NAME ?? attr?.WAGA_NAME; + // const scale = attr?.ENG_SCAL ?? attr?.WAGA_TYPE; + // if (attr?.RES_CODE) { + // window.$bus.$emit("open-water-dialog", { + // code, + // name, + // scale + // }); + // return ""; + // } else { + // return `
+ //
水闸名称:${name}
+ //
水闸编码:${code}
+ //
水闸位置:${attr.WAGA_LOC}
+ //
`; + // } + // } + // }, + // { + // closeButton: true, + // }, + // ); + // } + // } layer && window.viewer.addLayer(layer); if (["013000"].includes(layerType)) { // 3d tiles @@ -412,7 +425,7 @@ export function useLayer() { model.id = layerData.id; layer.addGraphic(model); } - // addMouseMove(); + addViewerClick(); }; const removeLayer = (layerData: any) => { const { id, layerType, isNeedCluster } = layerData; @@ -447,8 +460,8 @@ export function useLayer() { addLayer, removeLayer, zoomToLayer, - addMouseMove, - removeMouseMove, + addViewerClick, + removeViewerClick, }; }