【类 型】:feat 地图点击 指点飞行

【原  因】:
【过  程】:
【影  响】:

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
This commit is contained in:
tk 2024-10-11 12:42:56 +08:00
parent 35d983454a
commit bfe0a6ae3c
2 changed files with 114 additions and 24 deletions

View File

@ -135,6 +135,10 @@ export default {
}
},
props: {
enableGuided: { //
type: Boolean,
default: false
},
enableFollow: { //
type: Boolean,
default: false
@ -205,30 +209,57 @@ export default {
// this.map.setTerrain({ source: 'mapbox-dem', exaggeration: 1.5 })
})
//
if (this.enableGuided) {
// longPress
let pressTimer
this.map.on('mousedown', (event) => {
// pc
let pressTimer = null
let isLongPress = false //
let startPoint = null //
// pc
this.map.on('mousedown', (event) => { //
startPoint = { x: event.point.x, y: event.point.y } //
isLongPress = false //
pressTimer = setTimeout(() => {
const lonLat = { lon: this.map.unproject(event.point).lng, lat: this.map.unproject(event.point).lat }
//
this.$emit('longPress', lonLat)
}, 1000) //
isLongPress = true //
}, 200) //
})
this.map.on('mouseup', (event) => { //
clearTimeout(pressTimer) //
const currentPoint = { x: event.point.x, y: event.point.y }
const dx = currentPoint.x - startPoint.x
const dy = currentPoint.y - startPoint.y
if (Math.sqrt(dx * dx + dy * dy) <= 5 && isLongPress) { //
const lonLat = {
lon: this.map.unproject(currentPoint).lng,
lat: this.map.unproject(currentPoint).lat
}
this.$emit('longPress', lonLat) //
this.makeGuidedMarker(lonLat, this.map) //
}
})
//
this.map.on('touchstart', (event) => { //
clearTimeout(pressTimer) //
startPoint = { x: event.point.x, y: event.point.y } //
isLongPress = false //
pressTimer = setTimeout(() => {
isLongPress = true //
}, 200) //
})
this.map.on('touchend', (event) => { //
const currentPoint = { x: event.point.x, y: event.point.y }
const dx = currentPoint.x - startPoint.x
const dy = currentPoint.y - startPoint.y
if (Math.sqrt(dx * dx + dy * dy) <= 5 && isLongPress) { //
const lonLat = {
lon: this.map.unproject(currentPoint).lng,
lat: this.map.unproject(currentPoint).lat
}
this.$emit('longPress', lonLat) //
this.makeGuidedMarker(lonLat, this.map) //
}
})
this.map.on('touchstart', (event) => {
//
pressTimer = setTimeout(() => {
const lonLat = { lon: this.map.unproject(event.point).lng, lat: this.map.unproject(event.point).lat }
//
this.$emit('longPress', lonLat)
}, 1000) //
})
//
const clearPressTimer = () => {
clearTimeout(pressTimer)
}
this.map.on('mouseup', clearPressTimer)
this.map.on('touchend', clearPressTimer)
})
},
methods: {
@ -525,6 +556,24 @@ export default {
}
})
},
/**
* @abstract 创建指点飞行标记
* @param {Array} lonLat - 经纬度数组格式为 [longitude, latitude]
* @param {Object} map - mapboxgl 的地图实例
*/
makeGuidedMarker (lonLat, map) {
//
if (this.guidedMarker) {
this.guidedMarker.remove()
this.guidedMarker = null //
}
//
this.guidedMarker = new mapboxgl.Marker({
draggable: false//
})
.setLngLat(lonLat)
.addTo(map)
},
/**
* @description: 创建飞机轨迹 ps:原理删除之前的轨迹 重新绘制
* @param {arr} coordinatesArray 飞机经纬高度数组

View File

@ -1,12 +1,31 @@
<template>
<div class="h-100">
<map-box ref="mapbox" :enableFollow="true" :enblueScale="!$store.state.app.isWideScreen">
<!-- 地图组件 -->
<map-box ref="mapbox" :enableGuided="true" :enableFollow="true" :enblueScale="!$store.state.app.isWideScreen"
@longPress="handleLongPress">
<template #content>
<BatteryStatus :plane="plane" />
<PlaneStatus :plane="plane" />
<ControllerTabs :plane="plane" @mapXOffset="mapXOffset" @makeRoute="makeRoute" @clearRoute="clearRoute" />
</template>
</map-box>
<!-- 弹出框 -->
<el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="320px" top="30vh" @close="closeCallback"
@open="openCallback">
<!-- 点飞设置弹出框 -->
<template v-if="dialogItem == 'guidedBox'">
<template>
<font>高度设置</font>
<el-input-number v-model="guidedAlt" label="高度设置"></el-input-number>
<font class="m-l-5"></font>
</template>
<span slot="footer" class="dialog-footer">
<el-button size="medium" @click="dialogVisible = false">关闭</el-button>
<el-button size="medium" type="primary"
@click="publishFun(`{guidedMode:{lon:${guidedLonLat.lon},lat:${guidedLonLat.lat},alt:${guidedAlt}}`);">飞至</el-button>
</span>
</template>
</el-dialog>
</div>
</template>
@ -20,6 +39,11 @@ export default {
name: 'Planes',
data () {
return {
dialogTitle: '', //
dialogItem: '', //
dialogVisible: false, //
guidedLonLat: {}, //
guidedAlt: '', //
mapBoxKey: '', // map-box
planesId: this.$route.params.id,
localCount: 0 //
@ -57,6 +81,23 @@ export default {
}
},
methods: {
/** 弹出框 关闭事件回调 */
closeCallback () {
this.dialogVisible = false
this.dialogItem = ''
},
/** 弹出框 打开事件回调 */
openCallback () {
},
//
handleLongPress (lonLat) {
this.dialogTitle = '点飞'
this.dialogVisible = true
this.dialogItem = 'guidedBox'
this.guidedLonLat = lonLat //
const posLen = this.plane.planeState.position.length
this.guidedAlt = this.plane.planeState.position[posLen - 1][2]//
},
/**
* @description: 创建飞机图标
*/