uni微信小程序 map 添加padding

问题背景:

规划驾车线路的时候,使用uni的include-points指定可视范围的时候,会很极限。导致marker不能完全显示。

解决方法

  1. 给地图显示范围添加padding (推荐)
html 复制代码
 <map
        id="myMap"
        :markers="markers"
        :polyline="polyline"
        :longitude="curLongitude"
        :latitude="curLatitude"
        @markertap="markertap"
 ></map>
javascript 复制代码
onLoad((e) => {
 uni.createMapContext('myMap', this).includePoints({
      padding: [120, 110, 120, 110],
      points: [
        { latitude: startCityLat.value, longitude: startCityLog.value },
        { latitude: endCityLat.value, longitude: endCityLog.value }
      ]
    });
});
  1. 或者获取并修改缩放地图(记得设置中心点)
javascript 复制代码
const appMapRef = ref('');
appMapRef.value = uni.createMapContext('myMap');
appMapRef.value.getScale({
    success: (res) => {
      console.log('缩放', res);
      mapScale.value = res.scale - 1;
      console.log('mapScale.value', mapScale.value);
    }
  });

uni文档:点击这里

1的效果图:

相关推荐
我命由我123457 小时前
微信小程序 - 条件渲染(wx:if、hidden)与列表渲染(wx:for)
javascript·微信小程序·小程序·typescript·html·html5·js
有梦想的8 小时前
短剧小程序系统源码
小程序
我命由我123459 小时前
微信小程序 - 页面跳转(wx.navigateTo、wx.redirectTo、wx.switchTab、wx.reLaunch)
前端·微信小程序·小程序·前端框架·html·html5·js
小咕聊编程10 小时前
【含文档+PPT+源码】基于微信小程序的健康饮食食谱推荐平台的设计与实现
微信小程序·小程序
澄江静如练_12 小时前
小程序高度问题&背景scss
java·前端·小程序
Xiaohong071612 小时前
心理咨询小程序的未来发展
java·微信小程序·小程序·心理咨询小程序·微信小程序搭建开发
邹飞鸣15 小时前
若依前后端分离框架修改3.8.9版本(重点在安全框架讲解与微信小程序登录集成)
安全·微信小程序·小程序
前端南玖16 小时前
小程序如何实现跨页面通信
javascript·小程序·taro
编织幻境的妖17 小时前
python的Tkinter小程序上传Excel并下载Text
python·小程序·excel
计算机毕设指导618 小时前
基于Springboot医院预约挂号小程序系统【附源码】
java·spring boot·后端·spring·小程序·apache·intellij-idea