uniapp applet map setting map zoom failure solution

The reason is that the zoom level bound to the uniapp map does not update the value after zooming with the mouse or finger. If the zoom level needs to be modified, the map will not be updated because the set value has not changed.

<map class="my_map" id="myMap"  :scale="mapScale"></map>

......
data() {
    
    
	return {
    
    
		mapScale: 16,
	}
}		

The solution is to call the map query zoom level method before setting, reset the update zoom level and then set the required zoom level to zoom

// 一开始创建的地图对象

onReady() {
    
    
	this.mapCtx = uni.createMapContext("myMap")
},

//设置地图缩放等级
setScale(level){
    
    
	this.mapCtx.getScale({
    
    
		success: res=>{
    
    		
			console.log("缩放",res)
			this.mapScale = res.scale;
			this.$nextTick(()=>{
    
    
				this.mapScale = level
			})
		}
	})
},

おすすめ

転載: blog.csdn.net/weixin_38566069/article/details/130523943