代码
import {
  BaiduMapConfig,
  BaiduVectorTileProvider,
  Engine,
  LODModel,
  urlUtils,
} from '@baidumap/mapv-three';

BaiduMapConfig.ak = '您的密钥';

const container = document.getElementById('map');
const aspect = container.clientWidth / container.clientHeight;
const center = [116.392, 40.0347];
const engine = new Engine(container, {
  map: {
    projection: 'EPSG:3857',
    center,
    range: 300 / Math.min(1, aspect),
    pitch: 65,
    heading: 20,
    provider: new BaiduVectorTileProvider({
      displayOptions: {
        building: false,
        poi: false,
      },
    }),
  },
  rendering: {
    enableAnimationLoop: true,
  },
});

const lod = engine.add(
  new LODModel({
    hysteresis: 0.2,
  }),
);
lod.position.set(...engine.map.projectArrayCoordinate(center));
// glTF 模型 Y 轴朝上,旋转为地图的 Z 轴朝上。
lod.rotateX(Math.PI / 2);
// distance 为该层级的最远显示距离(米)。
lod.addLevel(urlUtils.getAssetUrl('assets/models/tree/tree18.glb'), 400);
lod.addLevel(urlUtils.getAssetUrl('assets/models/tree/tree19.glb'), 1500);

用 LODModel 按相机距离切换树木模型的精度:近处显示精细模型,远处显示简化模型,超出最远距离时隐藏。缩放地图观察切换效果。

预览