代码
const map = new BMap.Map('map');
map.centerAndZoom(new BMap.Point(116.404, 39.915), 14);

// GeoJSON 格式数据,FeatureCollection 中包含 Polygon 和 MultiPolygon
const geojsonData = {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      properties: {name: 'Polygon示例'},
      geometry: {
        type: 'Polygon',
        coordinates: [
          [
            [116.38, 39.92],
            [116.42, 39.92],
            [116.42, 39.9],
            [116.38, 39.9],
            [116.38, 39.92],
          ],
        ],
      },
    },
    {
      type: 'Feature',
      properties: {name: 'MultiPolygon示例'},
      geometry: {
        type: 'MultiPolygon',
        coordinates: [
          [
            [
              [116.36, 39.96],
              [116.4, 39.96],
              [116.4, 39.94],
              [116.36, 39.94],
              [116.36, 39.96],
            ],
          ],
          [
            [
              [116.42, 39.96],
              [116.46, 39.96],
              [116.46, 39.94],
              [116.42, 39.94],
              [116.42, 39.96],
            ],
          ],
        ],
      },
    },
  ],
};

const polygonLayer = new BMap.PolygonLayer({
  data: geojsonData,
  fillColor: '#108ee9',
  fillOpacity: 0.2,
  strokeColor: '#108ee9',
  strokeWeight: 2,
});

map.addLayer(polygonLayer);

function add() {
  map.addLayer(polygonLayer);
}

function remove() {
  map.removeLayer(polygonLayer);
}

PolygonLayer 支持批量绘制 Polygon、MultiPolygon 类型的 GeoJSON 面数据,适合面数据量较大的场景

预览