Browse Source

添加并封装船只及轨迹绘制方法

master
Fuyuu 9 months ago
parent
commit
5f86f2f740
  1. 16
      src/store/modules/earthMap.ts
  2. 69
      src/utils/earthMap/shipDraw.ts
  3. 301
      src/views/earthMap/edit/EarthComp.vue

16
src/store/modules/earthMap.ts

@ -1,7 +1,14 @@
/*
* @Author: Fuyuu 1805498209@qq.com
* @Date: 2023-12-15 16:47:17
* @LastEditors: Fuyuu 1805498209@qq.com
* @LastEditTime: 2024-01-03 10:47:55
* @FilePath: \dt-admin-pc-v2\src\store\modules\earthMap.ts
* @Description: ,`customMade`, koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { store } from '/@/store'; import { store } from '/@/store';
export const useEarthMapStore = defineStore({ export const useEarthMapStore = defineStore({
id: 'earth-map', id: 'earth-map',
state: () => ({ state: () => ({
@ -12,16 +19,17 @@ export const useEarthMapStore = defineStore({
shapeList: <any>[], //绘画数组(区域) shapeList: <any>[], //绘画数组(区域)
shapeShowList: <any>[], //绘画存储(临时) shapeShowList: <any>[], //绘画存储(临时)
keyAreaPos: <number[][]>[], //记录创建防区的点位,重点管控区域 keyAreaPos: <number[][]>[], //记录创建防区的点位,重点管控区域
shipDataList: <any>[], //船只数据列表
}), }),
getters: { getters: {
getCustomPrimitiveList(): any { getCustomPrimitiveList(): any {
return this.customPrimitiveList return this.customPrimitiveList;
}, },
getCustomPrimitive(): any { getCustomPrimitive(): any {
return this.customPrimitive return this.customPrimitive;
}, },
}, },
}) });
// 需要在设置之外使用 // 需要在设置之外使用
export function useEarthMapStoreWithOut() { export function useEarthMapStoreWithOut() {

69
src/utils/earthMap/shipDraw.ts

@ -0,0 +1,69 @@
/*
* @Author: Fuyuu 1805498209@qq.com
* @Date: 2024-01-03 17:42:49
* @LastEditors: Fuyuu 1805498209@qq.com
* @LastEditTime: 2024-01-03 18:05:32
* @FilePath: \dt-admin-pc-v2\src\utils\earthMap\shipDraw.ts
* @Description: ,`customMade`, koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
/**
*
*/
import { useEarthMapStore } from '/@/store/modules/earthMap';
import { addShipGroundImg, addShipTrack } from '@/utils/earthMap/earthObj';
// 暂存store
const store = useEarthMapStore();
// 船只数据列表
let shipDataList: any = [];
// 绘制单个船只
const drawShips = function (shipItem) {
// 引入图片
let imageUrl = new URL(`../../assets/images/ship.png`, import.meta.url).href;
// 绘制船只
let shipModel = addShipGroundImg(shipItem.longitude, shipItem.latitude, 0.5, imageUrl, shipItem.course, shipItem.trackId);
// 返回船只绘制信息
return shipModel;
};
// 角度转弧度
function toRadians(point) {
return window.Cesium.Math.toRadians(point);
}
// 绘制地球上所有船只和轨迹
export const drawAllShips = function (message) {
// 接收到的单个船只信息
let messageData = JSON.parse(JSON.parse(message).radarTrack);
// 获取store中的船只数据列表
shipDataList = store.shipDataList;
// 是否已经存在
let existingShip = shipDataList.find((shipItem) => shipItem.trackId === messageData.trackId);
if (existingShip) {
// 添加新的轨迹点
existingShip.trackList.unshift([toRadians(messageData.longitude), toRadians(messageData.latitude), 0]);
// 获取场景中的船只信息
let shipData = window.$earth.getObject(existingShip.guid);
// 更新位置和航向
shipData.position = [toRadians(messageData.longitude), toRadians(messageData.latitude), 0];
shipData.rotation = -(Math.PI / 180) * messageData.course;
// 绘制船只轨迹
addShipTrack(existingShip.trackList);
} else {
// 添加新的船只
shipDataList.push({
name: `${messageData.trackId}号船只`, // 名称
trackId: messageData.trackId, // 船只id
guid: drawShips(messageData).xbsjGuid, // 船只模型id
azimuth: messageData.azimuth, // 方位角
course: messageData.course, // 航向
latitude: messageData.latitude, // 纬度
longitude: messageData.longitude, // 经度
trackList: [[toRadians(messageData.longitude), toRadians(messageData.latitude), 0]], // 轨迹列表
});
// 更新store
store.shipDataList = shipDataList;
}
};

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

