代码
const map = new BMap.Map('map');
map.centerAndZoom(new BMap.Point(116.404, 39.915), 14);
map.enableScrollWheelZoom();
// 一个简单的 GeoJSON 面数据(Polygon,首尾坐标相同以闭合)
const geojson = {
type: 'Feature',
properties: {},
geometry: {
type: 'Polygon',
coordinates: [
[
[116.38, 39.93],
[116.43, 39.93],
[116.44, 39.9],
[116.4, 39.88],
[116.37, 39.9],
[116.38, 39.93],
],
],
},
};
// BMap.Polygon 直接接收 GeoJSON 数据
const polygon = new BMap.Polygon(geojson, {
strokeColor: '#3370ff',
strokeWeight: 3,
strokeOpacity: 0.9,
fillColor: '#3370ff',
fillOpacity: 0.3,
});
map.addOverlay(polygon);
预览