diff --git a/src/components/chart/EffectScatter.vue b/src/components/chart/EffectScatter.vue index 0be1380..3ff8e1c 100644 --- a/src/components/chart/EffectScatter.vue +++ b/src/components/chart/EffectScatter.vue @@ -8,7 +8,10 @@ const props = defineProps({ className: String, id: String, svg: Object, - getCoordinate: Function, + getCoordinate: { + type: Function, + default: null + }, }); let chart = ref(null); @@ -22,33 +25,23 @@ async function updateSvg(svg, option) { axios.get(svg.path).then(({ data }) => { echarts.registerMap(svg.full_name, { svg: data }); chart.value.setOption(option); - chart.value.getZr().on("click", function (params) { - var pixelPoint = [params.offsetX, params.offsetY]; - var dataPoint = chart.value.convertFromPixel({ geoIndex: 0 }, pixelPoint); - currentClickPosition.value = dataPoint; - props.getCoordinate(dataPoint); - chart.value.setOption({ - series: { - data: [dataPoint], - }, + if (props.getCoordinate) { + chart.value.getZr().on("click", function (params) { + var pixelPoint = [params.offsetX, params.offsetY]; + var dataPoint = chart.value.convertFromPixel({ geoIndex: 0 }, pixelPoint); + currentClickPosition.value = dataPoint; + props.getCoordinate(dataPoint); + chart.value.setOption({ + series: { + data: [dataPoint], + }, + }); + }); - console.log(chart.value.getOption()); - }); + } + }); console.log("updateSvg", svg.path); - // fetch(svg.path) - // .then((res) => console.log(res)) - // .then(function (svg) { - // console.log(svg); - // // echarts.registerMap(svg.full_name, { svg }); - // // chart.setOption(option); - // // chart.getZr().on("click", function (params) { - // // var pixelPoint = [params.offsetX, params.offsetY]; - // // var dataPoint = curChart.convertFromPixel({ geoIndex: 0 }, pixelPoint); - // // console.log(dataPoint); - // // currentClickPosition.value = dataPoint; - // // }); - // }); } function init() { @@ -69,7 +62,7 @@ defineExpose({ }); diff --git a/src/components/forge/ForgeForSystem.vue b/src/components/forge/ForgeForSystem.vue new file mode 100644 index 0000000..153c8a0 --- /dev/null +++ b/src/components/forge/ForgeForSystem.vue @@ -0,0 +1,217 @@ + + + + + diff --git a/src/hooks/baja/useSystemStatusByBaja.js b/src/hooks/baja/useSystemStatusByBaja.js index 35ef0ea..e8ba4cf 100644 --- a/src/hooks/baja/useSystemStatusByBaja.js +++ b/src/hooks/baja/useSystemStatusByBaja.js @@ -291,6 +291,7 @@ export default function useSystemStatusByBaja(updateHeatBarIsShow) { }; const fitToView = () => { + if(!searchParams.value.camera_position) return const { x, y, z } = JSON.parse(searchParams.value.camera_position); const newPosition = new THREE.Vector3(x, y, z); //!<<< 相机的新位置 diff --git a/src/hooks/forge/useForgeHeatmap.js b/src/hooks/forge/useForgeHeatmap.js new file mode 100644 index 0000000..e31c3c2 --- /dev/null +++ b/src/hooks/forge/useForgeHeatmap.js @@ -0,0 +1,47 @@ +export default function useForgeHeatmap(){ + + const createHeatMap = async (heatMapName) => { + const { + SurfaceShadingData, + SurfaceShadingPoint, + SurfaceShadingNode, + SurfaceShadingGroup, + } = Autodesk.DataVisualization.Core; + const shadingGroup = new SurfaceShadingGroup(`iot_heatmap_${heatMapName}`); + const rooms = new Map(); + + for (const { id, roomDbId, position, sensorTypes } of deviceList.value) { + if (!id || roomDbId == -1 || !roomDbId) { + continue; + } + + if (!rooms.has(roomDbId)) { + const room = new SurfaceShadingNode(id, roomDbId); + shadingGroup.addChild(room); + rooms.set(roomDbId, room); + } + const room = rooms.get(roomDbId); + room.addPoint(new SurfaceShadingPoint(id, position, sensorTypes)); + } + + const shadingData = new SurfaceShadingData(); + shadingData.addChild(shadingGroup); + shadingData.initialize(forgeViewer.value?.model); + + await dataVizExtension.value.setupSurfaceShading( + forgeViewer.value.model, + shadingData + ); + dataVizExtension.value.registerSurfaceShadingColors( + "temperature", + [0x0000ff, 0x00ff00, 0xffff00, 0xff0000] + ); + dataVizExtension.value.renderSurfaceShading( + `iot_heatmap_${heatMapName}`, + "temperature", + getSensorValue + ); + + console.log(dataVizExtension.value); + }; +} \ No newline at end of file diff --git a/src/hooks/forge/useForgeSprite.js b/src/hooks/forge/useForgeSprite.js new file mode 100644 index 0000000..e764aea --- /dev/null +++ b/src/hooks/forge/useForgeSprite.js @@ -0,0 +1,101 @@ +import { watch, inject, markRaw, ref } from "vue"; +import useAlarmStore from "@/stores/useAlarmStore"; +import hexToRgb from "@/util/hexToRgb"; + +export default function useForgeSprite() { + const store = useAlarmStore(); + const { subscribeData } = inject("system_deviceList"); + const forgeViewer = ref(null); + const dataVizExtn = ref(null); + const updateDataVisualization = async (viewer) => { + if (!forgeViewer.value) { + forgeViewer.value = markRaw(viewer); + } + + const dataVisualization = await NOP_VIEWER.loadExtension( + "Autodesk.DataVisualization" + ); + dataVizExtn.value = markRaw(dataVisualization); + }; + + const onSpriteClicked = (event) => { + event.hasStopped = true; + const data = deviceList.value.find((d) => d.spriteDbId === event.dbId); + modalContent.value = data; + store.getDbIdStore(data.forge_dbid); + toggleModal(event.originalEvent); + }; + // 創建 sprites + const createSprites = async () => { + const DataVizCore = Autodesk.DataVisualization.Core; + const viewableType = DataVizCore.ViewableType.SPRITE; + let spriteColor = new THREE.Color(0xffffff); + const BASEURL = import.meta.env.VITE_FORGE_BASEURL; + const spriteIconUrl = `${BASEURL}/hotspot.svg`; + const style = new DataVizCore.ViewableStyle( + viewableType, + spriteColor, + spriteIconUrl + ); + const viewableData = new DataVizCore.ViewableData(); + viewableData.spriteSize = 24; // Sprites as points of size 24 x 24 pixels + subscribeData.value?.forEach((d, index) => { + const position = d.device_coordinate_3d; + style.color = new THREE.Color(hexToRgb(d.device_normal_color)); + const viewable = new DataVizCore.SpriteViewable( + position, + style, + d.spriteDbId + ); + viewableData.addViewable(viewable); + }); + await viewableData.finish(); + dataVizExtn.value.addViewables(viewableData); + + NOP_VIEWER.addEventListener(DataVizCore.MOUSE_CLICK, onSpriteClicked); + NOP_VIEWER.addEventListener( + Autodesk.Viewing.SELECTION_CHANGED_EVENT, + onSpriteClicked + ); + }; + + const fitToView = () => { + const { x, y, z } = JSON.parse(searchParams.value.camera_position); + const newPosition = new THREE.Vector3(x, y, z); //!<<< 相机的新位置 + + const { + x: x1, + y: y1, + z: z1, + } = JSON.parse(searchParams.value.target_position); //!<<< 计算新焦点位置 + const newTarget = new THREE.Vector3(x1, y1, z1); //!<<< 焦點的新位置 + + NOP_VIEWER.navigation.getCamera().setView({ + position: newPosition.clone(), + target: newTarget.clone(), + }); + setTimeout(() => { + updateDbidPosition(NOP_VIEWER, subscribeData.value); + }, 700); + }; + + const hideAllObjects = () => { + const tree = NOP_VIEWER.model?.getData().instanceTree; + const allDbIdsStr = Object.keys(tree.nodeAccess.dbIdToIndex); + for (var i = 0; i < allDbIdsStr.length; i++) { + NOP_VIEWER.hide(parseInt(allDbIdsStr[i])); + } + + subscribeData.value.forEach((value, index) => { + NOP_VIEWER.show(value.forge_dbid); + }); + + NOP_VIEWER.impl.invalidate(true); + }; + + return { + createSprites, + updateDataVisualization, + hideAllObjects, + }; +} diff --git a/src/views/system/System.vue b/src/views/system/System.vue index bcdd4a2..5dfe30e 100644 --- a/src/views/system/System.vue +++ b/src/views/system/System.vue @@ -1,8 +1,11 @@ diff --git a/src/views/system/SystemFloor.vue b/src/views/system/SystemFloor.vue index 171439d..654a0cd 100644 --- a/src/views/system/SystemFloor.vue +++ b/src/views/system/SystemFloor.vue @@ -1,10 +1,62 @@ - \ No newline at end of file + diff --git a/src/views/system/components/SystemCard.vue b/src/views/system/components/SystemCard.vue index 3e89af2..bd5c1aa 100644 --- a/src/views/system/components/SystemCard.vue +++ b/src/views/system/components/SystemCard.vue @@ -1,29 +1,8 @@ @@ -31,31 +10,34 @@ watch([() => route, () => store.selectedBuilding], ([newRoute, newBuilding]) => \ No newline at end of file + \ No newline at end of file diff --git a/src/views/system/components/SystemSubBar.vue b/src/views/system/components/SystemSubBar.vue new file mode 100644 index 0000000..4471ef5 --- /dev/null +++ b/src/views/system/components/SystemSubBar.vue @@ -0,0 +1,34 @@ + + + + + \ No newline at end of file