效果
![uni-app 微信小程序 map marker label text-align无效 无法居中_第1张图片](http://img.e-com-net.com/image/info8/8d864d6b84b34b92b97aa3888d40d09d.jpg)
markers.push({
id: markerId,
width: 35,
height: 35,
joinCluster: true,
powerStationId: item.id,
latitude: item.latitude,
longitude: item.longitude,
iconPath: json.status === 1 ?
`${baseUri}/app/file/img/ps_online.png` : json
.status === 2 ? `${baseUri}/app/file/img/ps_offline.png` :
`${baseUri}/app/file/img/ps_alarm.png`,
label: {
content: item.powerStationName,
color: '#fff',
textAlign: 'right',
padding: 1.5,
borderRadius: 5,
borderWidth: 1,
fontSize: 9,
anchorX: -(0.5 * _t.getLenPx(item.powerStationName, 9)),
borderColor: json.status === 1 ? '#24a21d' : json
.status === 2 ? '#f40' : '#ffc123',
bgColor: '#000000BF'
}
})
getLenPx
getLenPx(str, fontSize) {
const str_leng = str.replace(/[^\x00-\xff]/gi, 'aa').length;
return str_leng * fontSize / 2
},