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

const container = document.getElementById('map');
const center = [116.50323, 39.99145];
const aspect = container.clientWidth / container.clientHeight;
const range = 1320 * Math.max(1, 1.05 / aspect);
BaiduMapConfig.ak = '您的密钥';
const provider = new BaiduVectorTileProvider({
  displayOptions: {
    building: false,
    flat: true,
    poi: false,
  },
});

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

// 沿北京 798 艺术区一带底图道路内侧描绘相邻建筑分区,坐标系为 BD-09。
const buildings = [
  {
    name: '西侧建筑区',
    color: '#347eae',
    boundary: [
      [116.500852, 39.992321],
      [116.501944, 39.992344],
      [116.502875, 39.992367],
      [116.502885, 39.991716],
      [116.502905, 39.991251],
      [116.502915, 39.990422],
      [116.501975, 39.990414],
      [116.500902, 39.990399],
      [116.500872, 39.990817],
      [116.500852, 39.991391],
    ],
  },
  {
    name: '东侧建筑区',
    color: '#be7a31',
    boundary: [
      [116.502936, 39.992367],
      [116.504028, 39.992398],
      [116.505475, 39.992421],
      [116.505515, 39.991825],
      [116.505505, 39.991391],
      [116.505525, 39.990802],
      [116.505525, 39.990499],
      [116.504261, 39.990468],
      [116.503421, 39.990437],
      [116.502956, 39.990414],
    ],
  },
  {
    name: '西街建筑区',
    color: '#357b67',
    boundary: [
      [116.500073, 39.992243],
      [116.500649, 39.992251],
      [116.50071, 39.991941],
      [116.50074, 39.991298],
      [116.500771, 39.990592],
      [116.500477, 39.990538],
      [116.500073, 39.990492],
    ],
  },
  {
    name: '东街建筑区',
    color: '#8135c1',
    boundary: [
      [116.505788, 39.991794],
      [116.506395, 39.991801],
      [116.506436, 39.99146],
      [116.506456, 39.99084],
      [116.505778, 39.990825],
    ],
  },
];

const source = GeoJSONDataSource.fromGeoJSON(
  buildings.map(({name, color, boundary}) => ({
    type: 'Feature',
    geometry: {
      type: 'Polygon',
      coordinates: [[...boundary, boundary[0]]],
    },
    properties: {name, color},
  })),
);
source.defineAttribute('color').defineAttribute('name');

const blocks = engine.add(
  new Polygon({
    vertexColors: true,
    transparent: true,
    opacity: 0.62,
    zOffset: 3,
    border: true,
    borderColor: '#233e58',
    borderWidth: 2,
  }),
);
blocks.dataSource = source;

const selection = document.getElementById('selected-block');
blocks.addEventListener('click', ({entity}) => {
  if (entity?.pairs.name) {
    selection.textContent = entity.pairs.name;
  }
});

沿北京 798 艺术区周边的道路圈绘四处建筑分区,以不同半透明颜色填充并显示 Polygon 原生描边。点击地块可查看分区名称。

预览