uniapp 小程序 地图<map> 渲染标注点 且自定义气泡内容(slot写到页面中/样式自定义)

效果图: (气泡可随意定义样式)

页面内容:  (slot为自定义标注气泡)

<map :style="mapStyle" show-location="true" :latitude="latitude" id="map" :longitude="longitude":markers="markers">
	<cover-view slot="callout">
		<block v-for="(item,index) in markers" :key="index">
			<cover-view class="customCallout" :marker-id="item.id">
				<cover-view class="content">
					{{item.id}} 内容
				</cover-view>
			</cover-view>
		</block>
	</cover-view>
</map>

获取经纬度方法:

//获取经纬度
getLication: function() {
	var that = this;
	uni.getLocation({
		type: 'gcj02',
		success: function(res) {
			// console.log('当前位置的经度:' + res.longitude);
			// console.log('当前位置的纬度:' + res.latitude);
			that.longitude = res.longitude;
			that.latitude = res.latitude;
		},
		fail(err) {
			console.log(err);
		}
	});
},

数据整理方法: (整理各坐标点经纬度和信息到maekers中)

//获取到的充电站展示到地图中
filterMapMarkers: function() {
	var list = this.changingStationList;
	console.log("充电站list", list)
	var markers = [];
	for (let i = 0; i < list.length; i++) {
		let markersItem = {
			id: i,
			latitude: list[i].location[0],
			longitude: list[i].location[1],
			iconPath: '/static/image/icon/icon-map-location.png',
			width: '35rpx',
			height: '46rpx',
			customCallout: {
			anchorY: 0, // Y轴偏移量
			anchorX: 0, // X轴偏移量
			display: 'ALWAYS' ,// 一直展示
			
			},
		}
		markers.push(markersItem);
	}
	this.markers = markers;
},

css内容:

.customCallout {
	box-sizing: border-box;
	background-color: #fff;
	background: #FFFFFF;
	box-shadow: 0px 4rpx 16px 0px rgba(189, 191, 193, 0.4);
	border-radius: 4rpx;
	display: inline-flex;
	padding: 6rpx 24rpx;
	justify-content: center;
	align-items: center;
	color: #2A7BE2;
}
  • 4
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值