|
@ -1,9 +1,8 @@ |
|
|
import { reactive } from "vue"; |
|
|
import { reactive } from "vue"; |
|
|
import * as SyCim from "sy-cesium-sdk"; |
|
|
import * as SyCim from "sy-cesium-sdk"; |
|
|
import { LayerTypeEnum } from "@/enums/projectEnum"; |
|
|
import { LayerTypeEnum } from "@/enums/projectEnum"; |
|
|
import { queryLayersByPos } from "@/utils/mapUtils"; |
|
|
|
|
|
import axios from "axios"; |
|
|
import axios from "axios"; |
|
|
import { useProjectStore } from "@/store/modules/project"; |
|
|
import { throttle } from "lodash-es"; |
|
|
const clustering = reactive({ |
|
|
const clustering = reactive({ |
|
|
enabled: true, |
|
|
enabled: true, |
|
|
pixelRange: 200, |
|
|
pixelRange: 200, |
|
@ -274,26 +273,19 @@ const baseLayerActions: Record<string, any> = { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
export function useLayer() { |
|
|
export function useLayer() { |
|
|
const viewerClick = (e: any) => { |
|
|
const mouseMoveEvent = throttle((e: any) => { |
|
|
const projectStore = useProjectStore(); |
|
|
const winPos = e.windowPosition; |
|
|
const selectedLayers: any = projectStore.selectedLayers; |
|
|
const target = viewer.scene.pick(winPos); |
|
|
queryLayersByPos(e.wgs84SurfacePosition, selectedLayers, (res: any) => { |
|
|
console.log(target); |
|
|
if (res?.attributes?.showCode) { |
|
|
}, 500); |
|
|
const { showCode, showName } = res?.attributes; |
|
|
const addMouseMove = () => { |
|
|
window.$bus.$emit("open-water-dialog", { |
|
|
window.viewer?.on(SyCim.MouseEventType.MOUSE_MOVE, mouseMoveEvent, window.viewer); |
|
|
code: showCode, |
|
|
|
|
|
name: showName, |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
}; |
|
|
const addViewerClick = () => { |
|
|
const removeMouseMove = () => { |
|
|
window.viewer?.on(SyCim.MouseEventType.CLICK, viewerClick, window.viewer); |
|
|
window.viewer?.off(SyCim.MouseEventType.MOUSE_MOVE, mouseMoveEvent, window.viewer); |
|
|
}; |
|
|
|
|
|
const removeViewerClick = () => { |
|
|
|
|
|
window.viewer?.off(SyCim.MouseEventType.CLICK, viewerClick, window.viewer); |
|
|
|
|
|
}; |
|
|
}; |
|
|
const addLayer = async (layerData: any) => { |
|
|
const addLayer = async (layerData: any) => { |
|
|
|
|
|
// removeMouseMove();
|
|
|
const { layerType, url, id, isNeedCluster } = layerData; |
|
|
const { layerType, url, id, isNeedCluster } = layerData; |
|
|
let action = null; |
|
|
let action = null; |
|
|
// 超图 S3M图层
|
|
|
// 超图 S3M图层
|
|
@ -317,49 +309,92 @@ export function useLayer() { |
|
|
} |
|
|
} |
|
|
if (!layerType || !(action = layerActions[layerType as string])) return; |
|
|
if (!layerType || !(action = layerActions[layerType as string])) return; |
|
|
let layer: any = await action(layerData); |
|
|
let layer: any = await action(layerData); |
|
|
if (isNeedCluster === "1" && layerData.nameCn === "水库点") { |
|
|
if (isNeedCluster === "1") { |
|
|
// let baseUrl = import.meta.env.VITE_BASE_URL;
|
|
|
let baseUrl = import.meta.env.VITE_BASE_URL; |
|
|
// const data = await getFeatures(layerData);
|
|
|
const data = await getFeatures(layerData); |
|
|
// if (data?.features?.[0]?.geometry?.type === 'Point') {
|
|
|
if (data?.features?.[0]?.geometry?.type === 'Point') { |
|
|
// let layerConfig = {};
|
|
|
let layerConfig = {}; |
|
|
// switch (layerData.nameCn) {
|
|
|
switch (layerData.nameCn) { |
|
|
// case "水库点":
|
|
|
case "水库点": |
|
|
// layerConfig = {
|
|
|
layerConfig = { |
|
|
// isUniqueRender: true,
|
|
|
isUniqueRender: true, |
|
|
// field: "ENG_SCAL",
|
|
|
field: "ENG_SCAL", |
|
|
// fieldOptions: [
|
|
|
fieldOptions: [ |
|
|
// { name: "1.0", attr: "image", value: "reservoir_big.png" },
|
|
|
{ name: "1.0", attr: "image", value: "reservoir_big.png" }, |
|
|
// { name: "2.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: "3.0", attr: "image", value: "reservoir_normal.png" }, |
|
|
// { name: "4.0", attr: "image", value: "reservoir_small.png" },
|
|
|
{ name: "4.0", attr: "image", value: "reservoir_small.png" }, |
|
|
// { name: "5.0", attr: "image", value: "reservoir_small.png" },
|
|
|
{ name: "5.0", attr: "image", value: "reservoir_small.png" }, |
|
|
// ],
|
|
|
], |
|
|
// image: "map-title-o.png",
|
|
|
width: 24, |
|
|
// };
|
|
|
height: 24, |
|
|
// break;
|
|
|
image: "reservoir_big.png", |
|
|
// }
|
|
|
}; |
|
|
// layer = new SyCim.ClusterWfsLayer(layerData.id, {
|
|
|
break; |
|
|
// data,
|
|
|
case "水闸": |
|
|
// symbol: {
|
|
|
layerConfig = { |
|
|
// type: "billboardP",
|
|
|
isUniqueRender: true, |
|
|
// imageProxy: `${baseUrl}/img/map/`, // 图片代理
|
|
|
field: "ENG_SCAL", |
|
|
// style: {
|
|
|
fieldOptions: [ |
|
|
// clampToGround: false,
|
|
|
{ name: "1.0", attr: "image", value: "sluice_big.png" }, |
|
|
// image: "reservoir_small.png",
|
|
|
{ name: "2.0", attr: "image", value: "sluice_big.png" }, |
|
|
// ...layerConfig,
|
|
|
{ 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" }, |
|
|
// clustering: {
|
|
|
], |
|
|
// enabled: clustering.enabled,
|
|
|
image: "sluice_middle.png", |
|
|
// pixelRange: clusstering.pixelRange,
|
|
|
}; |
|
|
// minimumClusterSize: clustering.minimumClusterSize,
|
|
|
break; |
|
|
// clusterEvent: undefined,
|
|
|
} |
|
|
// clusterColors: undefined, // 聚合点颜色
|
|
|
layer = new SyCim.ClusterWfsLayer(layerData.id, { |
|
|
// getImage: undefined, // 获取聚合图片的函数
|
|
|
data, |
|
|
// },
|
|
|
symbol: { |
|
|
// });
|
|
|
type: "billboardP", |
|
|
// }
|
|
|
imageProxy: `${baseUrl}/img/map/`, // 图片代理
|
|
|
addViewerClick(); |
|
|
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 `<div class="box">
|
|
|
|
|
|
<div class="detail-item"><span>水闸名称</span>:${name}</div> |
|
|
|
|
|
<div class="detail-item"><span>水闸编码</span>:${code}</div> |
|
|
|
|
|
<div class="detail-item"><span>水闸位置</span>:${attr.WAGA_LOC}</div> |
|
|
|
|
|
</div>`;
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
closeButton: true, |
|
|
|
|
|
}, |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
layer && window.viewer.addLayer(layer); |
|
|
layer && window.viewer.addLayer(layer); |
|
|
if (["013000"].includes(layerType)) { |
|
|
if (["013000"].includes(layerType)) { |
|
@ -378,9 +413,10 @@ export function useLayer() { |
|
|
model.id = layerData.id; |
|
|
model.id = layerData.id; |
|
|
layer.addGraphic(model); |
|
|
layer.addGraphic(model); |
|
|
} |
|
|
} |
|
|
|
|
|
// addMouseMove();
|
|
|
}; |
|
|
}; |
|
|
const removeLayer = (layerData: any) => { |
|
|
const removeLayer = (layerData: any) => { |
|
|
const { id, layerType, isNeedCluster, nameCn } = layerData; |
|
|
const { id, layerType, isNeedCluster } = layerData; |
|
|
if (!layerType) return; |
|
|
if (!layerType) return; |
|
|
const type: any = LayerTypeEnum[layerType as never]; |
|
|
const type: any = LayerTypeEnum[layerType as never]; |
|
|
|
|
|
|
|
@ -395,8 +431,13 @@ export function useLayer() { |
|
|
} as any); |
|
|
} as any); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (isNeedCluster === "1" && nameCn === "水库点") { |
|
|
if (isNeedCluster === "1") { |
|
|
removeViewerClick(); |
|
|
const layer = window.viewer.getLayer(id); |
|
|
|
|
|
layer?.clear(); |
|
|
|
|
|
window.viewer.removeLayer({ |
|
|
|
|
|
id, |
|
|
|
|
|
type: SyCim.LayerType['CLUSTER_WFS_PRIMITIVE'], |
|
|
|
|
|
} as any); |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
const zoomToLayer = (data: any) => { |
|
|
const zoomToLayer = (data: any) => { |
|
@ -407,7 +448,8 @@ export function useLayer() { |
|
|
addLayer, |
|
|
addLayer, |
|
|
removeLayer, |
|
|
removeLayer, |
|
|
zoomToLayer, |
|
|
zoomToLayer, |
|
|
removeViewerClick, |
|
|
addMouseMove, |
|
|
|
|
|
removeMouseMove, |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|