1***@163.com
1***@163.com
  • 发布:2022-04-13 13:03
  • 更新:2022-12-30 19:09
  • 阅读:798

includePoints(缩放视野展示所有经纬度)方法 控制台报Can not find `map1`

分类:nvue
map

在nvue页面调用includePoints(缩放视野展示所有经纬度)方法 控制台报Can not find map1

定位使用高德地图应用key

<template>  
  <div><map id="map1" style="width: 750rpx;height: 900rpx;" :polyline="polyline" :latitude="latitude" :longitude="longitude"></map></div>  
</template>  
<script>  
export default {  
  data() {  
    return {  
      polyline:[],  
      longitude: 118.27359771728516,  
      latitude: 33.930320739746094,  

      line: [  
        {  
          longitude: 118.27359771728516,  
          latitude: 33.930320739746094  
        },  
        {  
          longitude: 118.27359771728516,  
          latitude: 33.92970275878906  
        },  
        {  
          longitude: 118.27359771728516,  
         latitude: 33.92970275878906  
        },  
        {  
          longitude: 118.27833557128906,  
          latitude: 33.954166412353516  
        },  
        {  
          longitude: 118.27837371826172,  
          latitude: 33.954490661621094  
        },  
        {  
          longitude: 118.27876281738281,  
          latitude: 33.9583625793457  
        },  
        {  
          longitude: 118.27879333496094,  
          latitude: 33.958736419677734  
        },  
        {  
          longitude: 118.27880859375,  
          latitude: 33.95889663696289  
        }  
      ]  
    };  
  },  
  onLoad() {  
    this._mapContext = uni.createMapContext('map1', this);  
    this.init();  
  },  
  methods: {  
    init() {  
      console.log('--- 地图初始化 ---');  
      this._mapContext.includePoints({  
        points: this.line,  
        padding: [100, 200, 400, 200]  
      });  
      this.polyline = [  
        {  
          points: this.line,  
          color: '#19be6b',  
          width: 12,  
          arrowLine: true,  
          arrowIconPath: '/static/icon/icon_29.png',  
          borderWidth: 6, //线的边框宽度,还有很多参数,请看文档  
          borderColor: '#19be6b'  
        }  
      ];  
    }  
  }  
};  
</script>
2022-04-13 13:03 负责人:无 分享
已邀请:
DCloud_uni-ad_HDX

DCloud_uni-ad_HDX

onReady 中调用

  • 1***@163.com (作者)

    控制台不报错了,但是没有缩放视野展示所有经纬度

    2022-04-15 13:16

  • 6***@qq.com

    怎么样了?

    2022-09-08 17:24

  • QCW

    我是在onReady 创建的mapContext对象 后端数据也是在这请求的,然后也出现上面的问题

    2023-02-01 08:22

7***@qq.com

7***@qq.com

按官方文档写是不生效的 得按官方的例子写
map :include-points="includePoints"></map
this.includePoints = [{latitude, longitude}]
这样缩放后 那些点将将被四周遮挡 padding又不生效

要回复问题请先登录注册