缩放视野展示所有经纬度后获取当前地图的缩放级别有错误
发布于 5 年前 作者 jun40 9368 次浏览 来自 问答
  • 预期表现
  1. 初始设置地图的默认缩放级别,scale="{{scale}}",scale:13

  2. 点击一个POI类型,在地图上显示先关的经纬度坐标点,然后调用MapContext.includePoints(Object object)聚合所有坐标点在地图视野范围内

  3. MapContext.includePoints(Object object)调用成功后回调MapContext.getScale(Object object),获取聚合后的地图缩放级别

  4. 虽然坐标点聚合完成后地图缩放级别产生明显变化,但是MapContext.getScale(Object object)返回的缩放级别仍旧是初始值

  5. 所以导致在点击地图上加号和减号的时候,地图缩放未能显示预期效果

  • 提供一个最简复现 Demo
<map id='map' scale="{{scale}}" show-location bindmarkertap="bindmarkertap" markers="{{markers}}" bindcontroltap="bindcontroltap" longitude="{{longitude}}" latitude="{{latitude}}">
<cover-view bindtap='bindcontroltap' class='map-pos-box'>
<cover-image src='../../images/map-pos.png' mode="widthFix" class="map-pos"></cover-image>
</cover-view>
<cover-view class='scalePuls' bindtap='scalePuls'>+</cover-view>
<cover-view class='scaleMinus' bindtap='scaleMinus'>-</cover-view>
</map>
Page({
    data: {
        scale: 13
    },
....
})
//初始化地图控件
this.mapCtx = wx.createMapContext('map');
 
//聚合坐标点
this.mapCtx.includePoints({
    padding: [35, 35, 35, 35],
    points: markers,
    complete: function () {
        //获取聚合坐标点之后获取地图缩放级别
        that.mapCtx.getScale({
            success: function (res) {
                //返回仍旧是初始化的scale:13
                console.log(res.scale)
                that.setData({
                    scale: res.scale
                })
            }
        })
    }
})
1 回复

你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)

回到顶部