2023-09-20 21:33:11 +08:00
|
|
|
|
<template>
|
|
|
|
|
<div id="map">
|
|
|
|
|
<slot name="content"></slot>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import mapboxgl from 'mapbox-gl'
|
2024-07-25 19:59:01 +08:00
|
|
|
|
import { MapboxStyleSwitcherControl, FollowControl, CustomFullscreenControl } from '@/utils/mapboxgl_plugs'
|
2023-09-20 21:33:11 +08:00
|
|
|
|
import planeIcon from '@/assets/svg/plane.svg'
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'MapBox',
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
2024-10-09 12:14:52 +08:00
|
|
|
|
token: 'pk.eyJ1Ijoic3pkb3QiLCJhIjoiY2xhN2pkMWFoMHJ4eTN3cXp6bmlzaHZ0NCJ9.3hH-EAUr0wQCaLvIM2lBMQ',
|
2023-09-20 21:33:11 +08:00
|
|
|
|
map: null,
|
|
|
|
|
planes: [], // 飞机对象
|
2024-09-19 13:09:43 +08:00
|
|
|
|
lonLats: [], // 航线 所有航点
|
|
|
|
|
wayLonLats: [], // 航线 不包括起点航点
|
|
|
|
|
takeoffLonLats: [], // 航线 第一个航点 起点 最后一个航点
|
2024-07-25 05:13:30 +08:00
|
|
|
|
isflow: false, // 飞机经纬度变化时是否跟随飞机
|
2024-07-25 21:33:52 +08:00
|
|
|
|
currentStyleIndex: 0, // 当前选中的地图样式索引
|
2024-06-25 19:43:35 +08:00
|
|
|
|
// 地图样式
|
2024-07-25 21:33:52 +08:00
|
|
|
|
mapStyles: [
|
2024-07-25 05:13:30 +08:00
|
|
|
|
// mapbox官方样式 卫星地图
|
2024-07-25 21:33:52 +08:00
|
|
|
|
{
|
|
|
|
|
name: '谷歌卫星',
|
|
|
|
|
sprite: this.$store.state.settings.host + '/Public/map/sprite',
|
|
|
|
|
glyphs: 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf',
|
|
|
|
|
version: 8,
|
|
|
|
|
sources: {
|
|
|
|
|
google: {
|
|
|
|
|
type: 'raster',
|
|
|
|
|
tileSize: 256,
|
|
|
|
|
tiles: ['https://sb.im/google-maps/vt?lyrs=s&x={x}&y={y}&z={z}']
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
layers: [{ id: 'GoogleRasterLayer', type: 'raster', source: 'google' }]
|
2023-09-20 21:33:11 +08:00
|
|
|
|
},
|
2024-07-26 03:16:31 +08:00
|
|
|
|
{
|
|
|
|
|
name: '必应卫星',
|
|
|
|
|
sprite: this.$store.state.settings.host + '/Public/map/sprite',
|
|
|
|
|
glyphs: 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf',
|
|
|
|
|
version: 8,
|
|
|
|
|
sources: {
|
|
|
|
|
bing: {
|
|
|
|
|
type: 'raster',
|
|
|
|
|
tileSize: 256,
|
|
|
|
|
tiles: [
|
|
|
|
|
'https://ecn.t3.tiles.virtualearth.net/tiles/a{quadkey}.jpeg?g=1'
|
|
|
|
|
],
|
|
|
|
|
attribution: '© Microsoft, Bing Maps'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
layers: [{ id: 'BingRasterLayer', type: 'raster', source: 'bing' }]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Mapbox Streets',
|
|
|
|
|
sprite: 'mapbox://sprites/mapbox/streets-v11',
|
|
|
|
|
glyphs: 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf',
|
|
|
|
|
version: 8,
|
|
|
|
|
sources: {
|
|
|
|
|
mapbox: {
|
|
|
|
|
type: 'raster',
|
|
|
|
|
tileSize: 256,
|
|
|
|
|
tiles: ['https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/{z}/{x}/{y}?access_token=YOUR_MAPBOX_ACCESS_TOKEN']
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
layers: [{ id: 'MapboxStreetsLayer', type: 'raster', source: 'mapbox' }]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Google Maps',
|
|
|
|
|
sprite: this.$store.state.settings.host + '/Public/map/sprite',
|
|
|
|
|
glyphs: 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf',
|
|
|
|
|
version: 8,
|
|
|
|
|
sources: {
|
|
|
|
|
google: {
|
|
|
|
|
type: 'raster',
|
|
|
|
|
tileSize: 256,
|
|
|
|
|
tiles: ['https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}']
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
layers: [{ id: 'GoogleMapsLayer', type: 'raster', source: 'google' }]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'OpenStreetMap',
|
|
|
|
|
sprite: this.$store.state.settings.host + '/Public/map/sprite',
|
|
|
|
|
glyphs: 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf',
|
|
|
|
|
version: 8,
|
|
|
|
|
sources: {
|
|
|
|
|
osm: {
|
|
|
|
|
type: 'raster',
|
|
|
|
|
tileSize: 256,
|
|
|
|
|
tiles: ['https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png']
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
layers: [{ id: 'OSMRasterLayer', type: 'raster', source: 'osm' }]
|
|
|
|
|
},
|
2024-07-25 05:13:30 +08:00
|
|
|
|
// 第三方 高德矢量
|
2024-07-25 21:33:52 +08:00
|
|
|
|
{
|
|
|
|
|
name: '高德矢量',
|
|
|
|
|
sprite: this.$store.state.settings.host + '/Public/map/sprite',
|
|
|
|
|
glyphs: 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf',
|
|
|
|
|
version: 8,
|
|
|
|
|
sources: {
|
|
|
|
|
gaode: {
|
|
|
|
|
type: 'raster',
|
|
|
|
|
tileSize: 256, // 瓦片大小 256 512像素
|
|
|
|
|
tiles: [
|
|
|
|
|
'http://wprd04.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}'
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
layers: [{ id: 'GaodeVectorLayer', type: 'raster', source: 'gaode' }]
|
2024-06-25 19:43:35 +08:00
|
|
|
|
},
|
2024-07-25 05:13:30 +08:00
|
|
|
|
// 第三方 高德卫星
|
2024-07-25 21:33:52 +08:00
|
|
|
|
{
|
|
|
|
|
name: '高德卫星',
|
|
|
|
|
sprite: this.$store.state.settings.host + '/Public/map/sprite',
|
|
|
|
|
glyphs: 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf',
|
|
|
|
|
version: 8,
|
|
|
|
|
sources: {
|
|
|
|
|
gaode: {
|
|
|
|
|
type: 'raster',
|
|
|
|
|
tileSize: 256, // 瓦片大小 256 512像素
|
|
|
|
|
tiles: [
|
|
|
|
|
'https://webst02.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}'
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
layers: [{ id: 'GaodeRasterLayer', type: 'raster', source: 'gaode' }]
|
|
|
|
|
}
|
|
|
|
|
]
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2024-08-08 14:40:30 +08:00
|
|
|
|
props: {
|
2024-10-11 12:42:56 +08:00
|
|
|
|
enableGuided: { // 是否开启 飞机点飞功能
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
},
|
2024-08-08 14:40:30 +08:00
|
|
|
|
enableFollow: { // 开启跟随组件
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
},
|
|
|
|
|
enableSwitch: { // 开启 地图选择
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: true
|
|
|
|
|
},
|
|
|
|
|
enableZoom: { // 开启 地图放大组件
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: true
|
|
|
|
|
},
|
|
|
|
|
enblueTranslate: { // 开启 地图移动旋转 组件
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: true
|
|
|
|
|
},
|
|
|
|
|
enblueScale: { // 开启 地图 距离比例 组件
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-09-20 21:33:11 +08:00
|
|
|
|
computed: {
|
2024-09-19 13:09:43 +08:00
|
|
|
|
defaultLonlat () {
|
|
|
|
|
return this.$store.getters['app/getDefaultLonLat']
|
2023-09-20 21:33:11 +08:00
|
|
|
|
},
|
|
|
|
|
defaultZoom () {
|
|
|
|
|
return this.$store.getters['app/getDefaultZoom']
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted () {
|
2024-07-25 05:13:30 +08:00
|
|
|
|
this.init().then(() => {
|
|
|
|
|
// 地图初始化之后
|
2023-09-20 21:33:11 +08:00
|
|
|
|
this.map.on('load', () => {
|
2024-07-11 20:29:12 +08:00
|
|
|
|
/* 更新样式,添加自定义 sprite */
|
2023-09-20 21:33:11 +08:00
|
|
|
|
|
|
|
|
|
// 星空背景 大气层
|
|
|
|
|
this.map.setFog({
|
|
|
|
|
range: [1.0, 8.0],
|
|
|
|
|
color: 'white',
|
|
|
|
|
'horizon-blend': 0.01
|
|
|
|
|
})
|
|
|
|
|
// 添加等高线图层
|
|
|
|
|
// this.map.addSource('contours', {
|
|
|
|
|
// type: 'vector',
|
|
|
|
|
// url: 'mapbox://mapbox.mapbox-terrain-v2'
|
|
|
|
|
// })
|
|
|
|
|
// this.map.addLayer({
|
|
|
|
|
// id: 'contours',
|
|
|
|
|
// type: 'line',
|
|
|
|
|
// source: 'contours',
|
|
|
|
|
// 'source-layer': 'contour',
|
|
|
|
|
// layout: {
|
|
|
|
|
// 'line-join': 'round',
|
|
|
|
|
// 'line-cap': 'round'
|
|
|
|
|
// },
|
|
|
|
|
// paint: {
|
2024-07-27 19:04:53 +08:00
|
|
|
|
// 'line-color': '#ff69b4',// 设置等高线颜色
|
2023-09-20 21:33:11 +08:00
|
|
|
|
// 'line-width': 1 // 设置等高线宽度
|
|
|
|
|
// }
|
|
|
|
|
// })
|
2024-06-25 19:43:35 +08:00
|
|
|
|
// 3D地图
|
2023-09-20 21:33:11 +08:00
|
|
|
|
// this.map.addSource('mapbox-dem', {
|
|
|
|
|
// type: 'raster-dem',
|
|
|
|
|
// url: 'mapbox://mapbox.mapbox-terrain-dem-v1',
|
|
|
|
|
// tileSize: 512,
|
|
|
|
|
// maxzoom: 14
|
|
|
|
|
// })
|
|
|
|
|
// this.map.setTerrain({ source: 'mapbox-dem', exaggeration: 1.5 })
|
|
|
|
|
})
|
2023-11-07 13:28:53 +08:00
|
|
|
|
|
2024-10-11 12:42:56 +08:00
|
|
|
|
// 判断地图开启了点飞功能
|
|
|
|
|
if (this.enableGuided) {
|
|
|
|
|
// 长按事件 传longPress到组件外部调用
|
|
|
|
|
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(() => {
|
|
|
|
|
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) // 创建标记
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-11-07 13:28:53 +08:00
|
|
|
|
}
|
2023-09-20 21:33:11 +08:00
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
/**
|
2024-07-25 05:13:30 +08:00
|
|
|
|
* @description: 地图初始化
|
|
|
|
|
*/
|
2023-09-20 21:33:11 +08:00
|
|
|
|
async init () {
|
|
|
|
|
// token
|
2024-10-09 12:14:52 +08:00
|
|
|
|
mapboxgl.accessToken = this.token
|
2023-09-20 21:33:11 +08:00
|
|
|
|
// 实例化map
|
|
|
|
|
this.map = new mapboxgl.Map({
|
|
|
|
|
container: 'map',
|
2024-07-25 21:33:52 +08:00
|
|
|
|
style: this.mapStyles[0],
|
2024-09-19 13:09:43 +08:00
|
|
|
|
center: this.defaultLonlat,
|
2023-09-20 21:33:11 +08:00
|
|
|
|
zoom: this.defaultZoom,
|
2023-10-18 15:58:44 +08:00
|
|
|
|
pitch: 0,
|
2023-09-20 21:33:11 +08:00
|
|
|
|
bearing: 0,
|
|
|
|
|
projection: 'globe'
|
|
|
|
|
})
|
2024-07-25 05:13:30 +08:00
|
|
|
|
/* 地图控件 */
|
|
|
|
|
// 移动旋转指南针
|
2024-08-08 14:40:30 +08:00
|
|
|
|
if (this.enblueTranslate) {
|
|
|
|
|
this.map.addControl(new mapboxgl.NavigationControl(), 'top-right')
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-25 05:13:30 +08:00
|
|
|
|
// 地图比例
|
2024-08-08 14:40:30 +08:00
|
|
|
|
if (this.enblueScale) {
|
|
|
|
|
this.map.addControl(new mapboxgl.ScaleControl(), 'bottom-right')
|
|
|
|
|
}
|
2024-07-25 17:21:18 +08:00
|
|
|
|
// 全屏 并再之后 刷新地图
|
2024-08-08 14:40:30 +08:00
|
|
|
|
if (this.enableZoom) {
|
|
|
|
|
this.map.addControl(new CustomFullscreenControl(this.handleResize), 'top-right')
|
|
|
|
|
}
|
2024-07-25 17:21:18 +08:00
|
|
|
|
|
2024-07-25 19:59:01 +08:00
|
|
|
|
// 地图样式选择控件
|
2024-07-25 21:33:52 +08:00
|
|
|
|
// 自定义地图样式列表
|
2024-08-08 14:40:30 +08:00
|
|
|
|
if (this.enableSwitch) {
|
|
|
|
|
const styleSwitcherControl = new MapboxStyleSwitcherControl(this.mapStyles, 'iconfont icon-duozhang f-s-20', this.currentStyleIndex)
|
|
|
|
|
this.map.addControl(styleSwitcherControl, 'top-right')
|
|
|
|
|
}
|
2024-07-25 19:59:01 +08:00
|
|
|
|
|
2024-07-25 17:21:18 +08:00
|
|
|
|
// 飞机跟随
|
2024-08-08 14:40:30 +08:00
|
|
|
|
if (this.enableFollow) {
|
|
|
|
|
this.map.addControl(new FollowControl({
|
|
|
|
|
defaultIconClass: 'iconfont icon-weidingwei f-s-20', // 默认图标
|
|
|
|
|
activeIconClass: 'iconfont icon-dingwei f-s-20 brandFontColor', // 激活时图标
|
|
|
|
|
onClick: (isActive) => {
|
|
|
|
|
this.isflow = isActive // 根据控件的状态更新 isflow
|
|
|
|
|
if (this.isflow) {
|
|
|
|
|
this.goto(this.planes[0].getLngLat()) // 点击按钮首先直接 跳转到当前飞机对象最后的经纬度
|
|
|
|
|
}
|
2024-07-25 17:21:18 +08:00
|
|
|
|
}
|
2024-08-08 14:40:30 +08:00
|
|
|
|
}), 'top-right')
|
|
|
|
|
}
|
2023-09-20 21:33:11 +08:00
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* @description: 清除地图上的航线
|
|
|
|
|
*/
|
|
|
|
|
clearRoute () {
|
|
|
|
|
// 判断地图上是否已经存在 航线信息 存在先将其清除
|
|
|
|
|
if (this.map.getSource('way_route')) {
|
|
|
|
|
this.map.removeLayer('takeoff_layer')
|
|
|
|
|
this.map.removeSource('takeoff_route')
|
|
|
|
|
this.map.removeLayer('way_route_layer')
|
|
|
|
|
this.map.removeLayer('way_route_layer1')
|
|
|
|
|
this.map.removeSource('way_route')
|
|
|
|
|
this.map.removeLayer('home_point_layer')
|
|
|
|
|
this.map.removeSource('home_point')
|
|
|
|
|
this.map.removeLayer('takeoff_point_layer')
|
|
|
|
|
this.map.removeSource('takeoff_point')
|
2024-09-19 13:09:43 +08:00
|
|
|
|
for (let i = 2; i < this.lonLats.length - 1; i++) {
|
2023-09-20 21:33:11 +08:00
|
|
|
|
this.map.removeLayer('way_point_layer' + i)
|
|
|
|
|
this.map.removeSource('way_point' + i)
|
|
|
|
|
}
|
2024-09-19 13:09:43 +08:00
|
|
|
|
this.lonLats = []
|
|
|
|
|
this.wayLonLats = []
|
|
|
|
|
this.takeoffLonLats = []
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
/**
|
2024-07-25 05:13:30 +08:00
|
|
|
|
* @description: 绘画航线
|
|
|
|
|
* @param {*} routeObj 航点文件对象
|
|
|
|
|
*/
|
2023-09-20 21:33:11 +08:00
|
|
|
|
makeRoute (routeObj) {
|
|
|
|
|
// 初始化清空航线
|
|
|
|
|
this.clearRoute()
|
|
|
|
|
// 获取所有航点 及 非起点所有航点
|
2024-07-10 22:24:08 +08:00
|
|
|
|
routeObj.questAss.tasks.forEach((element, index) => {
|
2024-09-19 13:09:43 +08:00
|
|
|
|
const lonLat = [element.y, element.x, 100]
|
|
|
|
|
this.lonLats.push(lonLat)
|
2024-07-10 22:24:08 +08:00
|
|
|
|
if (index > 1 && index < routeObj.questAss.taskcount - 1) {
|
2024-09-19 13:09:43 +08:00
|
|
|
|
this.wayLonLats.push(lonLat)
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// 跳转home点位置
|
2024-09-19 13:09:43 +08:00
|
|
|
|
this.goto(this.lonLats[0])
|
2023-09-20 21:33:11 +08:00
|
|
|
|
// 起飞 降落虚线
|
2024-09-19 13:09:43 +08:00
|
|
|
|
if (routeObj.questAss.tasks[this.lonLats.length - 1].command === 20) {
|
|
|
|
|
this.takeoffLonLats.push(this.lonLats[2])
|
|
|
|
|
this.takeoffLonLats.push(this.lonLats[1])
|
|
|
|
|
this.takeoffLonLats.push(this.lonLats[this.lonLats.length - 2])
|
2024-07-25 05:13:30 +08:00
|
|
|
|
} else if (
|
2024-09-19 13:09:43 +08:00
|
|
|
|
routeObj.questAss.tasks[this.lonLats.length - 1].command === 21
|
2024-07-25 05:13:30 +08:00
|
|
|
|
) {
|
2024-09-19 13:09:43 +08:00
|
|
|
|
this.takeoffLonLats.push(this.lonLats[2])
|
|
|
|
|
this.takeoffLonLats.push(this.lonLats[1])
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 起飞降落虚线
|
|
|
|
|
this.map.addSource('takeoff_route', {
|
|
|
|
|
type: 'geojson',
|
|
|
|
|
data: {
|
|
|
|
|
type: 'Feature',
|
|
|
|
|
properties: {},
|
|
|
|
|
geometry: {
|
|
|
|
|
type: 'LineString',
|
2024-09-19 13:09:43 +08:00
|
|
|
|
coordinates: this.takeoffLonLats
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
this.map.addLayer({
|
|
|
|
|
id: 'takeoff_layer',
|
|
|
|
|
type: 'line',
|
|
|
|
|
source: 'takeoff_route',
|
|
|
|
|
layout: {
|
|
|
|
|
'line-join': 'round', // 线连接处的样式
|
2024-07-25 05:13:30 +08:00
|
|
|
|
'line-cap': 'round' // 线结束处的样式
|
2023-09-20 21:33:11 +08:00
|
|
|
|
},
|
|
|
|
|
paint: {
|
|
|
|
|
'line-color': '#fff', // 线的颜色
|
|
|
|
|
'line-width': 2, // 线的宽度
|
|
|
|
|
'line-opacity': 1.0, // 线的透明度
|
2024-07-25 05:13:30 +08:00
|
|
|
|
'line-dasharray': [3, 2] // 虚线
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// 航线 叠加描边线
|
|
|
|
|
this.map.addSource('way_route', {
|
|
|
|
|
type: 'geojson',
|
|
|
|
|
data: {
|
|
|
|
|
type: 'Feature',
|
|
|
|
|
properties: {},
|
|
|
|
|
geometry: {
|
|
|
|
|
type: 'LineString',
|
2024-09-19 13:09:43 +08:00
|
|
|
|
coordinates: this.wayLonLats
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
this.map.addLayer({
|
|
|
|
|
id: 'way_route_layer1',
|
|
|
|
|
type: 'line',
|
|
|
|
|
source: 'way_route',
|
|
|
|
|
layout: {
|
|
|
|
|
'line-join': 'round', // 线连接处的样式
|
2024-07-25 05:13:30 +08:00
|
|
|
|
'line-cap': 'round' // 线结束处的样式
|
2023-09-20 21:33:11 +08:00
|
|
|
|
},
|
|
|
|
|
paint: {
|
|
|
|
|
'line-color': '#fff', // 线的颜色
|
|
|
|
|
'line-width': 4, // 线的宽度
|
2024-07-25 05:13:30 +08:00
|
|
|
|
'line-opacity': 1.0 // 线的透明度
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
this.map.addLayer({
|
|
|
|
|
id: 'way_route_layer',
|
|
|
|
|
type: 'line',
|
|
|
|
|
source: 'way_route',
|
|
|
|
|
layout: {
|
|
|
|
|
'line-join': 'round', // 线连接处的样式
|
2024-07-25 05:13:30 +08:00
|
|
|
|
'line-cap': 'round' // 线结束处的样式
|
2023-09-20 21:33:11 +08:00
|
|
|
|
},
|
|
|
|
|
paint: {
|
|
|
|
|
'line-color': '#f00', // 线的颜色
|
|
|
|
|
'line-width': 2, // 线的宽度
|
2024-07-25 05:13:30 +08:00
|
|
|
|
'line-opacity': 1.0 // 线的透明度
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// 航点 图标 PS:home点 起飞点 航点 送餐点等
|
2024-09-19 13:09:43 +08:00
|
|
|
|
this.lonLats.forEach((item, index) => {
|
2023-09-20 21:33:11 +08:00
|
|
|
|
// home点
|
2024-07-25 05:13:30 +08:00
|
|
|
|
if (index === 0) {
|
|
|
|
|
// 第一点home点
|
2023-09-20 21:33:11 +08:00
|
|
|
|
this.map.addSource('home_point', {
|
|
|
|
|
type: 'geojson',
|
|
|
|
|
data: {
|
|
|
|
|
type: 'FeatureCollection',
|
2024-07-25 05:13:30 +08:00
|
|
|
|
features: [
|
|
|
|
|
{
|
|
|
|
|
type: 'Feature',
|
|
|
|
|
geometry: {
|
|
|
|
|
type: 'Point',
|
|
|
|
|
coordinates: item
|
|
|
|
|
},
|
|
|
|
|
properties: {
|
|
|
|
|
'marker-symbol': 'homePoint' // home点图标
|
|
|
|
|
}
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
2024-07-25 05:13:30 +08:00
|
|
|
|
]
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
this.map.addLayer({
|
|
|
|
|
id: 'home_point_layer',
|
|
|
|
|
type: 'symbol',
|
|
|
|
|
source: 'home_point',
|
|
|
|
|
layout: {
|
|
|
|
|
'icon-image': '{marker-symbol}',
|
|
|
|
|
'icon-size': 1.5, // 图标的大小
|
|
|
|
|
'icon-allow-overlap': true
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-07-25 05:13:30 +08:00
|
|
|
|
} else if (index === 1) {
|
|
|
|
|
// 起飞点
|
2023-09-20 21:33:11 +08:00
|
|
|
|
let takeoffPoint
|
|
|
|
|
// 起点图标设定 根据最后一个航点为RETURN_TO_LAUNCH 20 返回起点降落 或者 最后一个航点为LAND 21 指定点降落
|
2024-09-19 13:09:43 +08:00
|
|
|
|
if (routeObj.questAss.tasks[this.lonLats.length - 1].command === 20) {
|
2023-09-20 21:33:11 +08:00
|
|
|
|
takeoffPoint = 'takeoffLandPoint'
|
2024-07-25 05:13:30 +08:00
|
|
|
|
} else if (
|
2024-09-19 13:09:43 +08:00
|
|
|
|
routeObj.questAss.tasks[this.lonLats.length - 1].command === 21
|
2024-07-25 05:13:30 +08:00
|
|
|
|
) {
|
2023-09-20 21:33:11 +08:00
|
|
|
|
takeoffPoint = 'takeoffPoint'
|
|
|
|
|
}
|
|
|
|
|
this.map.addSource('takeoff_point', {
|
|
|
|
|
type: 'geojson',
|
|
|
|
|
data: {
|
|
|
|
|
type: 'FeatureCollection',
|
2024-07-25 05:13:30 +08:00
|
|
|
|
features: [
|
|
|
|
|
{
|
|
|
|
|
type: 'Feature',
|
|
|
|
|
geometry: {
|
|
|
|
|
type: 'Point',
|
|
|
|
|
coordinates: item
|
|
|
|
|
},
|
|
|
|
|
properties: {
|
|
|
|
|
'marker-symbol': takeoffPoint // 起飞点图标
|
|
|
|
|
}
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
2024-07-25 05:13:30 +08:00
|
|
|
|
]
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
this.map.addLayer({
|
|
|
|
|
id: 'takeoff_point_layer',
|
|
|
|
|
type: 'symbol',
|
|
|
|
|
source: 'takeoff_point',
|
|
|
|
|
layout: {
|
|
|
|
|
'icon-image': '{marker-symbol}',
|
|
|
|
|
'icon-size': 1.5, // 图标的大小
|
|
|
|
|
'icon-allow-overlap': true
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-07-25 05:13:30 +08:00
|
|
|
|
} else {
|
|
|
|
|
// waypoint点
|
2024-09-19 13:09:43 +08:00
|
|
|
|
if (index !== this.lonLats.length - 1) {
|
2024-07-25 05:13:30 +08:00
|
|
|
|
// 最后一个点不显示 要不和最后一个点结合 要不和起点结合
|
2023-09-20 21:33:11 +08:00
|
|
|
|
let wayPoint = 'wayPoint'
|
2024-09-19 13:09:43 +08:00
|
|
|
|
if (index === this.lonLats.length - 2) {
|
2024-07-25 05:13:30 +08:00
|
|
|
|
// 降落点 如果是LAND 21 和最后一个waypoint点结合
|
|
|
|
|
if (
|
2024-09-19 13:09:43 +08:00
|
|
|
|
routeObj.questAss.tasks[this.lonLats.length - 1].command === 21
|
2024-07-25 05:13:30 +08:00
|
|
|
|
) {
|
2023-09-20 21:33:11 +08:00
|
|
|
|
wayPoint = 'wayLandPoint'
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-25 05:13:30 +08:00
|
|
|
|
if (routeObj.questAss.tasks[index].command === 94) {
|
|
|
|
|
// command字段为94既然 投放放勾航点 放勾图标
|
2023-09-20 21:33:11 +08:00
|
|
|
|
wayPoint = 'hookPoint'
|
|
|
|
|
}
|
|
|
|
|
this.map.addSource('way_point' + index, {
|
|
|
|
|
type: 'geojson',
|
|
|
|
|
data: {
|
|
|
|
|
type: 'FeatureCollection',
|
2024-07-25 05:13:30 +08:00
|
|
|
|
features: [
|
|
|
|
|
{
|
|
|
|
|
type: 'Feature',
|
|
|
|
|
geometry: {
|
|
|
|
|
type: 'Point',
|
|
|
|
|
coordinates: item
|
|
|
|
|
},
|
|
|
|
|
properties: {
|
|
|
|
|
'marker-symbol': wayPoint
|
|
|
|
|
}
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
2024-07-25 05:13:30 +08:00
|
|
|
|
]
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
this.map.addLayer({
|
|
|
|
|
id: 'way_point_layer' + index,
|
|
|
|
|
type: 'symbol',
|
|
|
|
|
source: 'way_point' + index,
|
|
|
|
|
layout: {
|
|
|
|
|
'icon-image': '{marker-symbol}',
|
|
|
|
|
'icon-size': 1.5, // 图标的大小
|
|
|
|
|
'icon-allow-overlap': true
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
2024-10-11 12:42:56 +08:00
|
|
|
|
/**
|
|
|
|
|
* @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)
|
|
|
|
|
},
|
2023-09-20 21:33:11 +08:00
|
|
|
|
/**
|
|
|
|
|
* @description: 创建飞机轨迹 ps:原理删除之前的轨迹 重新绘制
|
|
|
|
|
* @param {arr} coordinatesArray 飞机经纬高度数组
|
|
|
|
|
*/
|
|
|
|
|
createPathWithArray (coordinatesArray) {
|
|
|
|
|
// 创建一个包含纬度、经度和高度信息的 GeoJSON LineString
|
|
|
|
|
const geojson = {
|
|
|
|
|
type: 'Feature',
|
|
|
|
|
properties: {},
|
|
|
|
|
geometry: {
|
|
|
|
|
type: 'LineString',
|
2024-07-25 05:13:30 +08:00
|
|
|
|
coordinates: coordinatesArray.map((coord) => [
|
|
|
|
|
coord[0],
|
|
|
|
|
coord[1],
|
|
|
|
|
coord[2]
|
|
|
|
|
])
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 不是第一次 则改变路径图层里面得数据
|
|
|
|
|
if (this.map.getLayer('path')) {
|
|
|
|
|
this.map.getSource('path').setData(geojson)
|
2024-07-25 05:13:30 +08:00
|
|
|
|
} else {
|
|
|
|
|
// 第一次在地图里添加路径图层
|
2023-09-20 21:33:11 +08:00
|
|
|
|
// 如果坐标数组不为空,创建新路径
|
|
|
|
|
if (coordinatesArray.length > 0) {
|
|
|
|
|
// 添加3D图层
|
|
|
|
|
this.map.addLayer({
|
|
|
|
|
id: 'path',
|
|
|
|
|
type: 'line',
|
|
|
|
|
source: {
|
|
|
|
|
type: 'geojson',
|
|
|
|
|
data: geojson
|
|
|
|
|
},
|
|
|
|
|
layout: {
|
|
|
|
|
'line-cap': 'round',
|
|
|
|
|
'line-join': 'round'
|
|
|
|
|
},
|
|
|
|
|
paint: {
|
|
|
|
|
'line-color': 'purple',
|
2024-07-25 01:05:28 +08:00
|
|
|
|
'line-width': 2
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
/**
|
2024-07-25 05:13:30 +08:00
|
|
|
|
* @description: 创建一个飞机
|
|
|
|
|
* @param {*} plane 飞机对象
|
|
|
|
|
*/
|
2023-09-20 21:33:11 +08:00
|
|
|
|
makePlane (plane, index = 0) {
|
|
|
|
|
const customIcon = document.createElement('div')
|
|
|
|
|
customIcon.className = 'custom-marker' // 添加自定义样式类名
|
|
|
|
|
customIcon.style.backgroundImage = `url(${planeIcon})` // 使用引入的 SVG 图标
|
|
|
|
|
customIcon.style.width = '64px' // 图标宽度
|
|
|
|
|
customIcon.style.height = '64px' // 图标高度
|
|
|
|
|
// 创建一个marker对象
|
|
|
|
|
this.planes[index] = new mapboxgl.Marker(customIcon)
|
2024-09-19 13:09:43 +08:00
|
|
|
|
.setLngLat([plane.lon, plane.lat])
|
2024-07-25 05:13:30 +08:00
|
|
|
|
.setPopup(
|
|
|
|
|
new mapboxgl.Popup({ offset: 25 }).setHTML(
|
|
|
|
|
'<h3>' + plane.name + '</h3><hr><p>macID:' + plane.macadd + '</p>'
|
|
|
|
|
)
|
|
|
|
|
) // 添加弹出窗口
|
2023-09-20 21:33:11 +08:00
|
|
|
|
.addTo(this.map)
|
|
|
|
|
},
|
|
|
|
|
/**
|
2024-07-25 05:13:30 +08:00
|
|
|
|
* @description: 移除页面上的所有飞机
|
|
|
|
|
*/
|
2023-09-20 21:33:11 +08:00
|
|
|
|
removePlanes () {
|
2024-07-25 05:13:30 +08:00
|
|
|
|
this.planes.forEach((plane) => {
|
2023-09-20 21:33:11 +08:00
|
|
|
|
plane.remove()
|
|
|
|
|
})
|
|
|
|
|
this.planes = []
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* @description: 实时更新经纬度
|
2024-09-19 13:09:43 +08:00
|
|
|
|
* @param {obj} lonLat lon经度 lat纬度
|
2023-09-20 21:33:11 +08:00
|
|
|
|
* @param {*} index 飞机序号
|
2024-07-25 05:13:30 +08:00
|
|
|
|
* @param {*} pathArr 飞机轨迹 痕迹坐标数组
|
2023-09-20 21:33:11 +08:00
|
|
|
|
*/
|
2024-09-19 13:09:43 +08:00
|
|
|
|
setPlaneLonLat (lonLat, index, pathArr) {
|
2023-09-20 21:33:11 +08:00
|
|
|
|
// 设置新的经纬度
|
|
|
|
|
const plane = this.planes[index]
|
|
|
|
|
if (plane != null) {
|
2024-09-19 13:09:43 +08:00
|
|
|
|
plane.setLngLat([lonLat.lon, lonLat.lat])
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
|
|
|
|
// 创建轨迹
|
2024-07-25 05:13:30 +08:00
|
|
|
|
this.createPathWithArray(pathArr) // 创建轨迹
|
2023-09-20 21:33:11 +08:00
|
|
|
|
// 镜头跟随飞机
|
2024-07-25 05:13:30 +08:00
|
|
|
|
if (this.isflow) {
|
2023-09-20 21:33:11 +08:00
|
|
|
|
this.map.flyTo({
|
2024-09-19 13:09:43 +08:00
|
|
|
|
center: lonLat,
|
2023-09-20 21:33:11 +08:00
|
|
|
|
speed: 2,
|
|
|
|
|
curve: 1,
|
|
|
|
|
easing (t) {
|
|
|
|
|
return t
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
/**
|
2024-07-25 05:13:30 +08:00
|
|
|
|
* @description: 镜头跳转
|
2024-09-19 13:09:43 +08:00
|
|
|
|
* @param {obj} lonLat {lon:lon,lat:lat} 经纬度
|
2024-07-25 05:13:30 +08:00
|
|
|
|
*/
|
2024-09-19 13:09:43 +08:00
|
|
|
|
goto (lonLat) {
|
2023-09-20 21:33:11 +08:00
|
|
|
|
this.map.flyTo({
|
2024-09-19 13:09:43 +08:00
|
|
|
|
center: lonLat,
|
2023-09-20 21:33:11 +08:00
|
|
|
|
speed: 2,
|
|
|
|
|
curve: 1,
|
|
|
|
|
easing (t) {
|
|
|
|
|
return t
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
/**
|
2024-07-25 05:13:30 +08:00
|
|
|
|
* @description: 屏幕横移 纵移
|
|
|
|
|
* @param {*} x 正数向左移动 负数向右移动
|
|
|
|
|
* @param {*} y 正数向上移动 负数向下移动
|
|
|
|
|
*/
|
2024-07-23 18:49:49 +08:00
|
|
|
|
mapXOffset (x, y) {
|
|
|
|
|
this.map.panBy([x, y], {
|
2023-09-20 21:33:11 +08:00
|
|
|
|
duration: 333 // 过渡持续时间,以毫秒为单位
|
|
|
|
|
})
|
2024-07-25 01:19:15 +08:00
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* @description:重置地图大小
|
|
|
|
|
*/
|
|
|
|
|
handleResize () {
|
|
|
|
|
if (this.map) {
|
2024-07-25 14:40:38 +08:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.map.resize()
|
2024-08-09 13:00:02 +08:00
|
|
|
|
}, 200)
|
2024-07-25 01:19:15 +08:00
|
|
|
|
}
|
2023-09-20 21:33:11 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
beforeDestroy () {
|
|
|
|
|
if (this.map) {
|
2024-09-19 13:09:43 +08:00
|
|
|
|
this.$store.commit('app/setDefaultLonLat', this.map.getCenter()) // 记录当前经纬度 缺省
|
2024-07-25 05:13:30 +08:00
|
|
|
|
this.$store.commit('app/setDefaultZoom', this.map.getZoom()) // 记录当前经纬度 缺省
|
|
|
|
|
this.map.remove() // 清除地图资源
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
2024-07-25 13:15:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-20 21:33:11 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
#map {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.custom-marker {
|
|
|
|
|
background-size: cover;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
|
|
|
|
</style>
|