export default { methods: { toFixed(num, length) { return parseFloat(num).toFixed(length); }, changeModelAngle(model) { if (this.type === "b3dm") { model.setEditData({ r_y: this.data.roll, r_x: this.data.pitch, r_z: this.data.heading }) } else { model.orientation = Cesium.Transforms.headingPitchRollQuaternion( model.position.getValue(), new Cesium.HeadingPitchRoll( Cesium.Math.toRadians(Cesium.defaultValue(this.data.heading, 0)), Cesium.Math.toRadians(Cesium.defaultValue(this.data.pitch, 0)), Cesium.Math.toRadians(Cesium.defaultValue(this.data.roll, 0)) ) ); } }, changeModelPosition(model) { if (this.type === "b3dm") { if (this.setPositionType === "height") { model.setHeight(this.data.height); } else { model.setPosition([this.data.lon, this.data.lat, this.data.height]); } } else if (this.type === "gltf") { model.position = Cesium.Cartesian3.fromDegrees(this.data.lon, this.data.lat, this.data.height); } }, changeModelScale(model) { model.model.scale = this.data.scale; }, // 编辑模型 editModel(editType, model) { if (editType === "lon" || editType === "lat" || editType === "height") { this.changeModelPosition(model, editType); } else if (editType === "scale") { this.changeModelScale(model); } else if (editType === "setPositionType") { if (this.setPositionType === "height") { model.setHeight(this.data.height); } else { this.data.lon = this.toFixed(model.modelEditData.lon, 6); this.data.lat = this.toFixed(model.modelEditData.lat, 6); this.data.heading = model.modelEditData.r_z; this.data.pitch = model.modelEditData.r_x; this.data.roll = model.modelEditData.r_y; model.setPosition([this.data.lon, this.data.lat, this.data.height]); } } else if (editType === "setPosition") { if (this.setPosition) { this.data.height = this.toFixed(model.modelEditData.height, 2); this.editModel("setPositionType", model); } else { model.restore(); } } else if (editType === "maximumScreenSpaceError") { model.item.maximumScreenSpaceError = this.data.maximumScreenSpaceError || 16; } else if (editType === "maximumMemoryUsage") { model.item.maximumMemoryUsage = this.data.maximumMemoryUsage || 512; } else if (editType === "geometricError" && this.data.geometricError) { model.item._geometricError = this.data.geometricError; } else if (editType === "color") { model.item.style = new Cesium.Cesium3DTileStyle(model.setStyle({ colors: this.data.color })); } else if (editType === "heading" || editType === "pitch" || editType === "roll") { this.changeModelAngle(model); } else if (editType === 'effects' || editType === 'effectsMaxHeight') { model[editType] = this.data[editType]; } }, // 还原 restore(model) { if (this.type === "b3dm") { if (this.defaultEditData.modelHeight != undefined) { model.setHeight(this.defaultEditData.modelHeight); } else if (this.defaultEditData.Center != undefined) { model.setPosition(this.defaultEditData.Center); model.setEditData({ r_y: this.defaultEditData.roll || 0, r_x: this.defaultEditData.pitch || 0, r_z: this.defaultEditData.heading || 0 }) } else { model.restore(); } if (this.defaultEditData.maximumScreenSpaceError) { model.item.maximumScreenSpaceError = this.defaultEditData.maximumScreenSpaceError || 16; } if (this.defaultEditData.color) { model.item.style = new Cesium.Cesium3DTileStyle(model.setStyle({ colors: this.defaultEditData.color })); } else { model.item.style = new Cesium.Cesium3DTileStyle(model.setStyle({ colors: `rgba(255,255,255,${this.defaultEditData.alpha || 1})` })); } } else if (this.type === "gltf") { model.position = Cesium.Cartesian3.fromDegrees(this.defaultEditData.lon, this.defaultEditData.lat, this.defaultEditData.height); model.model.scale = this.defaultEditData.scale; if (this.defaultEditData.heading || this.defaultEditData.pitch || this.defaultEditData.roll) { model.orientation = Cesium.Transforms.headingPitchRollQuaternion( model.position.getValue(), new Cesium.HeadingPitchRoll( Cesium.Math.toRadians(Cesium.defaultValue(this.defaultEditData.heading, 0)), Cesium.Math.toRadians(Cesium.defaultValue(this.defaultEditData.pitch, 0)), Cesium.Math.toRadians(Cesium.defaultValue(this.defaultEditData.roll, 0)) ) ); } else { model.orientation = undefined } } }, }, };