new Style({
stroke: new Stroke({
color: strokeColor,
width: 4,
}),
fill: new Fill({
color: fillColor,
}),
text: new Text({
text: this.displayText ? name : '', // 设置这里的text,太长了
font: '13px font-size',
overflow: false,
fill: new Fill({
color: '#fff',
}),
backgroundFill: new Fill({
color: this.displayTextBgc ? 'rgba(0,0,0,0.6)' : 'transparent', // transparent,
}),
padding: [2, 0, 0, 2],
}),
})
style="word-break: break-all;white-space: normal;"
题主是用canvas绘制的吧?内容来自那篇文章?canvas drawText不会换行,需要用measureText来测量文章宽度进行截取后分别绘制截取的内容实现换行。
具体参考下面的文章