uni-app 微信小程序 map marker label text-align无效 无法居中

效果

在这里插入图片描述

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
},
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uni-app是一款基于Vue.js框架的跨平台开发工具,可以同时开发微信小程序、H5、App等多个平台的应用。在uni-app中,我们可以很方便地使用地图组件来标记点。 首先,我们需要引入uni-app官方提供的地图组件,在页面的json文件中添加以下代码: ``` { "usingComponents": { "uni-map": "@dcloudio/uni-map/uni-map" } } ``` 然后,在需要使用地图的页面中,在template中添加以下代码: ``` <template> <view> <uni-map :longitude="longitude" :latitude="latitude" :markers="markers" :include-points="true" ></uni-map> </view> </template> ``` 在script中,我们需要定义地图的经纬度和标记点的数据: ``` <script> export default { data() { return { longitude: 113.324520, latitude: 23.099994, markers: [{ id: 1, longitude: 113.324520, latitude: 23.099994, title: '标记点1', iconPath: '/static/marker.png', width: 30, height: 30 }, { id: 2, longitude: 113.326520, latitude: 23.099994, title: '标记点2', iconPath: '/static/marker.png', width: 30, height: 30 }] } } } </script> ``` 我们可以通过设置longitude和latitude来指定地图的中心点,通过markers来设置标记点的位置、标题、图标等信息。iconPath需要提前准备好对应的图标文件。 最后,在地图组件上设置:include-points="true",可以使得地图自动包含所有标记点,确保能够显示所有标记点。 以上就是使用uni-app来在微信小程序中标记点的方法。通过引入uni-app提供的地图组件,结合相关的属性和数据即可实现地图的标记点功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值