效果图: (气泡可随意定义样式)
页面内容: (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中)文章来源:https://www.toymoban.com/news/detail-542491.html
//获取到的充电站展示到地图中
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内容:文章来源地址https://www.toymoban.com/news/detail-542491.html
.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;
}
到了这里,关于uniapp 小程序 地图<map> 渲染标注点 且自定义气泡内容(slot写到页面中/样式自定义)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!