美文网首页
uni 地图回到缩放scale

uni 地图回到缩放scale

作者: litielongxx | 来源:发表于2021-12-24 16:01 被阅读0次

uni 小程序地图map缩放重置

uni小程序中,涉及地图一类,基本都会涉及定位(即准心一样icon)
功能为:从地图的其他区域,回到当前定位且一般缩放会重置。


image.png

如需要回到定位且重置缩放如下:

<map :scale="scale"></map>

methods:{
  resert() {
     this.mapCtx = wx.createMapContext('mymap')  
      //复位  
      this.mapCtx.moveToLocation()  
     // 重置缩放  
      this.mapCtx.getScale({  
        success:(res=>{  
          this.scale=res.scale  
          this.$nextTick(()=>{  
           this.scale=16  
          })  
         // setTimeout(()={...},0) 同理  
        }),  
      })  
  }
}

$nextTick和setTimeout(0)

视图更新以后再执行操作。
后者为事件队列在同步代码,即上一句(this.scale=re.scale)后执行。
猜测除去可能和渲染的时机有关。
参考:https://ask.dcloud.net.cn/question/101850

相关文章

网友评论

      本文标题:uni 地图回到缩放scale

      本文链接:https://www.haomeiwen.com/subject/aknlqrtx.html