@ -106,7 +106,8 @@
import { drawInit } from '@/utils/earthMap/earthDraw'; import { drawInit } from '@/utils/earthMap/earthDraw';
import { keyControlInit } from '@/utils/earthMap/keyControlInit'; import { keyControlInit } from '@/utils/earthMap/keyControlInit';
import redFlag from '@/assets/earthMap/redFlag.png'; import redFlag from '@/assets/earthMap/redFlag.png';
import { addModel, addPin, addViewShedRadar, addShipPrimitive } from '@/utils/earthMap/earthObj'; import { addModel, addPin, addViewShedRadar, addShipGroundImg, addShipTrack } from '@/utils/earthMap/earthObj';
import { drawAllShips } from '@/utils/earthMap/shipDraw';
import hidePng from '@/assets/earthMap/hide.png'; import hidePng from '@/assets/earthMap/hide.png';
import alarmImg from '@/assets/earthMap/alarm.gif'; import alarmImg from '@/assets/earthMap/alarm.gif';
import VideoFusionWin from './components/VideoFusionWin.vue'; import VideoFusionWin from './components/VideoFusionWin.vue';
@ -114,7 +115,7 @@
import circleDot2 from '@/assets/earthMap/circleDot2.png'; import circleDot2 from '@/assets/earthMap/circleDot2.png';
import circleDot1 from '@/assets/earthMap/circleDot1.png'; import circleDot1 from '@/assets/earthMap/circleDot1.png';
import circleDot3 from '@/assets/earthMap/circleDot3.png'; import circleDot3 from '@/assets/earthMap/circleDot3.png';
import { nextTick } from 'vue'; import ship from '@/assets/images/ship.png';
class HandleNodeType { class HandleNodeType {
#sn; #sn;
@ -255,130 +256,7 @@
VideoFusionWin, VideoFusionWin,
}, },
props: {}, props: {},
// data() {
// return {
// earthTitle: '',
// realTime: '',
// // EarthCesiumvue使线
// _earth: undefined,
// _earthUI: undefined,
// _viewer: undefined,
// _pin: undefined,
// _handler: undefined,
// // sceneTree: require('@/assets/earthMap/resjson/sc.json'),
// // sceneTree: new URL(`@/assets/earthMap/resjson/sc.json`, import.meta.url).href,
// sceneTree: sceneTree,
// // areaB: require('@/assets/earthMap/resjson/area_b.json'),
// url: {
// queryLabelList: 'military/msMapLabel/queryLabelAndDeviceList',
// queryLineList: 'military/msMapLine/list',
// queryCameraInfo: 'military/camera/site/getCameraInfoForEarth',
// queryAllModelInfo: 'military/msModelPosition/queryAllModelInfo',
// queryPatrolRouteInfo: 'military/msPatrolLine/getLineDetail',
// queryBayoneByParam: 'military/msBayonetStatistics/getBayoneByParam',
// queryAisInfo: 'checkpoint/msAisInfo/list',
// keepAlive: 'mapInfo/keepAlive',
// //
// radarList: '/military/RadarConfig/list',
// //
// //
// deleteSensor: '/military/msModelPosition/deleteByEventSerialNum',
// //
// deleteSite: '/military/camera/site/delete',
// //
// deleteMapLabel: '/military/msMapLabel/delete',
// updateMapLine: '/military/msMapLine/edit',
// deleteMapLine: '/military/msMapLine/delete',
// saveMapLine: '/military/msMapLine/add',
// //
// //
// updateSensor: '/military/msModelPosition/editByEventSerialNum',
// //
// updateSite: '/military/camera/site/edit',
// //
// updateMapLabel: '/military/msMapLabel/edit',
// //
// //
// SaveSensorModel: '/military/msModelPosition/add',
// //
// saveCameraSiteModel: '/military/camera/site/add',
// //
// saveMapLabel: '/military/msMapLabel/addMapLabel',
// // 线 线
// queryMapLine: '/military/msMapLine/queryByName',
// querySiteById: '/military/camera/site/queryById',
// //
// queryDeviceInfoList: '/military/msDeviceInfo/list',
// setDefenseArea: '/military/netty/microwaveDetector/defenceArea',
// perimeterRegionList: '/third/api/perimeterRegionList',
// perimeterControl: '/third/api/perimeterControl',
// //
// sendRadarAlarmByWebSocket: '/military/warn/sendRadarAlarmByWebSocket',
// },
// cameraData: {},
// cameraModalShow: false,
// poiModalShow: false,
// radioBtnShow: true,
// glmId: [],
// earthChangeSpin: false,
// websock: [],
// timer: null, //
// timer2: null, //
// // -
// alarmTrackClearTimer: null,
// videoWindowProps: {
// visible: false,
// isAlarm: false,
// id: '',
// title: '',
// videoUrl: '',
// cameraIp: '',
// cameraUser: '',
// cameraPwd: '',
// playRecord: false,
// warnTime: null,
// warnEvent: {
// happenTime: '',
// happenLoc: '',
// warnNum: 0,
// warnLevel: 0,
// warnType: 0,
// warnContent: '',
// },
// },
// // - ref
// sceneTreeOldRefValue: '',
// sceneInfo: null,
// // By Ref
// nodeConfigByRef: new Map(),
// nodeCheckedByRef: new Map(),
// areaByNodeId: new Map(),
// statusByNodeId: new Map(),
// imgByRef: new Map(),
// radarAlarmDataMap: new Map(),
// wbUnifiedResponse: false,
// hostDeviceMapById: new Map(),
// alarmInfoMap: new Map(),
// toolbarShow: false,
// //addModelWin
// addModelWinShow: false,
// czmObject: null,
// node: null,
// type: '',
// lineId: '',
// areaCode: '',
// areaByNodeIdModel: '',
// el:null,
// eidtId: null,
// //addroamVideo
// addRoamVideoShow: false
// };
// },
}) })
export default class EarthComp extends Vue { export default class EarthComp extends Vue {
/** /**
@ -524,16 +402,6 @@
monitorPosition: any = []; monitorPosition: any = [];
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
//
shipData: any = {};
//
drawShips() {
let shipData = this.shipData;
let imageUrl = new URL(`../../../assets/images/ship.png`, import.meta.url).href; // PNG
let shipModel = addShipPrimitive(shipData.longitude, shipData.latitude, 0, imageUrl, [shipData.azimuth, 0, 0], '123456', [1, 1, 1]);
console.log('shipModel', shipModel);
}
mounted() { mounted() {
let that = this; let that = this;
@ -582,72 +450,6 @@
} }
}); });
} }
{
$mitt.on('winShow', function (e: any) {
that.VideoFusionWinShow = e;
});
//methods
$mitt.on('openNotification', (res: any) => {
// that.openNotification(msg, dt, type, top)
that.openNotification(res.msg, res.dt, res.type, res.top);
});
$mitt.on('listenMouseHandler', function () {
that.listenMouseHandler();
});
$mitt.on('removeHandler', function () {
that.removeHandler();
});
$mitt.on('createBBHLine', function () {
that.createBBHLine();
});
$mitt.on('createRealTimeObj', function () {
that.createRealTimeObj();
});
$mitt.on('radioChangeBtnShow', function (callback) {
that.radioChangeBtnShow(callback);
});
$mitt.on('loadingStatus', function () {
that.loadingStatus();
});
$mitt.on('clearAlarmModel', (mittData: any) => {
let { isWarnEvent, eventSerialNum } = mittData;
//
if (isWarnEvent) {
//
let url = 'military/msWarnEvent/queryWarnEventDetailList';
let params = {
eventSerialNum: eventSerialNum,
};
defHttp.get({ url, params }, { isTransformResponse: false }).then((res) => {
if (res.success) {
//
let data = res.result;
for (const warnEventInfo of data) {
this.clearAlarmModel(warnEventInfo.eventSerialNum);
}
} else {
//
console.log('失败');
this.$message.error(res.message);
}
});
} else {
// ,
this.clearAlarmModel(eventSerialNum);
}
});
// mqtt
$mitt.on('deviceCmd', (message: any) => {
//
this.shipData = JSON.parse(JSON.parse(message).radarTrack);
//
nextTick(() => {
this.drawShips();
});
});
}
} }
// //
guid() { guid() {
@ -805,17 +607,20 @@
this._earth.terrainEffect.subSurfaceEnabled = false; // this._earth.terrainEffect.subSurfaceEnabled = false; //
this._viewer = earthUI.earth.czm.viewer; this._viewer = earthUI.earth.czm.viewer;
this._viewer.scene.fxaa = true // this._viewer.scene.fxaa = true; //
this._viewer.scene.globe.baseColor = Cesium.Color.BLACK this._viewer.scene.globe.baseColor = Cesium.Color.BLACK;
// //
// console.log("this.sceneTree",this.sceneTree); // console.log("this.sceneTree",this.sceneTree);
// console.log("window._CONFIG['earthMapURL']",window._CONFIG['earthMapURL']); // console.log("window._CONFIG['earthMapURL']",window._CONFIG['earthMapURL']);
// console.log("window._CONFIG['satellite']",window._CONFIG['satellite']); // console.log("window._CONFIG['satellite']",window._CONFIG['satellite']);
this.sceneTree.children[0].czmObject.xbsjImageryProvider.TileMapServiceImageryProvider.url = window._CONFIG['earthMapURL'] + window._CONFIG['satellite']; this.sceneTree.children[0].czmObject.xbsjImageryProvider.TileMapServiceImageryProvider.url =
this.sceneTree.children[1].czmObject.xbsjImageryProvider.TileMapServiceImageryProvider.url = window._CONFIG['earthMapURL'] + window._CONFIG['vector'] window._CONFIG['earthMapURL'] + window._CONFIG['satellite'];
this.sceneTree.children[2].czmObject.xbsjTerrainProvider.XbsjCesiumTerrainProvider.url = window._CONFIG['earthMapURL'] + window._CONFIG['terrain']; this.sceneTree.children[1].czmObject.xbsjImageryProvider.TileMapServiceImageryProvider.url =
window._CONFIG['earthMapURL'] + window._CONFIG['vector'];
this.sceneTree.children[2].czmObject.xbsjTerrainProvider.XbsjCesiumTerrainProvider.url =
window._CONFIG['earthMapURL'] + window._CONFIG['terrain'];
// this.sceneTree.children.push(this.areaB) // this.sceneTree.children.push(this.areaB)
this._earth.sceneTree.root = { this._earth.sceneTree.root = {
@ -833,6 +638,9 @@
// //
this.listenMouseHandler(earthUI); this.listenMouseHandler(earthUI);
//mitt
this.listenMittHandler(earthUI);
// //
await this.fly(); await this.fly();
@ -2198,9 +2006,8 @@
// console.log("pickedFeature.id._xbsjOwner.addViewShedReturn",pickedFeature.id._xbsjOwner.addViewShedReturn); // console.log("pickedFeature.id._xbsjOwner.addViewShedReturn",pickedFeature.id._xbsjOwner.addViewShedReturn);
//undefined() //undefined()
pickedFeature.id._xbsjOwner.addViewShedReturn.clear() pickedFeature.id._xbsjOwner.addViewShedReturn.clear();
pickedFeature.id._xbsjOwner.addViewShedReturn = undefined pickedFeature.id._xbsjOwner.addViewShedReturn = undefined;
} else { } else {
defHttp.get({ url: this.url.radarList, params: { radarCode: labelCode } }, { isTransformResponse: false }).then((res) => { defHttp.get({ url: this.url.radarList, params: { radarCode: labelCode } }, { isTransformResponse: false }).then((res) => {
if (res.success) { if (res.success) {
@ -2215,19 +2022,19 @@
let radarShifting = data.angularRadian; let radarShifting = data.angularRadian;
let left = Number(radarShifting) - Number(radarRange) / 2; let left = Number(radarShifting) - Number(radarRange) / 2;
// //
console.log("雷达扫描范围",data); console.log('雷达扫描范围', data);
// //
let degreePosition = radianToDegreeInLngLatHeight( let degreePosition = radianToDegreeInLngLatHeight(
pickedFeature.id._xbsjOwner.position[0], pickedFeature.id._xbsjOwner.position[0],
pickedFeature.id._xbsjOwner.position[1], pickedFeature.id._xbsjOwner.position[1],
0.1 0.1
) );
// //
// this._viewer.scene.globe.depthTestAgainstTerrain = true; // this._viewer.scene.globe.depthTestAgainstTerrain = true;
let rader = new CircleScan(this._viewer) let rader = new CircleScan(this._viewer);
rader.add(degreePosition, null, radarRadius, 10000); rader.add(degreePosition, null, radarRadius, 10000);
pickedFeature.id._xbsjOwner.addViewShedReturn= rader pickedFeature.id._xbsjOwner.addViewShedReturn = rader;
// 2 // 2
// let rader2 = this._viewer.entities.add({ // let rader2 = this._viewer.entities.add({
@ -2247,7 +2054,6 @@
// } // }
// }) // })
// pickedFeature.id._xbsjOwner.addViewShedReturn= addViewShedRadar( // pickedFeature.id._xbsjOwner.addViewShedReturn= addViewShedRadar(
// pickedFeature.id._xbsjOwner.position, // pickedFeature.id._xbsjOwner.position,
// radarRadius, // radarRadius,
@ -2255,7 +2061,6 @@
// Number(radarRange) / 2 + Number(radarShifting), // Number(radarRange) / 2 + Number(radarShifting),
// [rgb.r / 255, rgb.g / 255, rgb.b / 255, rgb.a] // [rgb.r / 255, rgb.g / 255, rgb.b / 255, rgb.a]
// ); // );
} }
} }
}); });
@ -2538,6 +2343,70 @@
} }
} }
listenMittHandler(earthUI = null) {
let that = this;
{
$mitt.on('winShow', function (e: any) {
that.VideoFusionWinShow = e;
});
//methods
$mitt.on('openNotification', (res: any) => {
// that.openNotification(msg, dt, type, top)
that.openNotification(res.msg, res.dt, res.type, res.top);
});
$mitt.on('listenMouseHandler', function () {
that.listenMouseHandler();
});
$mitt.on('removeHandler', function () {
that.removeHandler();
});
$mitt.on('createBBHLine', function () {
that.createBBHLine();
});
$mitt.on('createRealTimeObj', function () {
that.createRealTimeObj();
});
$mitt.on('radioChangeBtnShow', function (callback) {
that.radioChangeBtnShow(callback);
});
$mitt.on('loadingStatus', function () {
that.loadingStatus();
});
$mitt.on('clearAlarmModel', (mittData: any) => {
let { isWarnEvent, eventSerialNum } = mittData;
//
if (isWarnEvent) {
//
let url = 'military/msWarnEvent/queryWarnEventDetailList';
let params = {
eventSerialNum: eventSerialNum,
};
defHttp.get({ url, params }, { isTransformResponse: false }).then((res) => {
if (res.success) {
//
let data = res.result;
for (const warnEventInfo of data) {
this.clearAlarmModel(warnEventInfo.eventSerialNum);
}
} else {
//
console.log('失败');
this.$message.error(res.message);
}
});
} else {
// ,
this.clearAlarmModel(eventSerialNum);
}
});
// mqtt
$mitt.on('deviceCmd', (message: any) => {
drawAllShips(message);
});
}
}
removeHandler() { removeHandler() {
this._handler.removeInputAction(window.Cesium.ScreenSpaceEventType.MOUSE_MOVE); // this._handler.removeInputAction(window.Cesium.ScreenSpaceEventType.MOUSE_MOVE); //
this._handler.removeInputAction(window.Cesium.ScreenSpaceEventType.LEFT_CLICK); // this._handler.removeInputAction(window.Cesium.ScreenSpaceEventType.LEFT_CLICK); //

Loading…
Cancel
Save