代码
const map = new BMap.Map('map');
const center = new BMap.Point(116.404, 39.915);
map.centerAndZoom(center, 15);
// geojson格式数据
var 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],
],
],
},
},
],
};
var imageUrl = 'https://bj.bcebos.com/mapopen-pub-jsapigl/svgmodel/up-two.png';
var polygonLayer = new BMap.PolygonLayer({
referCenter: center,
// fillTextureUrl 非空即启用纹理平铺填充
fillTextureUrl: imageUrl,
// 单张纹理图在屏幕上的宽度(px),高度按图片宽高比等比,当前示例图片宽高为32px,64px
fillTextureSize: 32,
fillTextureAlphaOnly: false, // 使用纹理图自身颜色,不只取 alpha 当蒙版
// 描边,strokeWeight 大于 0 时显示
strokeColor: 'rgba(25, 25, 250, 1)',
strokeWeight: 2,
});
polygonLayer.setData(geojsonData);
map.addLayer(polygonLayer);
预览