路径规划
该框架支持路径规划
代码实例
typescript
<script setup lang="ts">
import { onMounted, onBeforeUnmount } from 'vue'
const LarkExplorer = window.LarkExplorer
let map: any
onMounted(() => {
LarkExplorer.ready({
baseUrl: './dist/resources/',
}).then(initMap)
})
function initMap() {
// 默认谷歌影像地图
const baseImagery = LarkExplorer.BaseLayer.DefaultTdtImg
// 默认全球地形
const baseTerrain = LarkExplorer.BaseLayer.DefaultTerrain
map = new LarkExplorer.Map('map', baseImagery)
initView()
}
function initView() {
const status = {
position: {
x: -2185591.5394355264,
y: 4401786.6213633185,
z: 4076525.0618230435,
},
hpr: {
heading: 6.126130316862198,
pitch: -1.4997006529846066,
roll: 0.04886634548534996,
},
}
map.Navigation.flyToPos(status, 3)
console.log(map)
}
const pos1 = {
x: 116.34088031312257,
y: 39.89767747124668,
z: 37.37722853025194,
}
const pos2 = {
x: 116.4680262368402,
y: 39.858732826614144,
z: 26.990160668855886,
}
const getImage = (name: string) => {
return new URL('../assets/images/' + name + '.png', import.meta.url).href
}
let pathLine: any
const driving = async () => {
const startPos = LarkExplorer.Coordinate.PosFromXYZ(pos1.x, pos1.y, pos1.z)
map.Layers.Add.addBillboard(startPos, { image: getImage('start') })
const EndPos = LarkExplorer.Coordinate.PosFromXYZ(pos2.x, pos2.y, pos2.z)
map.Layers.Add.addBillboard(EndPos, { image: getImage('end') })
const gdKey = '2401b18dd27d6515643a3ea52c65ff3e'
let result = await LarkExplorer.WebApi.Path.drivingByGd(pos1, pos2, gdKey)
const path = result.paths[1]
pathLine = new map.SpecialAnalysis.Path(map.viewer, path, true)
showLine = true
}
let showLine = false
const changeShow = () => {
if (!pathLine) return
showLine = !showLine
pathLine.show = showLine
}
const destroy = () => {
pathLine && pathLine.destroy()
pathLine = undefined
}
</script>
运行效果
更多示例