代码
import * as mapvthree from '@baidumap/mapv-three';

mapvthree.BaiduMapConfig.ak = '您的密钥';
const {BaiduVectorTileProvider, Engine, GeoJSONDataSource, Polyline, SimplePoint} = mapvthree;

const container = document.getElementById('map');
const center = [120.397069, 36.06644];
const aspect = container.clientWidth / container.clientHeight;
const range = (2_200 * 1.35) / Math.min(1.35, aspect);
const engine = new Engine(container, {
  map: {
    projection: 'EPSG:3857',
    center,
    pitch: 0,
    heading: 0,
    range,
    provider: new BaiduVectorTileProvider({
      displayOptions: {
        building: false,
        flat: true,
        poi: true,
      },
    }),
  },
  rendering: {
    sky: null,
    enableAnimationLoop: false,
  },
});

const coordinates = routeCoordinates();
const trail = engine.add(
  new Polyline({
    color: '#116ae6',
    keepSize: true,
    lineWidth: 7,
    height: 1,
  }),
);
trail.dataSource = createRouteSource(coordinates);

const endpoints = engine.add(
  new SimplePoint({
    color: '#0c418d',
    size: 13,
    depthTest: false,
  }),
);
endpoints.dataSource = GeoJSONDataSource.fromGeoJSON({
  type: 'Feature',
  geometry: {
    type: 'MultiPoint',
    coordinates: [coordinates[0], coordinates.at(-1)].map(([lng, lat]) => [lng, lat, 2]),
  },
  properties: {},
});

const width = document.getElementById('width');
const value = document.getElementById('width-value');
width.addEventListener('input', () => {
  trail.lineWidth = Number(width.value);
  value.textContent = width.value + ' px';
  engine.requestRender();
});

function createRouteSource(coordinates) {
  return GeoJSONDataSource.fromGeoJSON({
    type: 'Feature',
    geometry: {
      type: 'LineString',
      coordinates,
    },
    properties: {},
  });
}

// 五四广场至青岛奥帆中心的百度步行路线,坐标为 BD-09 经纬度。
function routeCoordinates() {
  return [
    [120.39095563084, 36.068931598356],
    [120.3909493427, 36.068967409024],
    [120.39154042773, 36.069000885784],
    [120.39161858031, 36.068704116355],
    [120.39205964831, 36.06876975727],
    [120.39258875026, 36.068755170404],
    [120.39272259778, 36.068726726009],
    [120.39281063172, 36.068596902742],
    [120.39293998771, 36.06855022466],
    [120.3930199369, 36.06842105751],
    [120.39320049631, 36.068359865319],
    [120.39314480137, 36.068141060905],
    [120.3932813438, 36.067996649655],
    [120.39322654717, 36.067915691716],
    [120.39323014039, 36.067863907765],
    [120.39332266586, 36.067804100905],
    [120.3933783608, 36.067673473813],
    [120.39387332714, 36.067625409406],
    [120.39526120915, 36.067289905893],
    [120.39560436185, 36.06712944718],
    [120.39603734511, 36.066815093018],
    [120.39623317571, 36.066774978127],
    [120.39629426049, 36.066513136783],
    [120.39640115884, 36.066401543966],
    [120.39658081994, 36.066336630423],
    [120.39692037943, 36.066348300278],
    [120.39717190497, 36.066101701297],
    [120.39757434584, 36.065823884475],
    [120.39829838008, 36.06526007885],
    [120.39898019396, 36.064808593788],
    [120.39980843164, 36.064880802398],
    [120.40115139838, 36.06388154599],
    [120.40160055113, 36.064273956238],
    [120.40255006006, 36.065210481265],
    [120.40300909417, 36.064861765589],
    [120.40290848396, 36.064755349012],
    [120.40308994167, 36.064644483061],
    [120.40318965358, 36.064536534483],
    [120.40316629764, 36.06447154645],
    [120.40280068729, 36.064160901443],
    [120.40253478886, 36.063878628434],
  ];
}

使用百度步行路线规划返回的五四广场至奥帆中心路段,在青岛浮山湾底图上绘制实线。拖动滑块比较不同屏幕线宽。

预览