mapbox处理中文标注不能换行问题

mapbox的换行侧率是根据空格进行的,因为中文中没有设置空格,因此换行不起作用。

解决方法:在node_modules\ol-mapbox-style\util.js  60行添加下列代码:

let tempText = "",tempText1 = "",tempText2 = "",tempText3 = "",tempText4 = "";
if (text.length > em) {
tempText1 = text.substr(0,em) + " ";
tempText2 = text.substr(em);
if (tempText2.length > em) {
tempText3 = tempText2.substr(0,em) + " ";
tempText4 = tempText2.substr(em);
if (tempText4.length <=2) {
tempText = tempText1 + tempText3.trim() + tempText4;
} else {
tempText = tempText1 + tempText3 + tempText4;
}
text = tempText;
} else {
if (tempText2.length <=2) {
tempText = tempText1.trim() + tempText2;
} else {
tempText = tempText1 + tempText2;
}

text = tempText;
}
}

 

posted @ 2019-07-15 14:44  yiwenzhang  阅读(653)  评论(0编辑  收藏  举报