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

const container = document.getElementById('map');
const center = [116.4005, 39.9165];
const range = (2000 * 1.42) / Math.min(1.42, container.clientWidth / container.clientHeight);
BaiduMapConfig.ak = '您的密钥';
const provider = new BaiduVectorTileProvider({
  displayOptions: {
    building: false,
    poi: false,
  },
});

const engine = new Engine(container, {
  map: {
    projection: 'EPSG:3857',
    center,
    range,
    pitch: 0,
    heading: 0,
    provider,
  },
  rendering: {
    sky: null,
  },
});

// 纯文字标签。
engine.rendering.label.addLabel({
  position: [116.404, 39.915, 20],
  text: '北京市',
  textSize: 18,
  textFillStyle: '#1a2b3c',
  textStrokeStyle: '#ffffff',
  textStrokeWidth: 3,
  collision: true,
});

// 图标加文字标签,图标在文字左侧。
engine.rendering.label.addLabel({
  position: [116.397, 39.918, 20],
  mapSrc: urlUtils.getAssetUrl('assets/images/marker_red.png'),
  width: 32,
  height: 40,
  text: '故宫博物院',
  textSize: 14,
  textFillStyle: '#1a2b3c',
  textStrokeStyle: '#ffffff',
  textStrokeWidth: 3,
  textAnchor: 'left',
  collision: true,
});

用 engine.rendering.label 直接添加两个不依赖数据源的标签:天安门前的文字标签和故宫的图标文字标签,均开启碰撞检测。

预览