Skip to content

地图定位

框架支持多种对象的定向定位,包括定位到对象、定位到指定坐标、定位到指定视角

支持说明

INFO

定位到指定对象:支持场景加载的geojson、entity、model等对象

定位到指定坐标:指定经纬度(带高度)- (x,y,z)

定位到指定视角:参数与设置初始视角时的参数一致

代码实例

ts
let map: any
LarkExplorer.ready({
    baseUrl: './dist/resources/',
  }).then(()=>{
    map = new LarkExplorer.Map('map')
  })

// 加载数据对象
let obj: any
const geojson = async () => {
  const url = 'http://localhost:8086/geojson/point.json'
  obj = await map.Layers.Geojson.add(url, '1', 1)
}

// 定位至对象
const zoomToItem = () => map.Navigation.zoomToItem(obj)

// 定位到指定坐标
const zoomToDegree = () => {
  const pos = { x: 119, y: 29, z: 5000 }
  map.Navigation.zoomToDegree(pos, function () {
    console.log('定位至坐标完成')
  })
}

// 定位到指定视角
const zoomToPos = () => {
  const status = {
    position: {
      x: -2072151.6231208083,
      y: 8120125.20405065,
      z: 5940392.882414031,
    },
    hpr: {
      heading: 1.7763568394002505e-15,
      pitch: -1.5685994338656415,
      roll: 0,
    },
  }
  map.Navigation.zoomToPos(status)
}

运行效果 更多示例