图1:我想要的效果
图2:开发工具测试效果【正常】
图3:手机端预览效果【不正常】
问题描述:小程序端进入地图一瞬间显示正常,随即就自动放大了。导致3个点位无法显示在视野内。
代码:wxml部分
<view>
<map id="myMap" latitude="{{latitude}}"
style="width:100%; height: 400px;"
longitude="{{longitude}}"
markers="{{markers}}"
bindmarkertap="selectMarket"
include-points="{{markers}}"
subkey="XXX"
enable-satellite
scale="{{scale}}"
rotate="90"
>map>
view>
代码:js部分
var app = getApp();
Page({
data: {
latitude: 34.197742, // latitude 纬度
longitude: 108.883811, // longitude 经度
scale: 12,
markers:
[
{
id: 0,
latitude: 34.197742,
longitude: 108.883811,
name: '站点1',
iconPath: '../../images/location.png',
callout: {
content: "继保室 地址:xxx",
padding: 10,
display: 'BYCLICK',
textAlign: 'center',
borderRadius: 3,
borderWidth: 1,
fontSize:12,
}
},
{
id: 1,
latitude: 34.193183,
longitude: 108.885395,
name: '站点2',
callout: {
content: "继变电 地址:xxx",
padding: 10,
display: 'BYCLICK',
textAlign: 'center',
borderRadius: 3,
borderWidth: 1,
fontSize:12,
}
},
{
id: 2,
latitude: 34.192931,
longitude: 108.877964,
name: '站点3',
callout: {
content: "站点a 地址:xxx",
padding: 10,
display: 'BYCLICK',
textAlign: 'center',
borderRadius: 3,
borderWidth: 1,
fontSize:12,
}
},
]
},
selectMarket: function (e) {
console.log(e)
var id = e.markerId
console.log(id)
wx.openLocation({
latitude: this.data.markers[id].latitude,
longitude: this.data.markers[id].longitude,
name: this.data.markers[id].name,
})
},
onLoad: function (options) {
},
});
我想实现的效果,不管增加多少标记点,始终会显示在视野内。
that.mapCtx = wx.createMapContext('mapDom'); //创建初始地图 let includePointsData = [] for (let i = 0; i < locationsData.length; i++) { includePointsData.push({ latitude: locationsData[i].lat, longitude:locationsData[i].lng }) } // 显示所有标记点 that.mapCtx.includePoints({ padding: [100, 80, 100, 80], points: includePointsData //放入所有坐标轴的数组 并引用此方法 })
谢邀