uni微信小程序 map 添加padding

问题背景:

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

解决方法

  1. 给地图显示范围添加padding (推荐)
 <map
        id="myMap"
        :markers="markers"
        :polyline="polyline"
        :longitude="curLongitude"
        :latitude="curLatitude"
        @markertap="markertap"
        :include-points="includePoints"
 ></map>
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. 或者获取并修改缩放地图(记得设置中心点)
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的效果图:
在这里插入图片描述

*支付宝的兼容问题
// uni.createMapContext('myMap', this).includePoints() 在支付宝不太好用,视图不能缩放到指定范围
// 配置如下可以解决,但会影响微信小程序。需要用 "#ifdef MP-ALIPAY" 区分

  // #ifdef MP-ALIPAY
  includePoints.value = [
    { latitude: startCityLat.value, longitude: startCityLog.value },
    { latitude: endCityLat.value, longitude: endCityLog.value }
  ];
  // #endif
  
  • 11
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值