import { updateUserPwd } from "../../../api/api"; import store from "../../../store"; import Bus from "@tools/Bus"; const model = { title: null, modelLayer: null, titleSet: null, from: null, changeLayer(item, res) { store.state.addModelFlag = res; this.title = item; this.setModelMouseMove(); }, changeBatchLayer(item, res) { store.state.addModelFlag = res; this.title = item; }, deleteAll() { if (!this.modelLayer) return; for (var i = 0; i < this.modelLayer._primitives.length; i++) { this.modelLayer.remove(this.modelLayer._primitives[i]); i--; } this.modelLayer = null; }, setModelCoord(res) { store.state.addModelFlag = false; // this.setModelMouseMove(); if (res) { // 长度为62的数码数组 var result = [] var arr = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; for (var i = 0; i < 4; i++) { var num = Math.floor(Math.random() * 62); result.push(arr[num]); } result.join('') var id = new Date().getTime() - Math.floor(Math.random() * 9000) + result; var obj = { id: id, sourceType: 'GLB', name: this.title.name, style: { url: this.title.url, name: this.title.name, longitude: res.longitude, latitude: res.latitude, altitude: res.altitude, heading: res.heading, pitch: res.pitch, roll: res.roll, scale: res.scale, url: this.title.url, id: id, sourceType: 'GLB', } } Bus.$emit("addOtherData", "对象", obj); } }, setModelMouseMove() { if (store.state.addModelFlag) { document.getElementById("myImage").src = layerData.config.img_url + this.title.imgUrl; document.onmousemove = (event) => { this.setMouseMove(event) } } else { document.getElementById("myImage").src = ""; $("#imageModel").hide(); } }, setMouseMove(res) { if (!store.state.addModelFlag) return; var odiv = document.getElementById("imageModel"); odiv.style.top = (res.clientY - 15) + "px"; odiv.style.left = (res.clientX + 15) + "px"; $("#imageModel").show(); }, addModelLayer(res) { if (!res) return; this.getModelLayer(); var modelMatrix = this.getModelMatrix(res.style); var url = layerData.config.Model_URL + res.style.url; var model = this.modelLayer.add(Cesium.Model.fromGltf({ id: res.id, url: url, scale: res.scale, minimumPixelSize: 200, maximumScale: 200000, modelMatrix: modelMatrix })); model.name = res.name; setTimeout(() => { this.updateGlbModel(model, res.style) }, 200); }, setDelGLBModel(res) { for (var i = 0; i < this.modelLayer._primitives.length; i++) { var model = this.modelLayer._primitives[i] if (model.id === res.id) { this.modelLayer.remove(this.modelLayer._primitives[i]); } } }, flyTo(res) { for (var i = 0; i < this.modelLayer._primitives.length; i++) { var model = this.modelLayer._primitives[i] if (model.id == res.id) { // Viewer.trackedEntity = this.modelLayer._primitives[i] Viewer.scene.camera.flyTo(this.modelLayer._primitives[i]) } } }, getEditModelLayer(res) { for (var i = 0; i < this.modelLayer._primitives.length; i++) { var model = this.modelLayer._primitives[i] if (model.id == res.id) { this.titleSet = this.modelLayer._primitives[i]; } } if (!this.titleSet) return; var cm = this.titleSet.modelMatrix; // 获取当前模型modelMatrix var cartesian = new Cesium.Cartesian3(cm[12], cm[13], cm[14]); var carto = Cesium.Cartographic.fromCartesian(cartesian); var m1 = Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Matrix4.getTranslation(cm, new Cesium.Cartesian3()), Cesium.Ellipsoid.WGS84, new Cesium.Matrix4()); var m3 = Cesium.Matrix4.multiply(Cesium.Matrix4.inverse(m1, new Cesium.Matrix4()), cm, new Cesium.Matrix4()); var mat3 = Cesium.Matrix4.getRotation(m3, new Cesium.Matrix3()); var q = Cesium.Quaternion.fromRotationMatrix(mat3); var hpr = Cesium.HeadingPitchRoll.fromQuaternion(q); this.form = { id: this.titleSet.id, sourceType: 'GLB', name: this.titleSet.name, style: { url: res.style.url, name: this.titleSet.name, altitude: Math.round(carto.height * 10) / 10, longitude: res.style.longitude, latitude: res.style.latitude, heading: Math.round(Cesium.Math.toDegrees(hpr.heading)), pitch: Math.round(Cesium.Math.toDegrees(hpr.pitch)), roll: Math.round(Cesium.Math.toDegrees(hpr.roll)), scale: this.titleSet.scale, url: res.style.url, id: this.titleSet.id, sourceType: 'GLB', } } store.state.showModelFlag = false; store.state.isShowEditLayer = true; }, setEditChanege(res, flag) { this.form = res; Bus.$emit("updataTreeNode", this.form.id, this.form); if (flag == 2) { this.updateGlbModel(this.titleSet, this.form.style) } }, updateGlbModel(model, res) { if (!res.longitude) return var cm = model.modelMatrix; // 获取当前模型modelMatrix var nc = Cesium.Cartesian3.fromDegrees(res.longitude, res.latitude, res.altitude); var newHeading = Cesium.Math.toRadians(res.heading); //改变Heading值 var newPitch = Cesium.Math.toRadians(res.pitch); // pitch值填当前模型pitch,上文介绍过如何获取 var newRoll = Cesium.Math.toRadians(res.roll); // 同上 var headingPitchRoll = new Cesium.HeadingPitchRoll(newHeading, newPitch, newRoll); var m = Cesium.Transforms.headingPitchRollToFixedFrame(nc, headingPitchRoll, Cesium.Ellipsoid.WGS84, Cesium.Transforms.eastNorthUpToFixedFrame, new Cesium.Matrix4()); model.modelMatrix = m; model.scale = res.scale; var sm = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(res.scale, res.scale, res.scale), new Cesium.Matrix4()); model.modelMatrix = Cesium.Matrix4.multiply(model.modelMatrix, sm, model.modelMatrix); }, getModelMatrix(res) { var headingPitchRoll = new Cesium.HeadingPitchRoll(res.heading, res.pitch, res.roll); var position = Cesium.Cartesian3.fromDegrees(res.longitude, res.latitude, res.altitude); var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame( position, headingPitchRoll, Cesium.Ellipsoid.WGS84, Cesium.Transforms.eastNorthUpToFixedFrame, new Cesium.Matrix4()); return modelMatrix; }, getModelLayer() { if (this.modelLayer == null) { this.modelLayer = new Cesium.PrimitiveCollection(); this.modelLayer.id = "model_layer"; Viewer.scene.primitives.add(this.modelLayer); } }, addImgUpLayer(res) { var url = layerData.config.Model_URL + '/Data/img/mark1.png' var citizensBankPark = viewer.entities.add({ name: res.name, id: res.id, position: Cesium.Cartesian3.fromDegrees(res.x, res.y, res.z), billboard: { //图标 image: url, width: 32, height: 44, pixelOffset: new Cesium.Cartesian3(0, -40, 0), }, properties: res, }); }, delImgUpLayer(res) { var entity = Viewer.entities._entities._array; for (var i = 0; i < entity.length; i++) { var model = entity[i] if (model.id === res.id) { Viewer.entities.remove(model) } } }, } export default model;