Browse Source

1.更换地图提供

2.处理mitt事件
master
DIAMOND 1 year ago
parent
commit
77ec03d845
  1. 15
      src/views/earthMap/edit/EarthComp.vue
  2. 355
      src/views/military/modules/ai/monitorArea/components/VCEarthViewer.vue

15
src/views/earthMap/edit/EarthComp.vue

@ -627,6 +627,9 @@
this.clearAlarmModel(eventSerialNum) this.clearAlarmModel(eventSerialNum)
} }
}) })
$mitt.on('fly', function (callback) {
that.fly(callback)
})
} }
@ -841,7 +844,7 @@
}); });
} }
async fly() { async fly(callback:any = null) {
let position, rotation, viewDistance, duration; let position, rotation, viewDistance, duration;
// //
let parentData = let parentData =
@ -866,6 +869,11 @@
rotation = [data.rotationX, data.rotationY, data.rotationZ]; rotation = [data.rotationX, data.rotationY, data.rotationZ];
viewDistance = data.viewDistance; viewDistance = data.viewDistance;
duration = data.duration ? data.duration : 0; duration = data.duration ? data.duration : 0;
// mitt
if(callback){
callback(position,rotation,viewDistance,duration);
return
}
this._earth.camera.flyTo(position, viewDistance, rotation, duration); this._earth.camera.flyTo(position, viewDistance, rotation, duration);
// //
window.$flyTo = this.flyTo = () => { window.$flyTo = this.flyTo = () => {
@ -877,6 +885,11 @@
rotation = [parentData[0].rotationX, parentData[0].rotationY, parentData[0].rotationZ]; rotation = [parentData[0].rotationX, parentData[0].rotationY, parentData[0].rotationZ];
viewDistance = parentData[0].viewDistance; viewDistance = parentData[0].viewDistance;
duration = parentData[0].duration; duration = parentData[0].duration;
// mitt
if(callback){
callback(position,rotation,viewDistance,duration);
return
}
// //
this._earth.camera.flyTo(position, viewDistance, rotation, duration); this._earth.camera.flyTo(position, viewDistance, rotation, duration);
// //

355
src/views/military/modules/ai/monitorArea/components/VCEarthViewer.vue

@ -5,33 +5,21 @@
功能概述引入vc-drawings地图绘制插件实现区域绘制并编辑保存数据注意数据格式注意数据格式注意数据格式 功能概述引入vc-drawings地图绘制插件实现区域绘制并编辑保存数据注意数据格式注意数据格式注意数据格式
--> -->
<template> <template>
<a-modal :visible="visible" :title="title" @ok="handleOk" @cancel="handleCancel" width="60vw" destroyOnClose wrapClassName="EarthMap"> <a-modal :visible="visible" :title="title" @ok="handleOk" @cancel="handleCancel" width="60vw" destroyOnClose
wrapClassName="EarthMap">
<a-row ref="viewerContainer" class="demo-viewer"> <a-row ref="viewerContainer" class="demo-viewer">
<vc-viewer> <vc-viewer :showCredit="false">
<!-- 修改定位 位置偏移 --> <!-- 修改定位 位置偏移 -->
<vc-drawings <vc-drawings ref="drawingsRef" position="top-left" :main-fab-opts="mainFabOpts" :offset="[10, 50]"
ref="drawingsRef" :editable="editable" :clamp-to-ground="clampToGround" @draw-evt="drawEvt" @active-evt="activeEvt"
position="top-left" @editor-evt="editorEvt" @mouse-evt="mouseEvt" @clear-evt="clearEvt" @ready="drawingsReadyDefault"
:main-fab-opts="mainFabOpts" :pin-drawing-opts="pinDrawingOpts" :point-drawing-opts="pointDrawingOpts"
:offset="[10, 50]" :polygon-drawing-opts="polygonDrawingOpts" :polyline-drawing-opts="polylineDrawingOpts"
:editable="editable" :regular-drawing-opts="regularDrawingOpts" :circle-drawing-opts="circleDrawingOpts"
:clamp-to-ground="clampToGround" :rectangle-drawing-opts="rectangleDrawingOpts"></vc-drawings>
@draw-evt="drawEvt"
@active-evt="activeEvt"
@editor-evt="editorEvt"
@mouse-evt="mouseEvt"
@clear-evt="clearEvt"
@ready="drawingsReadyDefault"
:pin-drawing-opts="pinDrawingOpts"
:point-drawing-opts="pointDrawingOpts"
:polygon-drawing-opts="polygonDrawingOpts"
:polyline-drawing-opts="polylineDrawingOpts"
:regular-drawing-opts="regularDrawingOpts"
:circle-drawing-opts="circleDrawingOpts"
:rectangle-drawing-opts="rectangleDrawingOpts"
></vc-drawings>
<vc-layer-imagery> <vc-layer-imagery>
<vc-imagery-provider-tianditu map-style="img_c" :maximum-level="17" token="436ce7e50d27eede2f2929307e6b33c0"></vc-imagery-provider-tianditu> <!-- <vc-imagery-provider-tianditu map-style="img_c" :maximum-level="17" token="436ce7e50d27eede2f2929307e6b33c0"></vc-imagery-provider-tianditu> -->
<vc-imagery-provider-tms :url="mapURL"></vc-imagery-provider-tms>
</vc-layer-imagery> </vc-layer-imagery>
<vc-terrain-provider-cesium v-if="addTerrain"></vc-terrain-provider-cesium> <vc-terrain-provider-cesium v-if="addTerrain"></vc-terrain-provider-cesium>
</vc-viewer> </vc-viewer>
@ -50,11 +38,15 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
import { onMounted, watch } from 'vue'; import $mitt from '@/utils/earthMap/mitt';
import { ref, getCurrentInstance, nextTick } from 'vue'; import { onMounted, watch } from 'vue';
const { proxy }: any = getCurrentInstance(); import { ref, getCurrentInstance, nextTick } from 'vue';
const props = defineProps({ import { useUserStore } from '/@/store/modules/user';
import { defHttp } from '/@/utils/http/axios';
const { proxy }: any = getCurrentInstance();
const props = defineProps({
title: { title: {
type: String, type: String,
default: '区域选取', default: '区域选取',
@ -73,24 +65,31 @@
type: String, type: String,
default: '', default: '',
}, },
}); });
//
const mapURL = import.meta.env.VITE_GLOB_EARTHMAP_URL + import.meta.env.VITE_GLOB_SATELLITE_URL
// const mapURL = "http://127.0.0.1:8088/dt/mapTile/satellite_zh/"
// console.log("mapURL",mapURL);
const userStore = useUserStore();
//
const sceneInfo: any = ref()
let $viewer = ref(undefined); let $viewer: any = ref(undefined);
const drawingsRef = ref(); const drawingsRef = ref();
// //
const addTerrain: any = ref(false); const addTerrain: any = ref(false);
// //
const editable: any = ref(false); const editable: any = ref(false);
// //
const clampToGround: any = ref(false); const clampToGround: any = ref(false);
// //
const mainFabOpts = ref<any>({ const mainFabOpts = ref<any>({
direction: 'right', direction: 'right',
}); });
// //
const emit = defineEmits(['update:areaData', 'update:drawData']); const emit = defineEmits(['update:areaData', 'update:drawData']);
// //
const drawData = ref<any>({ const drawData = ref<any>({
name: '绘图数据', name: '绘图数据',
drawList: [ drawList: [
{ {
@ -129,19 +128,19 @@
list: [], list: [],
}, },
], ],
}); });
const areaDataLits = ref<any>([]); const areaDataLits = ref<any>([]);
// 线 // 线
const polylineDrawingOpts = ref<any>({ const polylineDrawingOpts = ref<any>({
// 线 // 线
preRenderDatas: [], preRenderDatas: [],
// loop: true, // loop: true,
onClick(e: any) { onClick(e: any) {
console.log(e); console.log(e);
}, },
}); });
// //
const pinDrawingOpts = ref<any>({ const pinDrawingOpts = ref<any>({
preRenderDatas: [], preRenderDatas: [],
billboardOpts: { billboardOpts: {
image: 'https://zouyaoji.top/vue-cesium/images/grepin.png', image: 'https://zouyaoji.top/vue-cesium/images/grepin.png',
@ -156,9 +155,9 @@
console.log(e); console.log(e);
}, },
}, },
}); });
// //
const pointDrawingOpts = ref<any>({ const pointDrawingOpts = ref<any>({
preRenderDatas: [], preRenderDatas: [],
pointOpts: { pointOpts: {
color: 'red', color: 'red',
@ -166,45 +165,45 @@
console.log(e); console.log(e);
}, },
}, },
}); });
// //
const polygonDrawingOpts = ref<any>({ const polygonDrawingOpts = ref<any>({
preRenderDatas: [], preRenderDatas: [],
onClick(e: any) { onClick(e: any) {
console.log(e); console.log(e);
}, },
}); });
// //
const regularDrawingOpts = ref<any>({ const regularDrawingOpts = ref<any>({
preRenderDatas: [], preRenderDatas: [],
onClick(e: any) { onClick(e: any) {
console.log(e); console.log(e);
}, },
}); });
// //
const circleDrawingOpts = ref<any>({ const circleDrawingOpts = ref<any>({
preRenderDatas: [], preRenderDatas: [],
onClick(e: any) { onClick(e: any) {
console.log(e); console.log(e);
}, },
}); });
// //
const rectangleDrawingOpts = ref<any>({ const rectangleDrawingOpts = ref<any>({
preRenderDatas: [], preRenderDatas: [],
onClick(e: any) { onClick(e: any) {
console.log(e); console.log(e);
}, },
}); });
// //
async function handleOk(viewer) { async function handleOk(viewer) {
// //
updateDraw(viewer); updateDraw(viewer);
message.success('区域编辑成功,请保存上传!'); message.success('区域编辑成功,请保存上传!');
//退 //退
handleCancel(); handleCancel();
} }
// //
function updateDraw(viewer: any) { function updateDraw(viewer: any) {
// //
getDrawingActionInstances(viewer); getDrawingActionInstances(viewer);
// //
@ -213,9 +212,9 @@
// //
emit('update:drawData', drawDataToString); emit('update:drawData', drawDataToString);
emit('update:areaData', areaDataToString); emit('update:areaData', areaDataToString);
} }
// //
function loadingData() { function loadingData() {
if (props.areaData || props.drawData) { if (props.areaData || props.drawData) {
let loadingSource = JSON.parse(props.drawData); let loadingSource = JSON.parse(props.drawData);
drawData.value.drawList = loadingSource; drawData.value.drawList = loadingSource;
@ -255,9 +254,9 @@
} }
}); });
} }
} }
// //
function getDrawingActionInstances(viewer: any) { function getDrawingActionInstances(viewer: any) {
// //
let areaData: any = []; let areaData: any = [];
let k = 0; let k = 0;
@ -413,32 +412,158 @@
} }
}); });
areaDataLits.value = areaData; areaDataLits.value = areaData;
} }
//visible //visible
watch( watch(
() => props.visible, () => props.visible,
(val) => { (val) => {
if (val) { if (val) {
loadingData(); loadingData();
} }
} }
); );
//
function handleCancel() { onMounted(async () => {
await loadingData();
});
//
function handleCancel() {
nextTick(() => { nextTick(() => {
proxy.$parent.mapVisible = false; proxy.$parent.mapVisible = false;
}); });
} }
async function drawingsReadyDefault({ viewer, cesiumObject }) { async function drawingsReadyDefault(e) {
let viewer = e.viewer
console.log("viewer", viewer);
console.log("e", e);
$viewer.value = viewer; $viewer.value = viewer;
// //
$viewer.value.cesiumWidget.screenSpaceEventHandler.removeInputAction(window.Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK); $viewer.value.cesiumWidget.screenSpaceEventHandler.removeInputAction(window.Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
}
onMounted(async () => { //
await loadingData(); await getSceneInfo();
//
await fly(viewer);
}
//
async function getSceneInfo() {
//
const orgCode: any = userStore.userInfo?.orgCode;
// this.orgCode = orgCode;
// console.log("orgCode",orgCode);
// 3屿
if (orgCode.length == 3) {
//
await defHttp.get({
url: '/military/msMapScene/list',
params: {
pageNo: 1,
pageSize: 999,
sceneCode: "00001-00001*",
column: 'sysOrgCode',
order: 'asc',
}
}, { isTransformResponse: false }).then((response) => {
// console.log("response",response);
const records = response.result.records
// 屿
sceneInfo.value = records;
return records;
}); });
} else {
await defHttp.get({
url: '/military/msMapScene/queryByOrgCode',
params: { orgCode: orgCode }
}, { isTransformResponse: false })
.then((response) => {
const data = response.result;
// 屿Object
sceneInfo.value = data;
return data;
});
}
}
function drawEvt(e, viewer) { //
function fly(viewer: any = null) {
let position, rotation, viewDistance, duration;
//
let ellipsoid = viewer.scene.globe.ellipsoid;
//
let parentData =
sceneInfo.value instanceof Array
? sceneInfo.value.filter((item, index) => {
return item.sceneCode == "00001-00001";
})
: sceneInfo.value;
//
let data = sceneInfo.value instanceof Array ?
sceneInfo.value.filter((item, index) => {
return item.sceneCode.length > 3;
})
: sceneInfo.value;
// console.log("data",data);
// console.log("this.sceneInfo",this.sceneInfo);
if (data) {
if (!(data instanceof Array)) {
// debugger;
//
position = [data.lon, data.lat, data.altitude];
rotation = [data.rotationX, data.rotationY, data.rotationZ];
viewDistance = data.viewDistance;
duration = data.duration ? data.duration : 0;
// viewer.camera.flyTo(position, viewDistance, rotation, duration);
console.log("data", position, viewDistance, rotation, duration);
} else {
//
position = [parentData[0].lon, parentData[0].lat, parentData[0].altitude];
rotation = [parentData[0].rotationX, parentData[0].rotationY, parentData[0].rotationZ];
viewDistance = parentData[0].viewDistance;
duration = parentData[0].duration;
console.log("data2", position, viewDistance, rotation, duration);
//
// let CartesianPosition = ellipsoid.cartographicToCartesian({
// x: position[0], y: position[1], z: position[2]
// });
// let CartesianPosition = ellipsoid.cartographicToCartesian(position[0],position[1],position[2]);
// console.log("CartesianPosition", CartesianPosition);
//
// viewer.camera.flyTo(CartesianPosition, viewDistance, rotation, duration);
// viewer.camera.flyTo({
// x: -990536.0465518984,
// y: 5531995.514841362,
// z: 3004737.189031571,
// duration: 1.0,
// });
// viewer.camera.position = {
// x: -990536.0465518984,
// y: 5531995.514841362,
// z: 3004737.189031571,
// }
// viewer.camera.position = CartesianPosition
// for (let record of data) {
// if (record.sceneCode.length == 11) {
// continue;
// }
// //
// this.setLoginPoint(record);
// }
}
} else {
//
}
}
function drawEvt(e, viewer) {
const restoreCursor = getComputedStyle(viewer.canvas).cursor; const restoreCursor = getComputedStyle(viewer.canvas).cursor;
if (e.finished) { if (e.finished) {
if (e.type === 'move') { if (e.type === 'move') {
@ -454,25 +579,25 @@
viewer.canvas.setAttribute('style', 'cursor: crosshair'); viewer.canvas.setAttribute('style', 'cursor: crosshair');
} }
} }
} }
function activeEvt(e, viewer) { function activeEvt(e, viewer) {
// console.log(e) // console.log(e)
viewer.canvas.setAttribute('style', `cursor: ${e.isActive ? 'crosshair' : 'auto'}`); viewer.canvas.setAttribute('style', `cursor: ${e.isActive ? 'crosshair' : 'auto'}`);
if (!e.isActive) { if (!e.isActive) {
proxy.drawing = false; proxy.drawing = false;
proxy.restoreCursorMove = 'auto'; proxy.restoreCursorMove = 'auto';
} }
} }
function editorEvt(e, viewer) { function editorEvt(e, viewer) {
if (e.type === 'move') { if (e.type === 'move') {
viewer.canvas.setAttribute('style', 'cursor: move'); viewer.canvas.setAttribute('style', 'cursor: move');
proxy.drawing = true; proxy.drawing = true;
} else { } else {
viewer.canvas.setAttribute('style', 'cursor: auto'); viewer.canvas.setAttribute('style', 'cursor: auto');
} }
} }
// //
function mouseEvt(e, viewer) { function mouseEvt(e, viewer) {
const restoreCursor = getComputedStyle(viewer.canvas).cursor; const restoreCursor = getComputedStyle(viewer.canvas).cursor;
if (!proxy.drawing) { if (!proxy.drawing) {
if (e.type === 'onmouseover') { if (e.type === 'onmouseover') {
@ -482,35 +607,37 @@
viewer.canvas.setAttribute('style', `cursor: ${proxy.restoreCursorMove || 'auto'}`); viewer.canvas.setAttribute('style', `cursor: ${proxy.restoreCursorMove || 'auto'}`);
} }
} }
} }
function clearEvt(e) { function clearEvt(e) {
console.log(e); console.log(e);
} }
function unload() { function unload() {
proxy.$refs.drawingsRef.unload(); proxy.$refs.drawingsRef.unload();
} }
function load() { function load() {
proxy.$refs.drawingsRef.load(); proxy.$refs.drawingsRef.load();
} }
function reload() { function reload() {
proxy.$refs.drawingsRef.reload(); proxy.$refs.drawingsRef.reload();
} }
function cartesian3ToCartographic(cartesian3: any, viewer: any) {
console.log("cartesian3", cartesian3);
function cartesian3ToCartographic(cartesian3: any, viewer: any) {
let ellipsoid = viewer.scene.globe.ellipsoid; let ellipsoid = viewer.scene.globe.ellipsoid;
let cartographic = ellipsoid.cartesianToCartographic(cartesian3); let cartographic = ellipsoid.cartesianToCartographic(cartesian3);
if (cartographic) { if (cartographic) {
return [Cesium.Math.toDegrees(cartographic.longitude), Cesium.Math.toDegrees(cartographic.latitude), cartographic.height]; return [Cesium.Math.toDegrees(cartographic.longitude), Cesium.Math.toDegrees(cartographic.latitude), cartographic.height];
} }
} }
// function pickEvt(e) { // function pickEvt(e) {
// console.log(e) // console.log(e)
// } // }
</script> </script>
<style scoped> <style scoped>
.demo-toolbar { .demo-toolbar {
margin-left: 20px; margin-left: 20px;
font-size: 20px; font-size: 20px;
} }
</style> </style>

Loading…
Cancel
Save