production forge sprite route | 熱圖api
This commit is contained in:
parent
9a77f7a719
commit
7f570fc366
@ -1,3 +1,3 @@
|
|||||||
VITE_API_BASEURL = "https://ibms-cvilux-api.production.mjmtech.com.tw"
|
VITE_API_BASEURL = "https://ibms-cvilux-api.production.mjmtech.com.tw"
|
||||||
VITE_FILE_API_BASEURL = "https://ibms-cvilux.production.mjmtech.com.tw"
|
VITE_FILE_API_BASEURL = "https://ibms-cvilux.production.mjmtech.com.tw"
|
||||||
VITE_FORGE_BASEURL = "http://202.39.218.221:8080/file/netzero"
|
VITE_FORGE_BASEURL = "https://cgems.cvilux-group.com:8088/dist"
|
@ -1,36 +1,75 @@
|
|||||||
import { watch, inject, markRaw, ref } from "vue";
|
import { watch, inject, markRaw, ref } from "vue";
|
||||||
|
import { useRoute } from "vue-router";
|
||||||
|
|
||||||
export default function useForgeHeatmap(dataVizExtn, forgeViewer){
|
export default function useForgeHeatmap() {
|
||||||
const { subscribeData } = inject("system_deviceList");
|
const route = useRoute();
|
||||||
|
const { subscribeData, realtimeData } = inject("system_deviceList");
|
||||||
|
|
||||||
const createHeatMap = async (heatMapName) => {
|
// const data = computed(()=>)
|
||||||
|
|
||||||
|
const forgeViewer = ref(null);
|
||||||
|
const dataVizExtn = ref(null);
|
||||||
|
const updateViewExtension = (viewer, dataVisualization) => {
|
||||||
|
forgeViewer.value = viewer;
|
||||||
|
dataVizExtn.value = dataVisualization;
|
||||||
|
};
|
||||||
|
|
||||||
|
//create the heatmap
|
||||||
|
function getSensorValue(device, sensorType, pointData) {
|
||||||
|
const dev = realtimeData.value.find(
|
||||||
|
({ device_number }) => device_number === device.id
|
||||||
|
);
|
||||||
|
const point = dev.data.find(({ point }) => point === route.query?.gas);
|
||||||
|
console.log(9, device, dev, point);
|
||||||
|
|
||||||
|
return (point?.value || 0) / 40;
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => realtimeData,
|
||||||
|
() => {
|
||||||
|
Object.keys(dataVizExtn.value?.surfaceShading).length &&
|
||||||
|
dataVizExtn.value.updateSurfaceShading(getSensorValue);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
deep: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const createHeatMap = async () => {
|
||||||
|
const heatMapName = `iot_heatmap_${route.query?.gas}`;
|
||||||
|
console.log("createHeatMap", heatMapName);
|
||||||
const {
|
const {
|
||||||
SurfaceShadingData,
|
SurfaceShadingData,
|
||||||
SurfaceShadingPoint,
|
SurfaceShadingPoint,
|
||||||
SurfaceShadingNode,
|
SurfaceShadingNode,
|
||||||
SurfaceShadingGroup,
|
SurfaceShadingGroup,
|
||||||
} = Autodesk.DataVisualization.Core;
|
} = Autodesk.DataVisualization.Core;
|
||||||
const shadingGroup = new SurfaceShadingGroup(`iot_heatmap_${heatMapName}`);
|
const shadingGroup = new SurfaceShadingGroup(`${heatMapName}_group`);
|
||||||
const rooms = new Map();
|
const rooms = new Map();
|
||||||
|
|
||||||
for (const { id, roomDbId, position, sensorTypes } of subscribeData.value) {
|
subscribeData.value.forEach(
|
||||||
if (!id || roomDbId == -1 || !roomDbId) {
|
({
|
||||||
continue;
|
device_number: id,
|
||||||
|
room_dbid: roomDbId,
|
||||||
|
device_coordinate_3d: position,
|
||||||
|
sensorTypes,
|
||||||
|
}) => {
|
||||||
|
if (!id || roomDbId == -1 || !roomDbId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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));
|
||||||
}
|
}
|
||||||
|
);
|
||||||
if (!rooms.has(roomDbId)) {
|
const shadingData = new SurfaceShadingData(`${heatMapName}_data`);
|
||||||
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.addChild(shadingGroup);
|
||||||
shadingData.initialize(forgeViewer.value?.model);
|
shadingData.initialize(forgeViewer.value?.model);
|
||||||
|
|
||||||
await dataVizExtn.value.setupSurfaceShading(
|
await dataVizExtn.value.setupSurfaceShading(
|
||||||
forgeViewer.value.model,
|
forgeViewer.value.model,
|
||||||
shadingData
|
shadingData
|
||||||
@ -40,10 +79,22 @@ export default function useForgeHeatmap(dataVizExtn, forgeViewer){
|
|||||||
[0x0000ff, 0x00ff00, 0xffff00, 0xff0000]
|
[0x0000ff, 0x00ff00, 0xffff00, 0xff0000]
|
||||||
);
|
);
|
||||||
dataVizExtn.value.renderSurfaceShading(
|
dataVizExtn.value.renderSurfaceShading(
|
||||||
`iot_heatmap_${heatMapName}`,
|
|
||||||
heatMapName,
|
heatMapName,
|
||||||
|
route.query.gas.shading,
|
||||||
getSensorValue
|
getSensorValue
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
watch(
|
||||||
|
() => route.query,
|
||||||
|
(newValue, oldValue) => {
|
||||||
|
if (newValue.gas !== oldValue.gas) {
|
||||||
|
createHeatMap(newValue.gas);
|
||||||
|
} else if (!newValue.gas) {
|
||||||
|
dataVizExtn.value?.removeSurfaceShading();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return { createHeatMap, updateViewExtension };
|
||||||
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { watch, inject, markRaw, ref, computed } from "vue";
|
import { watch, inject, markRaw, ref, computed, provide } from "vue";
|
||||||
import useAlarmStore from "@/stores/useAlarmStore";
|
import useAlarmStore from "@/stores/useAlarmStore";
|
||||||
import hexToRgb from "@/util/hexToRgb";
|
import hexToRgb from "@/util/hexToRgb";
|
||||||
import { useRoute } from "vue-router";
|
|
||||||
import useSelectedFloor from "@/hooks/useSelectedFloor";
|
import useSelectedFloor from "@/hooks/useSelectedFloor";
|
||||||
|
import useForgeHeatmap from "./useForgeHeatmap";
|
||||||
|
|
||||||
export default function useForgeSprite() {
|
export default function useForgeSprite() {
|
||||||
const store = useAlarmStore();
|
const store = useAlarmStore();
|
||||||
@ -12,6 +12,9 @@ export default function useForgeSprite() {
|
|||||||
);
|
);
|
||||||
const forgeViewer = ref(null);
|
const forgeViewer = ref(null);
|
||||||
const dataVizExtn = ref(null);
|
const dataVizExtn = ref(null);
|
||||||
|
|
||||||
|
const { createHeatMap, updateViewExtension } = useForgeHeatmap();
|
||||||
|
|
||||||
const updateDataVisualization = async (viewer) => {
|
const updateDataVisualization = async (viewer) => {
|
||||||
if (!forgeViewer.value) {
|
if (!forgeViewer.value) {
|
||||||
forgeViewer.value = markRaw(viewer);
|
forgeViewer.value = markRaw(viewer);
|
||||||
@ -21,6 +24,7 @@ export default function useForgeSprite() {
|
|||||||
"Autodesk.DataVisualization"
|
"Autodesk.DataVisualization"
|
||||||
);
|
);
|
||||||
dataVizExtn.value = markRaw(dataVisualization);
|
dataVizExtn.value = markRaw(dataVisualization);
|
||||||
|
updateViewExtension(markRaw(viewer), markRaw(dataVisualization));
|
||||||
};
|
};
|
||||||
|
|
||||||
function onSpriteClicked(event) {
|
function onSpriteClicked(event) {
|
||||||
@ -72,7 +76,6 @@ export default function useForgeSprite() {
|
|||||||
viewableData.spriteSize = 24; // Sprites as points of size 24 x 24 pixels
|
viewableData.spriteSize = 24; // Sprites as points of size 24 x 24 pixels
|
||||||
showData.value?.forEach((d, index) => {
|
showData.value?.forEach((d, index) => {
|
||||||
if (d.device_coordinate_3d) {
|
if (d.device_coordinate_3d) {
|
||||||
console.log(d.device_coordinate_3d);
|
|
||||||
const position = d.device_coordinate_3d;
|
const position = d.device_coordinate_3d;
|
||||||
style.color = new THREE.Color(hexToRgb(d.device_normal_color));
|
style.color = new THREE.Color(hexToRgb(d.device_normal_color));
|
||||||
const viewable = new DataVizCore.SpriteViewable(
|
const viewable = new DataVizCore.SpriteViewable(
|
||||||
@ -89,6 +92,7 @@ export default function useForgeSprite() {
|
|||||||
viewableData.finish().then(
|
viewableData.finish().then(
|
||||||
() => {
|
() => {
|
||||||
dataVizExtn.value.addViewables(viewableData);
|
dataVizExtn.value.addViewables(viewableData);
|
||||||
|
createHeatMap();
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
@ -171,6 +175,6 @@ export default function useForgeSprite() {
|
|||||||
updateDataVisualization,
|
updateDataVisualization,
|
||||||
hideAllObjects,
|
hideAllObjects,
|
||||||
forgeClickListener,
|
forgeClickListener,
|
||||||
clear
|
clear,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user