This commit is contained in:
dev02 2022-12-31 16:49:54 +08:00
commit c6714a980b
6 changed files with 270 additions and 329 deletions

View File

@ -260,20 +260,31 @@
function show3DModel(urn) { function show3DModel(urn) {
launchViewerForHotspot(urn, (viewer, nodeIds) => { launchViewerForHotspot(urn, (viewer, nodeIds) => {
let devices = [{ let devices = [{
roomDbId: 7567,
id: "Oficina 5", id: "Oficina 5",
//name: "Oficina-", //name: "Oficina-",
position: { x: 3.35, y: -4.81, z: 12.88 }, // x: 0, y: 25, z: -2.5 (3.35, -4.81, 12.88 position: { x: 3.35, y: -4.81, z: 12.88 }, // x: 0, y: 25, z: -2.5 (3.35, -4.81, 12.88
sensorTypes: ["temperature", "humidity"] sensorTypes: ["temperature", "humidity"]
}, {
roomDbId: 7567,
id: "Oficina 6",
//name: "Oficina-",
position: { x: 4.35, y: -4.81, z: 11.88 }, // x: 0, y: 25, z: -2.5 (3.35, -4.81, 12.88
sensorTypes: ["temperature", "humidity"]
}, {
roomDbId: 7567,
id: "Oficina 7",
//name: "Oficina-",
position: { x: 6.35, y: -4.81, z: 16.88 }, // x: 0, y: 25, z: -2.5 (3.35, -4.81, 12.88
sensorTypes: ["temperature", "humidity"]
}]; }];
let option = { let option = {
devices:devices, devices: devices,
} }
let heatMap = new ADHeatMaps(option); let heatMap = new ADHeatMaps(option);
let temp = 10;
heatMap.onComplete = function () { heatMap.onComplete = function () {
debugger heatMap.changeTemp(7567, 32);
heatMap.changeTemp(32);
} }
},"[name=forgeViewer]"); },"[name=forgeViewer]");

View File

@ -22,19 +22,16 @@
</div> </div>
</div> </div>
<script src="lib/echarts.min.js"></script>
<script> <script>
var floChart = null; var floChart = null;
var currentData = []; var currentData = [];
var allDeviceRowData = []; //所有設備原始資料 var allDeviceRowData = []; //所有設備原始資料
var global_emergency_alarm_device_number = []; var global_emergency_alarm_device_number = [];
var zoomToggle = 3; var zoomToggle = 3;
var urn_all = "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6LW1pdHN1YmlzaGkvJUUzJTgwJTkwJUU1JThGJUIwJUU1JThDJTk3JUU0JUI4JUFEJUU4JThGJUIxJUU1JUE0JUE3JUU2JUE4JTkzJUUzJTgwJTkxQVJDJUU5JTlCJTk5JUU5JUExJUFGXzEyMjgubndk";
$(function () { $(function () {
getHotspotPoint(() => { getHotspotPoint(() => {
show3DModel(urn_all); show3DModel(pageAct.urn);
}); });
initChart(); initChart();
getFloData(); getFloData();
@ -867,10 +864,12 @@
} }
} }
// show 3D 模型
function show3DModel(urn) { function show3DModel(urn) {
launchViewerForHotspot(urn, (viewer, nodeIds) => { launchViewerForHotspot(urn, (viewer, nodeIds) => {
getLevelsData(); getLevelsData("R2F", "RF");//剖面的下方樓層,剖面的上方樓層
loadHeatmapForFloor(); var roomsArr = [10481, 10479];//七樓的兩間房間dbid
toLoadHeatmap(roomsArr);
}); });
} }
@ -893,13 +892,13 @@
$.each(res.data, (idx, data) => { $.each(res.data, (idx, data) => {
let item = {}; let item = {};
item.position = {}; item.position = {};
if (item.device_coordinate_3d != null && isJSON(item.device_coordinate_3d)) { if (data.device_coordinate_3d != null && isJSON(data.device_coordinate_3d)) {
item.position = JSON.parse(x.device_coordinate_3d); item.position = JSON.parse(data.device_coordinate_3d);
} }
$.extend(item, data); $.extend(item, data);
myDataList.push(item); myDataList.push(item);
}) })
console.log("1", myDataList) console.log("1", myDataList)
setHotspotPoint(myDataList); setHotspotPoint(myDataList);
callback ? callback() : ""; callback ? callback() : "";

View File

@ -1,11 +1,12 @@
var viewer; var viewer;
let fragProxy; let fragProxy;
var targetFloorZ; var targetFloorZ;
var elevatorSpeed; var elevatorSpeed;
var selector = "#forgeViewer"; var selector = "#forgeViewer";
let myDataList; var myDataList;//設備list
var levels;//剖面用 var levels;//剖面用
var lowerIdx;//剖面的下方樓層
var upperIdx;//剖面的上方樓層
function launchViewer(urn, callback, _selector = "#forgeViewer") { function launchViewer(urn, callback, _selector = "#forgeViewer") {
selector = _selector; selector = _selector;
@ -26,31 +27,6 @@ function launchViewer(urn, callback, _selector = "#forgeViewer") {
callback ? callback(viewer, nodeIds) : ""; callback ? callback(viewer, nodeIds) : "";
}) })
//test
// for (let i = 0; i < urn.length; i++) {
// Autodesk.Viewing.Document.load(urn[i]["urn"], async (doc) => {
// let viewables = doc.getRoot().getDefaultGeometry();
// let model = await viewer.loadDocumentNode(doc, viewables, {
// preserveView: false,
// keepCurrentModels: true,
// placementTransform: (new THREE.Matrix4()).setPosition(urn[i]["xform"]),
// keepCurrentModels: true,
// globalOffset: {
// x: 0,
// y: 0,
// z: 0
// }
// });
// await viewer.waitForLoadDone(); //!<<< Wait for loading materials, properties and geometries for this model (URN)
// });
// }
//loadHeatmaps(viewer.getAllModels()[0]); //!<<< equals to viewer.model
}); });
} }
@ -271,13 +247,6 @@ class elevator3D {
hideColor(nodeId); hideColor(nodeId);
return; return;
} }
//let fragPosition = new THREE.Vector3(position);// 一樓0 二樓15 三樓 26
//fragProxy.position = fragPosition;
//fragProxy.updateAnimTransform();
//viewer.impl.sceneUpdated(true);
} }
} }
@ -285,89 +254,89 @@ function onDocumentLoadSuccess(doc, eleOption) {
var viewables = doc.getRoot().getDefaultGeometry(); var viewables = doc.getRoot().getDefaultGeometry();
viewer.loadDocumentNode(doc, viewables).then(i => { viewer.loadDocumentNode(doc, viewables).then(i => {
// documented loaded, any action? // documented loaded, any action?
}); });
// viewer.addEventListener(Autodesk.Viewing.AGGREGATE_SELECTION_CHANGED_EVENT, (args) => {
// var currSelection = viewer.getSelection();
// var domElem = document.getElementById('id_printer');
// domElem.innerText = currSelection[0];
// });
viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function () { viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function () {
let instanceTree = viewer.model.getData().instanceTree; let instanceTree = viewer.model.getData().instanceTree;
console.log(instanceTree.nodeAccess) console.log(instanceTree.nodeAccess)
allDbIdsStr = Object.keys(instanceTree.nodeAccess.dbIdToIndex); allDbIdsStr = Object.keys(instanceTree.nodeAccess.dbIdToIndex);
getNodeIdByDbIds(allDbIdsStr, (nodeIds) => { getNodeIdByDbIds("【電梯】", (nodeIds) => {
$(selector).trigger("autodesk:loaded", nodeIds); $(selector).trigger("autodesk:loaded", nodeIds);
}); });
}); });
} }
function getNodeIdByDbIds(allDbIdsStr, callback = null) { // 輔助函數,使用 Promise 封裝 viewer.getProperties 函數
let curDbId = 0; function viewerGetProperties(dbIds,attributeName = null) {
let tagId = 0; // 在這裡,我們使用 viewer.getProperties 函數的成功回調函數作為 resolve 函數,
let _parentId = 0; // 並使用 viewer.getProperties 函數的失敗回調函數作為 resolve 函數的參數
let _childId = 0; // 這樣,當 viewer.getProperties 函數成功時Promise 會傳回 properties 物件;
let evelMap = new Map(); // 當 viewer.getProperties 函數失敗時Promise 會傳回 null。
let finTimeout = null; return new Promise((resolve, reject) => {
let fin2Timeout = null; let option = {};
let hasElec = false; if (attributeName != null) {
option.propFilter = [attributeName]; // 限制只返回指定的屬性
allDbIdsStr.forEach((dbId) => { }
curDbId = parseInt(dbId); viewer.model.getBulkProperties2(dbIds, option, // 取得指定元素的屬性信息
viewer.getProperties(curDbId, function (e) { function (elements) {
e.properties.forEach(function (item, idx) { resolve(elements); // 成功時傳回 elements 物件
if (item.displayName == "tag_id" && e.name.indexOf("【電梯】") != -1) {
hasElec = true
tagId = e.dbId;
viewer.getProperties(tagId, function (e2) {
e2.properties.forEach(function (item2, idx2) {
if (item2.displayName == "child") {
_parentId = item2.displayValue;
viewer.getProperties(_parentId, function (e3) {
//var childIdArr = new Array();
/*childIdArr.push(_parentId)*/
//e3.properties.forEach(function (item3, idx3) {
// if (item3.displayName == "child") {
// _childId = item3.displayValue;
// childIdArr.push(_childId);
// }
//});
evelMap.set(item.displayValue, e3.dbId)
console.log("map: " + evelMap);
clearTimeout(finTimeout)
finTimeout = setTimeout(() => {
if (hasElec == true) {
callback ? callback(evelMap) : "";
}
}, 10)
})
}
});
})
} else {
clearTimeout(fin2Timeout)
fin2Timeout = setTimeout(() => {
if (hasElec == false) {
callback ? callback([]) : "";
}
}, 10)
}
});
}) })
});
}
// 輔助函數,使用 Promise 封裝 viewer.search 函數
async function getNodeIdBySearch(text) {
return new Promise((resolve, reject) => {
viewer.search(text, (e) => { // 在 3D 模型中搜索具有指定文本的元素
resolve(e); // 成功時傳回搜索結果
}, (e) => {
resolve(null); // 失敗時傳回 null
})
}) })
}
// 主函數 - 透過 model 全部 node 取得特定 nodeId
async function getNodeIdByDbIds(checkName = "【電梯】", callback = null) {
let evelMap = new Map();
let hasElement = false; // 設置是否有 【tag_id】的node
let targetNodeIds = await getNodeIdBySearch(checkName);
let elements = await viewerGetProperties(targetNodeIds,"【tag_id】");
// 從 elements 中篩選出包含 【tag_id】 屬性的元素
elements = elements.filter(x => x.properties.findIndex(y => y.displayName == "【tag_id】" && y.displayValue == checkName) != -1);
if (elements) {
hasElement = true;
}
for (var e of elements) {
let name = e.properties[0].displayValue; // 獲取元素的 【tag_id】 屬性
let chiElements = null;
// 獲取 node 元素的子元素信息
targetNodeIds = await viewerGetProperties([e.dbId], "child");
// 二次篩選
chiElements = targetNodeIds.filter(x => x.properties.findIndex(y => y.displayName == "child") != -1);
// 獲取子元素的 nodeId
targetNodeIds = chiElements.map(x => x.properties[0].displayValue);
// 獲取子元素的屬性信息
chiElements = await viewerGetProperties(targetNodeIds);
// 將 node 元素的 【tag_id】 屬性和子元素的 nodeId 加入 Map 中
evelMap.set(name, chiElements[0]?.dbId);
}
if (!hasElement) {
callback ? callback([]) : "";
return [];
}
callback ? callback(evelMap) : "";
return evelMap; return evelMap;
} }
function setElevatorFloor(floor) { function setElevatorFloor(floor) {
if (floor == 0) if (floor == 0)
targetFloorZ = 0; targetFloorZ = 0;
@ -382,14 +351,11 @@ function setElevatorSpeed(speed) { //0.01 ~ 1
} }
function movElevator() { function movElevator() {
let tree = viewer.model.getData().instanceTree; let tree = viewer.model.getData().instanceTree;
let nodeId = 10952; let nodeId = 10952;
let fragProxyZ = 0; let fragProxyZ = 0;
var movStatus = 0; // 0=no 1=up 2=down var movStatus = 0; // 0=no 1=up 2=down
if (fragProxy.position.z > targetFloorZ) { if (fragProxy.position.z > targetFloorZ) {
movStatus = 2 movStatus = 2
} }
@ -404,7 +370,6 @@ function movElevator() {
tree.enumNodeFragments(nodeId, function (frag) { tree.enumNodeFragments(nodeId, function (frag) {
fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag);
fragProxy.getAnimTransform(); fragProxy.getAnimTransform();
//let fragPosition = new THREE.Vector3(0, 0, 15);// 一樓0 二樓15 三樓 26
if (movStatus == 2) { if (movStatus == 2) {
fragProxy.position.z -= elevatorSpeed; fragProxy.position.z -= elevatorSpeed;
} }
@ -428,15 +393,6 @@ function movElevator() {
requestAnimationFrame(movElevator); requestAnimationFrame(movElevator);
} }
} }
//let fragPosition = new THREE.Vector3(position);// 一樓0 二樓15 三樓 26
//fragProxy.position = fragPosition;
//fragProxy.updateAnimTransform();
//viewer.impl.sceneUpdated(true);
} }
function getAllDbIds(viewer) { function getAllDbIds(viewer) {
@ -482,9 +438,10 @@ function getForgeToken(callback) {
//------------------ 熱圖 ------------------------------- //------------------ 熱圖 -------------------------------
class ADHeatMaps { class ADHeatMaps {
constructor(option = {}) { constructor(option = {}) {
this.devices = option.devices || []; this.devices = option.devices ?? [];
this.tempVals = []; this.checkNodeString = "【ROOM】";
this.roomDbIds = [8181, 8183, 8185]; this.tempVal = 0;
this.roomDbIds = []; //房間 dbId
this.model = null; this.model = null;
this.dataVizExtn = null; this.dataVizExtn = null;
this.onComplete = option.onComplete ?? null; this.onComplete = option.onComplete ?? null;
@ -502,21 +459,31 @@ class ADHeatMaps {
SurfaceShadingNode, SurfaceShadingNode,
} = Autodesk.DataVisualization.Core; } = Autodesk.DataVisualization.Core;
// 建立一個名為 "Room Panel" 的 SurfaceShadingNode 物件,並將房間的模型給傳入 let nodeIds = await getNodeIdByDbIds(this.checkNodeString);
const shadingNode = new SurfaceShadingNode("Room Panel", this.roomDbIds); nodeIds = Array.from(nodeIds);
nodeIds = nodeIds.map(x => { return { room: x[0] , nodeId: x[1]} });
this.roomDbIds = nodeIds;
// 遍歷每個設備,建立一個 SurfaceShadingPoint 物件並加入到 SurfaceShadingNode 中
this.devices.forEach((device) => {
const shadingPoint = new SurfaceShadingPoint(
device.id,
device.position,
device.sensorTypes
);
shadingNode.addPoint(shadingPoint);
});
// 建立一個 SurfaceShadingData 物件,並將 SurfaceShadingNode 加入到該物件中 // 建立一個 SurfaceShadingData 物件,並將 SurfaceShadingNode 加入到該物件中
const heatmapData = new SurfaceShadingData(); const heatmapData = new SurfaceShadingData();
heatmapData.addChild(shadingNode);
$.each(this.roomDbIds.map(x => x.nodeId), (idx, rDbid) => {
// 建立一個名為 "Room Panel" 的 SurfaceShadingNode 物件,並將房間的模型給傳入,只在該房間呈現溫度
const shadingNode = new SurfaceShadingNode("RoomPanel" + rDbid, rDbid);
// 遍歷每個設備,建立一個 SurfaceShadingPoint 物件並加入到 SurfaceShadingNode 中,透過這些設備渲染溫度
this.devices.filter(x => x.roomDbId == rDbid).forEach((device) => {
const shadingPoint = new SurfaceShadingPoint(
device.id,
device.position,
device.sensorTypes
);
shadingNode.addPoint(shadingPoint);
});
heatmapData.addChild(shadingNode);
})
// 將資料初始化並顯示在模型上 // 將資料初始化並顯示在模型上
heatmapData.initialize(this.model); heatmapData.initialize(this.model);
@ -528,38 +495,34 @@ class ADHeatMaps {
this.dataVizExtn = dataVizExtn; this.dataVizExtn = dataVizExtn;
this.changeTemp(0); this.changeTemp(this.tempVal);
this.onComplete ? this.onComplete() : ""; this.onComplete ? this.onComplete() : "";
} }
// 改變溫度 // 改變溫度
changeTemp = function (temp) { changeTemp = function (devId, temp) {
// 取得新的溫度值 this.tempVal = temp;
function getSensorValue(device, sensorType) { // 透過 device id 取得 roomDbId
return temp / 40; /*const rDbid = this.roomDbIds.filter(x => x.)[0]?.roomDbId;*/
if (rDbid != null) {
// 取得新的溫度值
let getSensorValue = (device, sensorType) => {
return this.tempVal / 40;
}
// 對 "Room Panel" 做表面顏色的渲染,並使用新的溫度值
this.dataVizExtn.renderSurfaceShading("RoomPanel" + rDbid, "temperature", getSensorValue);
} }
// 對 "Room Panel" 做表面顏色的渲染,並使用新的溫度值
this.dataVizExtn.renderSurfaceShading("Room Panel", "temperature", getSensorValue);
} }
} }
function setTransparentBuilding() { function setTransparentBuilding() {
//allDbIdsStr.forEach((dbId) => {
// setTransparency(dbId, 0.2);
//})
for (var i = 0; i < allDbIdsStr.length; i++) { for (var i = 0; i < allDbIdsStr.length; i++) {
setTransparency(parseInt(allDbIdsStr[i]), 0.2); setTransparency(parseInt(allDbIdsStr[i]), 0.2);
} }
} }
function recoverTransparentBuilding() { function recoverTransparentBuilding() {
//allDbIdsStr.forEach((dbId) => {
// setTransparency(dbId, 1);
//})
for (var i = 0; i < allDbIdsStr.length; i++) { for (var i = 0; i < allDbIdsStr.length; i++) {
setTransparency(parseInt(allDbIdsStr[i]), 1); setTransparency(parseInt(allDbIdsStr[i]), 1);
} }
@ -612,16 +575,6 @@ function hideColor(nodeId) {//顏色改成透明
} }
//------------------ 紀錄熱點座標 ---------------
function getHopspotPoint(data) {
//var av = Autodesk.Viewing;
myDataList = data;
//viewer.addEventListener(av.GEOMETRY_LOADED_EVENT, addHotPoint, {
// once: true,
//});
}
//-------------------- end ----------------------
//------------------- 加入熱點 ----------------- //------------------- 加入熱點 -----------------
async function addHotPoint(data) { async function addHotPoint(data) {
var viewer = data.target; var viewer = data.target;
@ -640,7 +593,7 @@ async function addHotPoint(data) {
//熱點 點擊事件註冊 //熱點 點擊事件註冊
viewer.addEventListener(DataVizCore.MOUSE_CLICK, onSpriteClicked);// SPRITE_SELECTED viewer.addEventListener(DataVizCore.MOUSE_CLICK, onSpriteClicked);// SPRITE_SELECTED
//viewer.addEventListener( //viewer.addEventListener(
// Autodesk.Viewing.SELECTION_CHANGED_EVENT, // Autodesk.Viewing.SELECTION_CHANGED_EVENT,
// onSelectionChange // onSelectionChange
@ -651,7 +604,7 @@ async function addHotPoint(data) {
myDataList.forEach((myData, index) => { myDataList.forEach((myData, index) => {
const dbId = 10 + index; const dbId = 10 + index;
const myPosition = myData.position; const myPosition = JSON.parse(myData.device_coordinate_3d);
const viewable = new DataVizCore.SpriteViewable(myPosition, style, dbId); const viewable = new DataVizCore.SpriteViewable(myPosition, style, dbId);
myData._dbId = dbId; myData._dbId = dbId;
viewableData.addViewable(viewable); viewableData.addViewable(viewable);
@ -667,10 +620,9 @@ async function addHotPoint(data) {
if (event != undefined && event != null) { if (event != undefined && event != null) {
if (event.dbId >= dbIdStart && event.dbId <= dbIdEnd) {//event.dbId > 0 && event.dbId < 19 if (event.dbId >= dbIdStart && event.dbId <= dbIdEnd) {//event.dbId > 0 && event.dbId < 19
console.log(`Sprite clicked: ${event.dbId}`); console.log(`Sprite clicked: ${event.dbId}`);
openHotspotModal(); for (let i = dbIdStart; i <= dbIdEnd; i++) {
for(let i = dbIdStart; i <= dbIdEnd; i++){ changeColorForHotspot(i, false);
changeColorForHotspot(i,false); changeScaleForHotspot(i, false);
changeScaleForHotspot(i,false);
} }
let myData = myDataList.filter(x => x._dbId == event.dbId)[0]; let myData = myDataList.filter(x => x._dbId == event.dbId)[0];
$(selector).trigger("autodesk:click:sprite", { event, myData }); $(selector).trigger("autodesk:click:sprite", { event, myData });
@ -694,7 +646,6 @@ async function addHotPoint(data) {
// if (dbIds.length > 0) { // if (dbIds.length > 0) {
// // 處理已選取元件的邏輯 // // 處理已選取元件的邏輯
// $(selector).trigger("autodesk:click:sprite", event); // $(selector).trigger("autodesk:click:sprite", event);
// //openHotspotModal();
// console.log(`------ name: ${viewer.model.getInstanceTree().getNodeName(dbIds)} , dbId: ${dbIds}`);//, id: ${event.clickInfo.object.id}, position.x: ${event.clickInfo.point.x}, y: ${event.clickInfo.point.y}, z: ${event.clickInfo.point.z} // console.log(`------ name: ${viewer.model.getInstanceTree().getNodeName(dbIds)} , dbId: ${dbIds}`);//, id: ${event.clickInfo.object.id}, position.x: ${event.clickInfo.point.x}, y: ${event.clickInfo.point.y}, z: ${event.clickInfo.point.z}
// } else { // } else {
// // 處理沒有選取元件的邏輯 // // 處理沒有選取元件的邏輯
@ -707,7 +658,7 @@ async function addHotPoint(data) {
} }
// 熱點 更換顏色 // 熱點 更換顏色
async function changeColorForHotspot(dbId,type = true) { async function changeColorForHotspot(dbId, type = true) {
const dataVizExtn = await viewer.loadExtension("Autodesk.DataVisualization"); const dataVizExtn = await viewer.loadExtension("Autodesk.DataVisualization");
let spriteColorFocus = new THREE.Color(0x00ffe1); let spriteColorFocus = new THREE.Color(0x00ffe1);
if (!type) { if (!type) {
@ -722,10 +673,10 @@ async function changeColorForHotspot(dbId,type = true) {
} }
// 熱點 更換大小 // 熱點 更換大小
async function changeScaleForHotspot(dbId,type = true) { async function changeScaleForHotspot(dbId, type = true) {
const dataVizExtn = await viewer.loadExtension("Autodesk.DataVisualization"); const dataVizExtn = await viewer.loadExtension("Autodesk.DataVisualization");
let scale = 1; let scale = 1;
if(type){ if (type) {
scale = 1.2; scale = 1.2;
} }
const viewablesToUpdate = dbId; const viewablesToUpdate = dbId;
@ -736,52 +687,16 @@ async function changeScaleForHotspot(dbId,type = true) {
}; };
}); });
} }
//------------------------------ end ----------------------------------
//------------------- end -------------- //------------------------------ 熱圖 ---------------------------------
async function loadHeatmaps(model, roomsArr) {
//----------------- 開關熱點小視窗 ----------------------
function openHotspotModal() {
//var modal = document.getElementById("hotspotModal");
//modal.style.display = "block";
//$("#pills-register-tab").removeClass("active");
//$("#pills-alarm-tab").removeClass("active");
//$("#pills-operation-tab").removeClass("active");
//$("#pills-login-tab").tab("show");
}
function closeHotspotModal() {
//var modal = document.getElementById("hotspotModal");
//modal.style.display = "none";
}
//------------------ end --------------------------------
//------------------ 熱圖 -------------------------------
async function loadHeatmaps(model) {
const dataVizExtn = await viewer.loadExtension("Autodesk.DataVisualization"); const dataVizExtn = await viewer.loadExtension("Autodesk.DataVisualization");
var devices = [];
//取三個空調設備的位置打點 myDataList.forEach((myData, index) => {
const devices = [ devices.push({ id: index, position: JSON.parse(myData.device_coordinate_3d), sensorTypes: ["temperature", "humidity"] });
{ });
id: "Oficina 5",
//name: "Oficina-",
position: { x: 6.98, y: -19.00, z: 16.86 }, // x: 0, y: 25, z: -2.5 (-4.93, -20.61, 16.86)
sensorTypes: ["temperature", "humidity"]
},
{
id: "Oficina 4",
//name: "Oficina-",
position: { x: 35.85, y: -2.24, z: 16.86 }, // x: 0, y: 25.03, z: -2.52 (23.94, -3.85, 16.86)
sensorTypes: ["temperature", "humidity"]
},
{
id: "Oficina 3",
//name: "Oficina-",
position: { x: 6.98, y: -2.24, z: 16.86 }, // x: 0, y: 25.03, z: -2.52 (-4.93, -3.85, 16.86)
sensorTypes: ["temperature", "humidity"]
}
];
//冷氣N5: (-4.93, -20.61, 16.86), N4: (23.94, -3.85, 16.86), N3: (-4.93, -3.85, 16.86)
// Initialize sensor values // Initialize sensor values
let sensorVals = []; let sensorVals = [];
@ -790,7 +705,9 @@ async function loadHeatmaps(model) {
} }
const roomDbIds = []; const roomDbIds = [];
roomDbIds.push(7567); for (var i = 0; i < roomsArr.length; i++) {
roomDbIds.push(roomsArr[i]);
}
const { const {
SurfaceShadingData, SurfaceShadingData,
@ -815,11 +732,10 @@ async function loadHeatmaps(model) {
// Setup surface shading // Setup surface shading
await dataVizExtn.setupSurfaceShading(model, heatmapData); await dataVizExtn.setupSurfaceShading(model, heatmapData);
dataVizExtn.registerSurfaceShadingColors("temperature", [0xff0000, 0x0000ff]); dataVizExtn.registerSurfaceShadingColors("temperature", [0xff0000, 0x0000ff]);
function getSensorValue(device, sensorType) { function getSensorValue(device, sensorType) {
return sensorVals[parseInt(device.id.slice(-1)) - 1]; return sensorVals[parseInt(device.id)];
} }
dataVizExtn.renderSurfaceShading("Room Panel", "temperature", getSensorValue); dataVizExtn.renderSurfaceShading("Room Panel", "temperature", getSensorValue);
@ -832,97 +748,9 @@ async function loadHeatmaps(model) {
dataVizExtn.updateSurfaceShading(getSensorValue); dataVizExtn.updateSurfaceShading(getSensorValue);
}, 2000); }, 2000);
} }
//------------------ end -------------------------------- //------------------------------ end ----------------------------------
async function loadHeatmapsForFloor(model) {
const dataVizExtn = await viewer.loadExtension("Autodesk.DataVisualization"); //--------------------------- -- 剖面 ---------------------------------
//x: -17.33, y: 51.03, z: -2.52
const devices = [
{
id: "Oficina 5",
//name: "Oficina-",
position: { x: 6.98, y: -19.00, z: 16.86 }, // x: 0, y: 25, z: -2.5 (-4.93, -20.61, 16.86)
sensorTypes: ["temperature", "humidity"]
},
{
id: "Oficina 4",
//name: "Oficina-",
position: { x: 35.85, y: -2.24, z: 16.86 }, // x: 0, y: 25.03, z: -2.52 (23.94, -3.85, 16.86)
sensorTypes: ["temperature", "humidity"]
},
{
id: "Oficina 3",
//name: "Oficina-",
position: { x: 6.98, y: -2.24, z: 16.86 }, // x: 0, y: 25.03, z: -2.52 (-4.93, -3.85, 16.86)
sensorTypes: ["temperature", "humidity"]
}
];
// Initialize sensor values
let sensorVals = [];
for (let i = 0; i < devices.length; i++) {
sensorVals[i] = Math.random();
}
const roomDbIds = [];
roomDbIds.push(7567);
const {
SurfaceShadingData,
SurfaceShadingPoint,
SurfaceShadingNode,
} = Autodesk.DataVisualization.Core;
const shadingNode = new SurfaceShadingNode("Room Panel", roomDbIds);
devices.forEach((device) => {
const shadingPoint = new SurfaceShadingPoint(
device.id,
device.position,
device.sensorTypes
);
shadingNode.addPoint(shadingPoint);
});
const heatmapData = new SurfaceShadingData();
heatmapData.addChild(shadingNode);
heatmapData.initialize(model);
// Setup surface shading
await dataVizExtn.setupSurfaceShading(model, heatmapData);
//dataVizExtn.registerSurfaceShadingColors("co2", [0x00ff00, 0xff0000]);
dataVizExtn.registerSurfaceShadingColors("temperature", [0xff0000, 0x0000ff]);
function getSensorValue(device, sensorType) {
return sensorVals[parseInt(device.id.slice(-1)) - 1];
}
dataVizExtn.renderSurfaceShading("Room Panel", "temperature", getSensorValue);
setInterval(() => {
// Modify sensor values.
for (let i = 0; i < devices.length; i++) {
sensorVals[i] = Math.random();
}
dataVizExtn.updateSurfaceShading(getSensorValue);
}, 2000);
}
//
async function loadHeatmap() {
const model = viewer.model;
loadHeatmaps(model);
}
async function loadHeatmapForFloor() {
const model = viewer.model;
loadHeatmapsForFloor(model);
}
//------------ 剖面 ----------------------
async function getRemoteLevels() { async function getRemoteLevels() {
const aecData = await Autodesk.Viewing.Document.getAecModelData(this.viewer.model.getDocumentNode()); const aecData = await Autodesk.Viewing.Document.getAecModelData(this.viewer.model.getDocumentNode());
if (!aecData.levels) return null; if (!aecData.levels) return null;
@ -932,12 +760,6 @@ async function getRemoteLevels() {
return levels2; return levels2;
} }
async function getLevelsData() {
const data = await this.getRemoteLevels();
this.levels = data;
profile();
}
function getCutPlaneParam(idx, n) { function getCutPlaneParam(idx, n) {
if (idx < 0 || !n) return; if (idx < 0 || !n) return;
@ -957,10 +779,38 @@ function getCutPlaneParam(idx, n) {
} }
function profile() { function profile() {
const upperIdx = 6;
const upperCutPlaneParam = this.getCutPlaneParam(upperIdx, 1); const upperCutPlaneParam = this.getCutPlaneParam(upperIdx, 1);
const lowerIdx = 7;
const lowerCutPlaneParam = this.getCutPlaneParam(lowerIdx, -1); const lowerCutPlaneParam = this.getCutPlaneParam(lowerIdx, -1);
this.viewer.setCutPlanes([upperCutPlaneParam, lowerCutPlaneParam]); this.viewer.setCutPlanes([upperCutPlaneParam, lowerCutPlaneParam]);
} }
//----------------- end ----------------------------------------------- //------------------------------ end ----------------------------------
//======================== 外部呼叫function ===========================
//紀錄熱點座標
function getHopspotPoint(data) {
myDataList = data;
}
//呼叫載入熱圖
async function toLoadHeatmap(roomArr) {
const model = viewer.model;
loadHeatmaps(model, roomArr);
}
//取得levels執行剖面
async function getLevelsData(lowerFloor, upperFloor) {
const data = await this.getRemoteLevels();
for (var i = 0; i < data.length; i++) {
if ((data[i].name).indexOf(lowerFloor) != -1) {
lowerIdx = i;
}
if ((data[i].name).indexOf(upperFloor) != -1) {
upperIdx = i;
}
}
this.levels = data;
profile();
}
//============================= end ===================================

View File

@ -219,7 +219,7 @@ namespace FrontendWebApi.ApiControllers
try try
{ {
var sqlString = $@"select f.full_name as floor_tag var sqlString = $@"select f.full_name as floor_tag, f.floor_guid
from sub_system_floor ssf from sub_system_floor ssf
join floor f on ssf.floor_tag = f.full_name and ssf.building_tag = f.building_tag and f.deleted = 0 join floor f on ssf.floor_tag = f.full_name and ssf.building_tag = f.building_tag and f.deleted = 0
where ssf.deleted = 0 and f.building_tag = @building_tag and sub_system_tag = @sub_system_tag order by f.priority"; where ssf.deleted = 0 and f.building_tag = @building_tag and sub_system_tag = @sub_system_tag order by f.priority";
@ -265,7 +265,7 @@ namespace FrontendWebApi.ApiControllers
try try
{ {
var sqlString = $@"select f.full_name, f.InitMapName as map_name, concat(f.floor_map_name,'.svg') as floor_map_name var sqlString = $@"select f.full_name, f.InitMapName as map_name, concat(f.floor_map_name,'.svg') as floor_map_name, f.urn_3D
from sub_system_floor ssf from sub_system_floor ssf
join floor f on ssf.floor_tag = f.full_name and ssf.building_tag = f.building_tag and f.deleted = 0 join floor f on ssf.floor_tag = f.full_name and ssf.building_tag = f.building_tag and f.deleted = 0
where ssf.deleted = 0 and ssf.building_tag = @building_tag and ssf.sub_system_tag = @sub_system_tag and ssf.floor_tag = ifnull(@floor_tag, ssf.floor_tag);"; where ssf.deleted = 0 and ssf.building_tag = @building_tag and ssf.sub_system_tag = @sub_system_tag and ssf.floor_tag = ifnull(@floor_tag, ssf.floor_tag);";
@ -278,7 +278,8 @@ namespace FrontendWebApi.ApiControllers
sqlString = $@"select d.device_guid, d.full_name, d.device_coordinate, d.priority, dk.device_image, d.device_number, CONCAT('{baseURL}', '{deviceKindFilePath}', dk.device_image) AS device_image_url,d.status, sqlString = $@"select d.device_guid, d.full_name, d.device_coordinate, d.priority, dk.device_image, d.device_number, CONCAT('{baseURL}', '{deviceKindFilePath}', dk.device_image) AS device_image_url,d.status,
dk.device_normal_point_id, dk.device_normal_point_guid, dk.device_normal_point_col, dk.device_normal_point_value, dk.device_normal_flashing, dk.device_normal_point_name, dk.device_normal_point_id, dk.device_normal_point_guid, dk.device_normal_point_col, dk.device_normal_point_value, dk.device_normal_flashing, dk.device_normal_point_name,
dk.device_close_point_id, dk.device_close_point_guid, dk.device_close_point_col, dk.device_close_point_value, dk.device_close_flashing, dk.device_close_point_name, dk.device_close_point_id, dk.device_close_point_guid, dk.device_close_point_col, dk.device_close_point_value, dk.device_close_flashing, dk.device_close_point_name,
dk.device_error_point_id, dk.device_error_point_guid, dk.device_error_point_col, dk.device_error_point_value, dk.device_error_flashing, dk.device_error_point_name dk.device_error_point_id, dk.device_error_point_guid, dk.device_error_point_col, dk.device_error_point_value, dk.device_error_flashing, dk.device_error_point_name,
d.room_dbid, d.device_coordinate_3d
from device d from device d
left join device_kind dk on d.device_building_tag = dk.device_building_tag and d.device_system_tag = dk.device_system_tag left join device_kind dk on d.device_building_tag = dk.device_building_tag and d.device_system_tag = dk.device_system_tag
and d.device_name_tag = dk.device_name_tag and d.device_name_tag = dk.device_name_tag
@ -753,5 +754,81 @@ namespace FrontendWebApi.ApiControllers
} }
return Ok(apiResult); return Ok(apiResult);
} }
/// <summary>
/// 取得 forge 模型 node 名稱,透過 node key
/// </summary>
/// <param name="account"></param>
/// <returns></returns>
[HttpPost]
[Route("api/Device/GetForgeNodeName")]
public async Task<ActionResult<List<Variable>>> GetForgeNodeName([FromBody] string forgeNodeKey)
{
ApiResult<List<Variable>> apiResult = new ApiResult<List<Variable>>();
List<Variable> variable = new List<Variable>();
try
{
var param = new
{
@system_type = forge_node_name_system_type,
@system_key = forgeNodeKey
};
var v = await backendRepository.GetAllAsync<Variable>($@"SELECT id,system_value FROM variable WHERE system_type = @system_type and system_key = ifnull(@system_key,system_key)"
, param);
apiResult.Data = v;
apiResult.Code = "0000";
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
return Ok(apiResult);
}
return Ok(apiResult);
}
/// <summary>
/// 樓層列表
/// </summary>
/// <param name="account"></param>
/// <returns></returns>
[HttpPost]
[Route("api/Device/GetNextFloor")]
public async Task<ActionResult<ApiResult<Floor>>> GetNextFloor([FromBody] Floor f)
{
ApiResult<Floor> apiResult = new ApiResult<Floor>();
if (string.IsNullOrEmpty(f.floor_guid))
{
apiResult.Code = "0002";
apiResult.Msg = "需傳入樓層guid";
return apiResult;
}
try
{
var sqlString = $@" SELECT * FROM floor WHERE
priority = (SELECT MIN(priority) FROM floor WHERE priority > (SELECT priority FROM floor WHERE floor_guid = @floor_guid)
AND building_tag = (SELECT building_tag FROM floor WHERE floor_guid = @floor_guid))
AND building_tag = (SELECT building_tag FROM floor WHERE floor_guid = @floor_guid)";
var param = new { @floor_guid = f.floor_guid };
var fr = await backendRepository.GetOneAsync<Floor>(sqlString, param);
apiResult.Code = "0000";
apiResult.Data = fr;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
return Ok(apiResult);
}
return Ok(apiResult);
}
} }
} }

View File

@ -35,13 +35,14 @@ namespace FrontendWebApi.ApiControllers
public string actionName; public string actionName;
public string main_system_type = "device_system_category_layer2"; public string main_system_type = "device_system_category_layer2";
public string sub_system_type = "device_system_category_layer3"; public string sub_system_type = "device_system_category_layer3";
public string forge_node_name_system_type = "forge_check_tag_id";
public ErrorCode errorCode = new ErrorCode(); public ErrorCode errorCode = new ErrorCode();
[Authorize] [Authorize]
public override void OnActionExecuting(ActionExecutingContext filterContext) public override void OnActionExecuting(ActionExecutingContext filterContext)
{ {
controllerName = ControllerContext.RouteData.Values["controller"].ToString(); //controller名稱 controllerName = ControllerContext.RouteData.Values["controller"].ToString(); //controller名稱
actionName = ControllerContext.RouteData.Values["action"].ToString(); //action名稱 actionName = ControllerContext.RouteData.Values["action"].ToString(); //action名稱
var ctx = filterContext.HttpContext; var ctx = filterContext.HttpContext;
ctx.Response.Headers.Add("Access-Control-Allow-Origin", "*"); ctx.Response.Headers.Add("Access-Control-Allow-Origin", "*");
ctx.Response.Headers.Add("Access-Control-Allow-Headers", "*"); ctx.Response.Headers.Add("Access-Control-Allow-Headers", "*");

View File

@ -24,8 +24,10 @@ namespace FrontendWebApi.Models
{ {
public string full_name { get; set; } public string full_name { get; set; }
public string floor_tag { get; set; } public string floor_tag { get; set; }
public string floor_guid { get; set; }
public string map_name { get; set; } public string map_name { get; set; }
public string floor_map_name { get; set; } public string floor_map_name { get; set; }
public string urn_3D { get; set; }
public List<DeviceLists> device_list {get; set;} public List<DeviceLists> device_list {get; set;}
} }
@ -71,6 +73,7 @@ namespace FrontendWebApi.Models
public string device_error_point_name { get; set; } public string device_error_point_name { get; set; }
public string device_error_point_value { get; set; } public string device_error_point_value { get; set; }
public string device_error_flashing { get; set; } public string device_error_flashing { get; set; }
public string room_dbid { get; set; }
public List<DeviceNode> Device_nodes { get; set; } public List<DeviceNode> Device_nodes { get; set; }
} }