| | |
| | | }, |
| | | ] |
| | | |
| | | const waylinePointsEvent = ref<tragetPoint[]>([]) |
| | | // 路线详情 |
| | | const waylineDetails = reactive<waylineDetails[]>([ |
| | | { |
| | | title: '航线长度', |
| | | value: '0', |
| | | }, |
| | | { |
| | | title: '预计执行时间', |
| | | value: '0', |
| | | }, |
| | | { |
| | | title: '航点', |
| | | value: 0, |
| | | }, |
| | | { |
| | | title: '照片', |
| | | value: 0, |
| | | }, |
| | | ]) |
| | | // kml中的全部实体 |
| | | const kmlEntities = ref<Cesium.Entity[]>([]) |
| | | |
| | | const useMapDraw = ( |
| | | dataSource: Cesium.DataSource | any, |
| | | entitiesList: Cesium.Entity[] | any, |
| | |
| | | global: any, |
| | | ) => { |
| | | const ellipsoid = global.$viewer.scene.globe.ellipsoid |
| | | const waylinePointsEvent = ref<tragetPoint[]>([]) |
| | | // 路线详情 |
| | | const waylineDetails = reactive<waylineDetails[]>([ |
| | | { |
| | | title: '航线长度', |
| | | value: '0', |
| | | }, |
| | | { |
| | | title: '预计执行时间', |
| | | value: '0', |
| | | }, |
| | | { |
| | | title: '航点', |
| | | value: 0, |
| | | }, |
| | | { |
| | | title: '照片', |
| | | value: 0, |
| | | }, |
| | | ]) |
| | | // kml中的全部实体 |
| | | const kmlEntities = ref<Cesium.Entity[]>([]) |
| | | |
| | | // kml文件中点位string |
| | | let kmlPoints: string[] | any = [] |
| | | // 记录点位信息 |
| | | const cartesianArr: Cesium.Cartesian3[] = [] |
| | | // 记录点位信息 |
| | | let cartesianArr: Cesium.Cartesian3[] = [] |
| | | |
| | | // 绘制路线 |
| | | const drawWayline = async () => { |
| | | dataSource.show = false |
| | | let kmlEntityArr = [...entitiesList] |
| | | const drawWayline = async (entities: Cesium.Entity[], kmlStr: string) => { |
| | | if (!entities && !kmlStr) { |
| | | dataSource.show = false |
| | | } |
| | | let kmlEntityArr = entities || [...entitiesList] |
| | | if (dataSource) { |
| | | kmlEntityArr = dataSource.entities.values[0]._children |
| | | kmlEntities.value = kmlEntityArr |
| | | } |
| | | // 获取所有点位 |
| | | const kmlRes = await analyzeKmzFile(fileUrl) |
| | | let kmlRes = '' |
| | | if (kmlStr) { |
| | | kmlRes = kmlStr |
| | | } else { |
| | | kmlRes = await analyzeKmzFile(fileUrl) |
| | | } |
| | | // 所有航点 |
| | | kmlPoints = getKmlParams(kmlRes, false, { |
| | | name: 'Placemark', |
| | |
| | | }) |
| | | // 起飞点 |
| | | let btmStartPoint = null |
| | | // 判断是否存在实体集 |
| | | if (entities) { |
| | | cartesianArr = [] |
| | | waylinePointsEvent.value = [] |
| | | } |
| | | // 修改点位样式 |
| | | for (let i = 0; i < kmlEntityArr.length; i++) { |
| | | const entity: any = kmlEntityArr[i] |
| | |
| | | const latitude = Cesium.Math.toDegrees(c2Postion.latitude) |
| | | // 获取当前航点中的值 |
| | | const point = kmlPoints[i] |
| | | const getPointHeight: any = getKmlParams(point, true, { |
| | | const getHaeHeight: any = getKmlParams(point, true, { |
| | | name: 'ellipsoidHeight', |
| | | findRegx: '([\\s\\S]*?)', |
| | | }) |
| | | const getHaeHeight: any = getKmlParams(point, true, { |
| | | const getPointHeight: any = getKmlParams(point, true, { |
| | | name: 'height', |
| | | findRegx: '([\\s\\S]*?)', |
| | | }) |
| | | const AslHeight = Number(getPointHeight[1]) |
| | | const HeaHeight = Number(getHaeHeight[1]) |
| | | entity.position = Cesium.Cartesian3.fromDegrees( |
| | | longitude, |
| | | latitude, |
| | | AslHeight, |
| | | ) |
| | | entity.position = Cesium.Cartesian3.fromDegrees(longitude, latitude, AslHeight) |
| | | if (i === 0) { |
| | | btmStartPoint = Cesium.Cartesian3.fromDegrees(longitude, latitude, 0) |
| | | } |
| | |
| | | color: Cesium.Color.GHOSTWHITE, |
| | | outlineColor: Cesium.Color.BLACK, |
| | | }) |
| | | if (entities) { |
| | | global.$viewer.entities.add(entity) |
| | | } |
| | | // 创建虚线 |
| | | addPolyline({ |
| | | id: 'dashLine' + i, |
| | |
| | | }) |
| | | // 获取航线详情 |
| | | getWaylineDetails(kmlRes) |
| | | dataSource.show = true |
| | | if (!entities && !kmlStr) { |
| | | dataSource.show = true |
| | | } |
| | | global.$viewer.flyTo(getEntityById('entityLine'), { |
| | | offset: new Cesium.HeadingPitchRange(0, -90, 600), |
| | | }) |
| | |
| | | const sportTime = polylineLength / speed |
| | | // 判断有没有超过一分钟 |
| | | const time = sportTime / 60 |
| | | waylineDetails[1].value = |
| | | Math.trunc(time) + ' m ' + Math.round((time % 1) * 60) + ' s' |
| | | waylineDetails[1].value = Math.trunc(time) + ' m ' + Math.round((time % 1) * 60) + ' s' |
| | | |
| | | // 获取事件 |
| | | getPointEvent() |
| | | getPointEvent(kmlStr || null) |
| | | } |
| | | // 获取航线点位事件 |
| | | const getPointEvent = async () => { |
| | | const kmlRes = await analyzeKmzFile(fileUrl) |
| | | const getPointEvent = async (kmlStr: string | null) => { |
| | | let kmlRes = '' |
| | | if (kmlStr) { |
| | | kmlRes = kmlStr |
| | | } else { |
| | | await analyzeKmzFile(fileUrl) |
| | | } |
| | | // 所有航点 |
| | | const points = getKmlParams(kmlRes, false, { |
| | | name: 'Placemark', |
| | |
| | | } |
| | | }) |
| | | } |
| | | const clearWaylineData = () => { |
| | | kmlEntities.value = [] |
| | | waylinePointsEvent.value = [] |
| | | } |
| | | |
| | | return { |
| | | waylinePointsEvent, |
| | |
| | | kmlEntities, |
| | | drawWayline, |
| | | getWaylineDetails, |
| | | clearWaylineData, |
| | | } |
| | | } |
| | | |
| | | export { waylinePointsEvent, waylineDetails, kmlEntities } |
| | | export default useMapDraw |