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

const container = document.getElementById('map');
const center = [116.5023, 39.9914];
const range = (720 * 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: 45,
    heading: 0,
    provider,
  },
  rendering: {
    sky: null,
  },
});

// 北京 798 艺术区的路网骨架,坐标为 BD-09 经纬度。
const roads = [
  {
    name: '北街',
    color: '#0dccff',
    coordinates: [
      [116.4998, 39.9936],
      [116.5048, 39.9936],
    ],
  },
  {
    name: '中一街',
    color: '#ffb020',
    coordinates: [
      [116.4998, 39.9921],
      [116.5048, 39.9921],
    ],
  },
  {
    name: '中二街',
    color: '#0dccff',
    coordinates: [
      [116.4998, 39.9907],
      [116.5048, 39.9907],
    ],
  },
  {
    name: '南街',
    color: '#ffb020',
    coordinates: [
      [116.4998, 39.9893],
      [116.5048, 39.9893],
    ],
  },
  {
    name: '西巷',
    color: '#0dccff',
    coordinates: [
      [116.5005, 39.9888],
      [116.5005, 39.994],
    ],
  },
  {
    name: '中巷',
    color: '#ffb020',
    coordinates: [
      [116.502, 39.9888],
      [116.502, 39.994],
    ],
  },
  {
    name: '东巷',
    color: '#0dccff',
    coordinates: [
      [116.5035, 39.9888],
      [116.5035, 39.994],
    ],
  },
];
const source = GeoJSONDataSource.fromGeoJSON(
  roads.map((road) => ({
    type: 'Feature',
    geometry: {
      type: 'LineString',
      coordinates: road.coordinates,
    },
    properties: {
      name: road.name,
      color: road.color,
    },
  })),
);
source.defineAttribute('color');

// 线宽固定 1 像素,逐条颜色由数据里的 color 字段决定。
const lines = engine.add(
  new SimpleLine({
    vertexColors: true,
  }),
);
lines.dataSource = source;

在北京 798 艺术区绘制 1 像素宽的细线路网,线路颜色按数据逐条设置。

预览