代码
const map = new BMap.Map('map', {
displayOptions: {
poi: false,
},
});
map.centerAndZoom(new BMap.Point(116.404, 39.915), 14);
// GeoJSON 格式数据
const data = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {type: 'Point', coordinates: [116.38, 39.92]},
properties: {text: '文字1文字1文字1文字1文字1文字1'},
},
{
type: 'Feature',
geometry: {type: 'Point', coordinates: [116.4, 39.91]},
properties: {text: '文字2文字2文字2文字2文字2文字2'},
},
{
type: 'Feature',
geometry: {type: 'Point', coordinates: [116.42, 39.93]},
properties: {text: '文字3文字3文字3文字3文字3文字3'},
},
],
};
var layer = new BMap.TextLayer({
textMaxWidth: 84,
lineHeight: 30,
fontSize: 20,
color: '#333',
strokeColor: 'rgba(255, 255, 255, 1)',
strokeWeight: 2,
enablePicked: true,
});
layer.setData(data);
map.addLayer(layer);
通过 textMaxWidth 设置文字最大宽度,实现换行效果
预览