Skip to content

对象拾取(全局)

框架支持全局开启/关闭鼠标点击拾取对象

说明

INFO

理论支持场景中加载的所有对象,返回形式为集合,支持穿透拾取

代码实例

ts
let map: any
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, baseTerrain)
  initView()
}
function initView() {
  const status = {
    position: {
      x: -2359984.660925278,
      y: 4202729.34380753,
      z: 4254973.613698083,
    },
    hpr: {
      heading: 6.19143009202889,
      pitch: -0.8427814562100515,
      roll: 2.0657168686710747e-7,
    },
  }
  map.Navigation.flyToPos(status, 3)
}

const datas = [
  { id: '1', name: 'point' },
  { id: '2', name: 'polyline' },
  { id: '3', name: 'polygon' },
]

/**
 * 加载数据
 * @param type 1-entity形式加载,2-primitive形式加载
 */
const geojson = async (type: number) => {
  remove()
  for (let index = 0; index < datas.length; index++) {
    const { id, name } = datas[index]
    const url = 'http://localhost:8086/geojson/' + name + '.json'
    await map.Layers.Geojson.add(url, id, type)
  }
}
// 移除数据
const remove = () => {
  for (let index = 0; index < datas.length; index++) {
    const { id } = datas[index]
    map.Layers.removeById(id)
  }
}

const pick = (bool: boolean) => {
  map.Handler.pickEnabled(bool, (res: any) => {
    console.log('拾取结果:', res)
  })
}

运行效果 更多示例