diff --git a/src/components/Common/Cesium/index.js b/src/components/Common/Cesium/index.js index d589f14..c315513 100644 --- a/src/components/Common/Cesium/index.js +++ b/src/components/Common/Cesium/index.js @@ -43,16 +43,10 @@ export default class MyCesium { } viewer = null - // 选中模型 - selectedModel = null - // 右鍵菜單 - contextMenu = { - visible: false, - left: 0, - top: 0, - } // 未完成的在地图上移动类的操作 operations = [] + // 已添加的军标 + plots = [] constructor(dom, options = {}) { const imageryProvider = new Cesium.UrlTemplateImageryProvider({ @@ -127,144 +121,6 @@ export default class MyCesium { // 用于启用或禁用指南针外环。true是启用,false是禁用。默认值为true。如果将选项设置为false,则该环将可见但无效。 enableCompassOuterRing: true, }) - - const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas) - handler.setInputAction(({ position }) => { - if (this.selectedModel) { - this.deselectModel(this.selectedModel) - this.selectedModel = null - } - const pickedObject = viewer.scene.pick(position) - if (!Cesium.defined(pickedObject) || !pickedObject.id) { - window.Emit('pickedObject', null) - return - } - const entity = pickedObject.id - if ( - !entity.properties || - (entity.properties.type != MyCesium.ENTITY_TYPES.MODEL && entity.properties.type != MyCesium.ENTITY_TYPES.IMAGE) - ) { - window.Emit('pickedObject', null) - return - } - this.selectedModel = entity - this.selectModel(entity) - window.Emit('selectedModel', { - id: entity.id, - }) - }, Cesium.ScreenSpaceEventType.LEFT_CLICK) - - // 鼠标右键事件 - handler.setInputAction(({ position }) => { - const pickedObject = viewer.scene.pick(position) - if (!Cesium.defined(pickedObject) || !pickedObject.id) return - const entity = pickedObject.id - const properties = entity.properties - if ( - !properties || - !properties.type || - (properties.type != MyCesium.ENTITY_TYPES.MODEL && properties.type != MyCesium.ENTITY_TYPES.IMAGE) - ) { - return - } - const nomove = properties.nomove - if (selectedModel && entity.id == selectedModel.id && !(nomove && nomove.valueOf())) { - this.showContextMenu(entity) - this.cancelPreviousOperation() - } - }, Cesium.ScreenSpaceEventType.RIGHT_CLICK) - - // shift + 左键事件 - handler.setInputAction( - ({ position }) => { - const pickedObject = viewer.scene.pick(position) - if (!Cesium.defined(pickedObject) || !pickedObject.id) return - const entity = pickedObject.id - if (!entity.properties || entity.properties.type != MyCesium.ENTITY_TYPES.MODEL) return - if (this.selectedModel) { - // 找到已有的properties中的from和to是选中的两个模型的id的线 - const find = viewer.entities.values.find((item) => { - const props = item.properties - if (!props || !props.type || !props.from || !props.to) return false - return ( - (props.from == this.selectedModel.id && props.to == entity.id) || - (props.from == entity.id && props.to == this.selectedModel.id) - ) - }) - // 如果已经有了,移除 - if (find) { - viewer.entities.remove(find) - const { from, to } = find.properties - // 发送删除线的事件 - window.Emit('removeLineBetwenModel', { - id: find.id, - from: from.valueOf(), - to: to.valueOf(), - }) - } else { - const id = Cesium.createGuid() - const currentTime = viewer.clock.currentTime - const positions = [this.selectedModel.position.getValue(currentTime), entity.position.getValue(currentTime)] - if (positions.some((item) => !item)) { - console.log('缺少位置信息') - return - } - this.addLineBetwenModel(id, positions, selectedModel.id, entity.id) - // 发送添加线的事件 - window.Emit('addLineBetwenModel', { - positions, - id, - from: selectedModel.id, - to: entity.id, - }) - } - } - }, - Cesium.ScreenSpaceEventType.LEFT_CLICK, - Cesium.KeyboardEventModifier.SHIFT - ) - } - - /** - * 选中模型 - * @param {Cesium.Entity} entity - */ - selectModel(entity) { - if (!entity.model) return - - const { - properties: { color: _color }, - } = entity - const color = _color.valueOf() - // 设置模型轮廓效果 - entity.model.silhouetteSize = 2 // 轮廓线宽度 - entity.model.silhouetteColor = Cesium.Color.fromCssColorString(color) - entity.label.show = true - } - /** - * 取消选中模型 - * @param {Cesium.Entity} entity - */ - deselectModel(entity) { - if (!entity.model) return - - entity.model.silhouetteSize = 0 // 设置为0取消轮廓 - entity.label.show = false - } - - /** - * 显示右键菜单 - * @param {Cesium.Entity} entity - */ - showContextMenu(entity) { - const currentTime = viewer.clock.currentTime - // 获取entity中心点的屏幕坐标 - const position = entity.position.getValue(currentTime) - const screenPosition = Cesium.SceneTransforms.wgs84ToWindowCoordinates(viewer.scene, position) - - this.contextMenu.left = screenPosition.x + 20 - this.contextMenu.top = screenPosition.y - this.contextMenu.visible = true } // 取消未完成的在地图上移动类的操作(划线之类的) @@ -274,33 +130,13 @@ export default class MyCesium { } /** - * 在模型之间添加线 - * @param id - * @param { Cesium.Cartesian3[] } positions - * @param fromId - * @param toId + * 根据四个角落坐标确定视口位置 + * @param leftUp + * @param rightUp + * @param rightDown + * @param leftDown */ - addLineBetwenModel(id, positions, fromId, toId) { - this.viewer.entities.add({ - id, - polyline: { - positions, - width: 2, - material: new Cesium.PolylineDashMaterialProperty({ - color: Cesium.Color.YELLOW, - dashLength: 20, //短划线长度 - }), - clampToGround: true, - }, - properties: { - type: MyCesium.ENTITY_TYPES.LINE, - from: fromId, - to: toId, - }, - }) - } - - setViewerByAllCorner(leftUp, rightUp, rightDown, leftDown) { + setClientByAllCorner(leftUp, rightUp, rightDown, leftDown) { const [leftUpLon, leftUpLat] = leftUp const [rightUpLon, rightUpLat] = rightUp const [rightDownLon, rightDownLat] = rightDown @@ -328,18 +164,17 @@ export default class MyCesium { * @param x * @param y */ - addPlot(base64, { x, y }) { + addPlot(base64, screenPosition) { this.cancelPreviousOperation() - const id = Cesium.createGuid() - const position = getCatesian3FromPX(this.viewer, { x, y }) - if (!position) return + const position = getCatesian3FromPX(this.viewer, screenPosition) + if (!position) return false + const id = Cesium.createGuid() const isEnemy = false const color = 'red' const radius = 150000 - - this.viewer.entities.add({ + const plot = { id, position, billboard: { @@ -364,6 +199,19 @@ export default class MyCesium { radius, collisions: new Set(), }, - }) + } + this.viewer.entities.add(plot) + this.plots.push(plot) + + // 1. 将屏幕坐标转换为世界坐标(在椭球体表面) + const cartesian = this.viewer.camera.pickEllipsoid(screenPosition, this.viewer.scene.globe.ellipsoid) + if (Cesium.defined(cartesian)) { + // 2. 将世界坐标 (Cartesian3) 转换为地理坐标 Cartographic (弧度) + const cartographic = Cesium.Cartographic.fromCartesian(cartesian) + // 3. 将弧度转换为度数 + const longitude = Cesium.Math.toDegrees(cartographic.longitude) + const latitude = Cesium.Math.toDegrees(cartographic.latitude) + return { plotId: id, longitude, latitude } + } } } diff --git a/src/components/Common/register.js b/src/components/Common/register.js index d8586c2..d52741c 100644 --- a/src/components/Common/register.js +++ b/src/components/Common/register.js @@ -42,5 +42,6 @@ export default { window.MyWebsocket = MyWebsocket Vue.prototype.$bus = Bus + Vue.prototype.$console = window.console }, } diff --git a/src/config/router.config.js b/src/config/router.config.js index 9ad5a0b..9aec983 100644 --- a/src/config/router.config.js +++ b/src/config/router.config.js @@ -261,6 +261,14 @@ export const constantRouterMap = [ }, ], }, + + { + path: '/simulationScene/instructor', + name: 'SimulationSceneInstructor', + component: () => import(/* webpackChunkName: "fail" */ '@/views/simulationScene/instructor/index.vue'), + meta: { title: '教员系统' }, + }, + { path: '/simulationScene/systemSelect', name: 'SimulationSceneSystemSelect', diff --git a/src/views/simulationScene/database/fdsjk.vue b/src/views/simulationScene/database/fdsjk.vue new file mode 100644 index 0000000..516c35f --- /dev/null +++ b/src/views/simulationScene/database/fdsjk.vue @@ -0,0 +1,120 @@ + + + + + diff --git a/src/views/simulationScene/instructor/AddRoom.vue b/src/views/simulationScene/instructor/AddRoom.vue new file mode 100644 index 0000000..3ae9a86 --- /dev/null +++ b/src/views/simulationScene/instructor/AddRoom.vue @@ -0,0 +1,24 @@ + + + + + diff --git a/src/views/simulationScene/instructor/index.vue b/src/views/simulationScene/instructor/index.vue new file mode 100644 index 0000000..b730d4a --- /dev/null +++ b/src/views/simulationScene/instructor/index.vue @@ -0,0 +1,305 @@ + + + + + diff --git a/src/views/simulationScene/sceneEditing/components/SceneEditing.vue b/src/views/simulationScene/sceneEditing/components/SceneEditing.vue index c1ef2d8..8bd0b6b 100644 --- a/src/views/simulationScene/sceneEditing/components/SceneEditing.vue +++ b/src/views/simulationScene/sceneEditing/components/SceneEditing.vue @@ -44,13 +44,7 @@ - + {{ item.name }} @@ -78,7 +72,7 @@