【类 型】: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: { props: {
enableGuided: { //
type: Boolean,
default: false
},
enableFollow: { // enableFollow: { //
type: Boolean, type: Boolean,
default: false default: false
@ -205,30 +209,57 @@ export default {
// this.map.setTerrain({ source: 'mapbox-dem', exaggeration: 1.5 }) // this.map.setTerrain({ source: 'mapbox-dem', exaggeration: 1.5 })
}) })
// longPress //
let pressTimer if (this.enableGuided) {
this.map.on('mousedown', (event) => { // longPress
// pc let pressTimer = null
pressTimer = setTimeout(() => { let isLongPress = false //
const lonLat = { lon: this.map.unproject(event.point).lng, lat: this.map.unproject(event.point).lat } let startPoint = null //
// // pc
this.$emit('longPress', lonLat) this.map.on('mousedown', (event) => { //
}, 1000) // startPoint = { x: event.point.x, y: event.point.y } //
}) isLongPress = false //
this.map.on('touchstart', (event) => { pressTimer = setTimeout(() => {
// isLongPress = true //
pressTimer = setTimeout(() => { }, 200) //
const lonLat = { lon: this.map.unproject(event.point).lng, lat: this.map.unproject(event.point).lat } })
// this.map.on('mouseup', (event) => { //
this.$emit('longPress', lonLat) clearTimeout(pressTimer) //
}, 1000) // const currentPoint = { x: event.point.x, y: event.point.y }
}) const dx = currentPoint.x - startPoint.x
// const dy = currentPoint.y - startPoint.y
const clearPressTimer = () => { if (Math.sqrt(dx * dx + dy * dy) <= 5 && isLongPress) { //
clearTimeout(pressTimer) 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('mouseup', clearPressTimer)
this.map.on('touchend', clearPressTimer)
}) })
}, },
methods: { 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:原理删除之前的轨迹 重新绘制 * @description: 创建飞机轨迹 ps:原理删除之前的轨迹 重新绘制
* @param {arr} coordinatesArray 飞机经纬高度数组 * @param {arr} coordinatesArray 飞机经纬高度数组

View File

@ -1,12 +1,31 @@
<template> <template>
<div class="h-100"> <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> <template #content>
<BatteryStatus :plane="plane" /> <BatteryStatus :plane="plane" />
<PlaneStatus :plane="plane" /> <PlaneStatus :plane="plane" />
<ControllerTabs :plane="plane" @mapXOffset="mapXOffset" @makeRoute="makeRoute" @clearRoute="clearRoute" /> <ControllerTabs :plane="plane" @mapXOffset="mapXOffset" @makeRoute="makeRoute" @clearRoute="clearRoute" />
</template> </template>
</map-box> </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> </div>
</template> </template>
@ -20,6 +39,11 @@ export default {
name: 'Planes', name: 'Planes',
data () { data () {
return { return {
dialogTitle: '', //
dialogItem: '', //
dialogVisible: false, //
guidedLonLat: {}, //
guidedAlt: '', //
mapBoxKey: '', // map-box mapBoxKey: '', // map-box
planesId: this.$route.params.id, planesId: this.$route.params.id,
localCount: 0 // localCount: 0 //
@ -57,6 +81,23 @@ export default {
} }
}, },
methods: { 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: 创建飞机图标 * @description: 创建飞机图标
*/ */