文档
wxml
<view class="map-container">
<map
id="map"
class="map"
longitude="{{longitude}}"
latitude="{{latitude}}"
scale="{{scale}}"
markers="{{markers}}"
polyline="{{polyline}}"
circles="{{circles}}"
controls="{{controls}}"
show-location="{{true}}"
enable-overlooking="{{true}}"
show-compass="{{true}}"
enable-rotate="{{true}}"
enable-traffic="{{true}}"
enable-building="{{true}}"
>
<view class="controls-btn">
<view class="btn">+</view>
<view class="btn">-</view>
</view>
</map>
</view>
wxss
.map {
width: 100vw;
height: 100vh;
position: relative;
}
.controls-btn {
position: absolute;
top: 0;
right: 0;
display: flex;
}
.btn {
padding: 10rpx;
font-size: 40rpx;
}
js
const app = getApp()
Page({
data: {
longitude: 108.971553,
latitude: 34.35888,
longitude1: 108.977103,
latitude1: 34.35948,
markers: [],
scale: 16,
polyline: [],
circles: [],
controls: [],
includePoints: [],
},
onLoad() {
const mapCtx = wx.createMapContext("map", this);
console.log(mapCtx);
const { latitude, longitude, latitude1, longitude1 } = this.data;
const markers = [{
id: "1",
latitude,
longitude,
width: 30,
height: 30,
joinCluster: true,
iconPath: 'https://img-crs.vchangyi.com//standard/order-map-user.png',
rotate: 15,
alpha: 0.5,
label: {
content: '标记点',
color: '#f00',
fontSize: 12,
borderRadius: 2,
padding: 4,
bgColor: 'transparent'
},
callout: {
content: '取货点',
color: '#666',
fontSize: 12,
borderRadius: 6,
padding: 8,
display: "ALWAYS"
}
},
{
id: "1",
latitude: latitude1,
longitude: longitude1,
width: 30,
height: 30,
joinCluster: true,
iconPath: 'https://img-crs.vchangyi.com/standard/order-driver-icon-1.png',
rotate: 15,
alpha: 0.5,
callout: {
content: '骑手',
color: '#666',
fontSize: 12,
borderRadius: 6,
padding: 8,
display: "ALWAYS"
}
}];
const polyline = [{
points: [{ latitude, longitude }, { latitude: latitude1, longitude: longitude1 }],
colorList: ['#f00'],
width: 1,
dottedLine: false,
arrowLine: false,
level: "abovelabels"
}];
const circles = [{
latitude,
longitude,
color: '#fff',
fillColor: '#7cb5ec88',
radius: 100,
strokeWidth: 1,
level: 'abovelabels'
}];
const controls = [{
id: 11,
iconPath: 'https://img-crs.vchangyi.com//standard/order-map-user.png',
position: {
left: 120,
top: 50,
width: 50,
height: 50
},
clickable: true
}];
mapCtx.includePoints({
points: [{ latitude, longitude }, { latitude: latitude1, longitude: longitude1 }],
padding: [100, 100, 100, 100],
success: function (e) {
console.log(e)
}
});
this.setData({
markers,
polyline,
circles,
controls
})
}
})
效果图