开发
API
直播能力

MapContext.includePoints

基础库 1.63.0 开始支持本方法。

缩放视野展示所有经纬度。

语法

MapContext.includePoints(options)

参数说明

options 为 object 类型,属性如下:

属性名类型默认值必填说明最低支持版本
pointsarray要显示在可视区域内的坐标点列表,point 详见下表1.63.0
successfunction接口调用成功的回调函数1.63.0
failfunction接口调用失败的回调函数1.63.0
completefunction接口调用结束的回调函数1.63.0

point

属性名类型默认值必填说明最低支持版本
longitudenumber经度1.63.0
latitudenumber经度1.63.0

回调成功

object 类型,属性如下:

属性类型说明最低支持版本
errMsgstring"includePoints:ok"1.63.0

回调失败

object 类型,属性如下:

属性类型说明最低支持版本
errMsgstring"includePoints:fail " + 错误信息1.63.0

代码示例

<map
  id="myMap"
  show-location
  longitude="{{longitude}}"
  latitude="{{latitude}}"
  markers="{{markers}}"
  style="width:100%; height: 300px;"
></map>
<button type="primary" size="default" bindtap="includepoints">
  includepoints
</button>
Page({
  data: {
    show: false,
    latitude: 23.099994,
    longitude: 113.32452,
    showLocation: true,
    scale: 10,
    markers: [
      {
        id: 1,
        latitude: 23.099994,
        longitude: 113.32452,
        iconPath: "",
        title: "marker 1",
      },
      {
        id: 2,
        latitude: 24.099994,
        longitude: 113.32452,
        iconPath: "",
        title: "marker 2",
      },
      {
        id: 3,
        latitude: 30.199994,
        longitude: 115.32452,
        iconPath: "",
        title: "marker 3",
      },
      {
        id: 4,
        latitude: 34.199994,
        longitude: 90.32452,
        iconPath: "",
        title: "marker 4",
      },
      {
        id: 5,
        latitude: 36.199994,
        longitude: 85.32452,
        iconPath: "",
        title: "marker 5",
      },
      {
        id: 6,
        latitude: 22.199994,
        longitude: 80.32452,
        iconPath: "",
        title: "marker 6",
      },
      {
        id: 7,
        latitude: 34.199994,
        longitude: 90.32452,
        iconPath: "",
        title: "marker 7",
      },
    ],
  },
  onReady: function (e) {
    this.mapCtx = tt.createMapContext("myMap");
  },
  includepoints() {
    this.mapCtx.includePoints({
      points: this.data.markers,
      success: (res) => {
        tt.showToast({
          title: "移动成功", // 内容
        });
      },
      fail: (error) => {
        tt.showModal({
          content: error.errMsg,
        });
      },
      complete(res) {
        console.log(res);
      },
    });
  },
});

Bug & Tip

点击纠错
评价此篇文档