tencent cloud

文档反馈

最后更新时间:2024-03-04 23:01:18

    createMapContext

    该 API 使用方法为 wx.createMapContext(string mapId, Object this)
    功能说明:创建 map 上下文 MapContext 对象。
    参数及说明:string mapId,map 组件的 id;Object this,在自定义组件下,当前组件实例的 this,以操作组件内 map 组件
    返回值:MapContext

    MapContext

    注意:
    若无特殊说明,MapContext 的方法对手机厂商支持度默认为 系统地图(仅 iOS 支持):是;
    谷歌地图(Android、IDE 支持):是;
    华为地图(仅 Android 支持):是;
    腾讯地图:是;
    百度地图:是;
    高德地图:是。
    MapContext 实例,可通过 wx.createMapContext 获取。
    MapContext 通过 id 跟一个 <map> 组件绑定,操作对应的 <map> 组件。
    示例代码:
    <!-- map.wxml -->
    <map id="myMap" show-location />
    
    <button type="primary" bindtap="getCenterLocation">获取位置</button>
    <button type="primary" bindtap="moveToLocation">移动位置</button>
    <button type="primary" bindtap="translateMarker">移动标注</button>
    <button type="primary" bindtap="includePoints">缩放视野展示所有经纬度</button>
    // map.js
    Page({
    onReady: function (e) {
    // 使用 wx.createMapContext 获取 map 上下文
    this.mapCtx = wx.createMapContext('myMap')
    },
    getCenterLocation: function () {
    this.mapCtx.getCenterLocation({
    success: function(res){
    console.log(res.longitude)
    console.log(res.latitude)
    }
    })
    },
    moveToLocation: function () {
    this.mapCtx.moveToLocation()
    },
    translateMarker: function() {
    this.mapCtx.translateMarker({
    markerId: 0,
    autoRotate: true,
    duration: 1000,
    destination: {
    latitude:23.10229,
    longitude:113.3345211,
    },
    animationEnd() {
    console.log('animation end')
    }
    })
    },
    includePoints: function() {
    this.mapCtx.includePoints({
    padding: [10],
    points: [{
    latitude:23.10229,
    longitude:113.3345211,
    }, {
    latitude:23.00229,
    longitude:113.3345211,
    }]
    })
    }
    })

    .addArc

    该 方法 使用方式为 MapContext.addArc(Object object)
    功能说明:添加弧线,途经点与夹角必须设置一个。途经点必须在起终点有效坐标范围内,否则不能生成正确的弧线,同时设置夹角角度时,以夹角角度为准。夹角定义为起点到终点,与起点外切线逆时针旋转的角度。工具侧暂未支持。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    id
    number
    -
    圆弧 id
    start
    Object
    -
    起始点
    end
    Object
    -
    终点
    pass
    Object
    -
    途经点
    angle
    number
    0
    夹角角度
    width
    number
    5
    线宽
    color
    number
    #000000
    线的颜色
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)
    start 的结构属性
    结构属性
    类型
    默认值
    必填
    说明
    longitude
    number
    -
    经度
    latitude
    number
    -
    纬度
    end 结构属性
    结构属性
    类型
    默认值
    必填
    说明
    longitude
    number
    -
    经度
    latitude
    number
    -
    纬度
    pass 结构属性
    结构属性
    类型
    默认值
    必填
    说明
    longitude
    number
    -
    经度
    latitude
    number
    -
    纬度

    .addCustomLayer

    该 方法 使用方式为 MapContext.addCustomLayer(Object object)
    功能说明:添加个性化图层。图层创建参考文档
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    layerId
    string
    -
    个性化图层id
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)

    .addGroundOverlay

    该 方法 使用方式为 MapContext.addGroundOverlay(Object object)
    功能说明:创建自定义图片图层,图片会随着地图缩放而缩放。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    id
    String
    -
    图片图层 id
    src
    String
    -
    图片路径,支持网络图片、临时路径、代码包路径
    bounds
    Object
    -
    图片覆盖的经纬度范围
    visible
    Boolean
    true
    是否可见
    zIndex
    Number
    1
    图层绘制顺序
    opacity
    Number
    1
    图层透明度
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)
    bounds 的结构属性
    结构属性
    类型
    默认值
    必填
    说明
    southwest
    Object
    -
    西南角经纬度
    northeast
    Object
    -
    东北角经纬度
    southwest 结构属性
    结构属性
    类型
    默认值
    必填
    说明
    longitude
    number
    -
    经度
    latitude
    number
    -
    纬度
    northeast 结构属性
    结构属性
    类型
    默认值
    必填
    说明
    longitude
    number
    -
    经度
    latitude
    number
    -
    纬度

    .addMarkers

    该 方法 使用方式为 MapContext.addMarkers(Object object)
    功能说明:添加 marker。
    参数及说明:Object object。
    属性
    类型
    默认值
    必填
    说明
    markers
    array
    -
    同传入 map 组件的 marker 属性
    clear
    boolean
    false
    是否先清空地图上所有 marker
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)

    .eraseLines

    该 方法 使用方式为 MapContext.eraseLines(Object object)
    功能说明:擦除或置灰已添加到地图中的线段。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    lines
    Array.<Object>
    -
    要擦除的线段数组。详见 polyline 属性
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)
    lines 的结构属性
    结构属性
    类型
    默认值
    必填
    说明
    id
    number
    -
    线段的 id
    index
    number
    -
    指定线段的某一段,线段起点 index 为0
    point
    Object
    -
    指定线段某一段中的点
    clear
    boolean
    true
    为 true 是擦除,false 是置灰
    point 的结构属性
    结构属性
    类型
    默认值
    必填
    说明
    longitude
    number
    -
    经度
    latitude
    number
    -
    纬度

    .fromScreenLocation

    该 方法 使用方式为 MapContext.fromScreenLocation(Object object)
    功能说明:获取屏幕上的点对应的经纬度,坐标原点为地图左上角。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    x
    number
    -
    x 坐标值
    y
    number
    -
    y 坐标值
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)
    object.success 回调函数参数:Object res。
    属性
    类型
    说明
    latitude
    number
    纬度
    longitude
    number
    经度

    .getCenterLocation

    该 方法 使用方式为 MapContext.getCenterLocation(Object object)
    功能说明:获取当前地图中心的经纬度。返回的是 gcj02 坐标系,可以用于 wx.openLocation()
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    iconPath
    string
    -
    图标路径,支持网络路径、本地路径、代码包路径
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)
    object.success 回调函数参数:Object res
    属性
    类型
    说明
    longitude
    number
    经度
    latitude
    number
    纬度

    .getRegion

    该 方法 使用方式为 MapContext.getRegion(Object object)
    功能说明:获取当前地图的视野范围。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)
    object.success 回调函数参数:Object res
    属性
    类型
    说明
    southwest
    object
    西南角经纬度
    northeast
    object
    东北角经纬度
    southwest 结构属性
    结构属性
    类型
    说明
    longitude
    number
    经度
    latitude
    number
    纬度
    northeast 结构属性
    结构属性
    类型
    说明
    longitude
    number
    经度
    latitude
    number
    纬度

    .getRotate

    该 方法 使用方式为 MapContext.getRotate(Object object)
    功能说明:获取当前地图的旋转角。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)
    object.success 回调函数参数:Object res
    属性
    类型
    说明
    rotate
    number
    旋转角

    .getScale

    该 方法 使用方式为 MapContext.getScale(Object object)
    功能说明:获取当前地图的缩放级别。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)
    object.success 回调函数参数:Object res
    属性
    类型
    说明
    scale
    number
    缩放值

    .getSkew

    该 方法 使用方式为 MapContext.getSkew(Object object)
    功能说明:获取当前地图的倾斜角。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)
    object.success 回调函数参数:Object res
    属性
    类型
    说明
    skew
    number
    倾斜角

    .includePoints

    该 方法 使用方式为 MapContext.includePoints(Object object)
    功能说明:缩放视野展示所有经纬度。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    points
    array.
    -
    要显示在可视区域内的坐标点列表
    padding
    array.
    -
    坐标点形成的矩形边缘到地图边缘的距离,单位:像素。格式为[上,右,下,左],Android 上只能识别数组第一项,上下左右的 padding 一致。开发者工具暂不支持 padding 参数。
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)
    points 结构属性
    结构属性
    类型
    默认值
    必填
    说明
    longitude
    number
    -
    经度
    latitude
    number
    -
    纬度

    .initMarkerCluster

    该 方法 使用方式为 MapContext.initMarkerCluster(Object object)
    功能说明:初始化点聚合的配置,未调用时采用默认配置。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    enableDefaultStyle
    boolean
    true
    启用默认的聚合样式
    zoomOnClick
    boolean
    true
    点击已经聚合的标记点时是否实现聚合分离
    gridSize
    number
    60
    聚合算法的可聚合距离,即距离小于该值的点会聚合至一起,以像素为单位
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)

    .moveAlong

    该 方法 使用方式为 MapContext.moveAlong(Object object)
    功能说明:沿指定路径移动marker,用于轨迹回放等场景。动画完成时触发回调事件,若动画进行中,对同一 marker 再次调用 moveAlong 方法,前一次的动画将被打断。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    markerId
    number
    -
    指定 marker
    path
    array
    -
    移动路径的坐标串,坐标点格式 {longitude, latitude}
    autoRotate
    boolean
    true
    根据路径方向自动改变 marker 的旋转角度
    duration
    number
    -
    平滑移动的时间
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)

    .moveToLocation

    该 方法 使用方式为 MapContext.moveToLocation(Object object)
    功能说明:将地图中心移至当前定位点,此时需设置地图组件 show-location 为 true。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    longitude
    number
    -
    经度
    latitude
    number
    -
    纬度
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)

    .on

    该 方法 使用方式为 MapContext.on(string event, function callback)
    功能说明:监听地图事件。
    参数1:visualLayerEvent,可视化图层 visualLayer 统一回调出口,1.5.16 起支持。
    参数
    类型
    说明
    layerId
    String
    图层 id
    eventType
    String
    事件类型
    eventInfo
    String
    事件信息
    参数2:markerClusterCreate,缩放或拖动导致新的聚合簇产生时触发,仅返回新创建的聚合簇信息。
    参数
    类型
    说明
    clusters
    Array&lt;ClusterInfo&gt;
    聚合簇数据
    参数3:markerClusterClick,聚合簇的点击事件。
    参数
    类型
    说明
    cluster
    ClusterInfo
    聚合簇
    ClusterInfo 结构
    参数
    类型
    说明
    clusterId
    Number
    聚合簇的 id
    center
    LatLng
    聚合簇的坐标
    markerIds
    Array&lt;Number&gt;
    该聚合簇内的点标记数据数组
    参数4:string event,事件名;function callback,事件的回调函数。
    event 合法值有 markerClusterCreate、markerClusterClick、visualLayerEvent。
    示例代码
    MapContext.on('visualLayerEvent', (res) => {})
    MapContext.on('markerClusterCreate', (res) => {})
    MapContext.on('markerClusterClick', (res) => {})

    .openMapApp

    该 方法 使用方式为 MapContext.openMapApp(Object object)
    功能说明:拉起地图 App 选择导航。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    longitude
    number
    -
    目的地经度
    latitude
    number
    -
    目的地纬度
    destination
    string
    -
    目的地名称
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)

    .removeArc

    该 方法 使用方式为 MapContext.removeArc(Object object)
    功能说明:删除弧线。工具侧暂未支持。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    id
    number
    -
    圆弧 id
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)

    .removeCustomLayer

    该 方法 使用方式为 MapContext.removeCustomLayer(Object object)
    功能说明:移除个性化图层。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    layerId
    string
    -
    个性化图层id
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)

    .removeGroundOverlay

    该 方法 使用方式为 MapContext.removeGroundOverlay(Object object)
    功能说明:移除自定义图片图层。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    id
    String
    -
    图片图层 id
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)

    .removeMarkers

    该 方法 使用方式为 MapContext.removeMarkers(Object object)
    功能说明:移除 marker。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    markerIds
    array
    -
    marker 的 id 集合。
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)

    .setBoundary

    该 方法 使用方式为 MapContext.setBoundary(Object object)
    功能说明:限制地图的显示范围。此接口同时会限制地图的最小缩放整数级别。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    southwest
    Object
    -
    西南角经纬度
    northeast
    Object
    -
    东北角经纬度
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)
    southwest 结构属性
    结构属性
    类型
    默认值
    必填
    说明
    longitude
    number
    -
    经度
    latitude
    number
    -
    纬度
    northeast 结构属性
    结构属性
    类型
    默认值
    必填
    说明
    longitude
    number
    -
    经度
    latitude
    number
    -
    纬度

    .setCenterOffset

    该 方法 使用方式为 MapContext.setCenterOffset(Object object)
    功能说明:设置地图中心点偏移,向后向下为增长,屏幕比例范围(0.25~0.75),默认偏移为[0.5, 0.5]。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    offset
    Array.<number>
    -
    偏移量,两位数组
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)

    .setLocMarkerIcon

    该 方法 使用方式为 MapContext.setLocMarkerIcon(Object object)
    功能说明:设置定位点图标,支持网络路径、本地路径、代码包路径。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    iconPath
    string
    -
    图标路径,支持网络路径、本地路径、代码包路径
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)

    .toScreenLocation

    该 方法 使用方式为 MapContext.toScreenLocation(Object object)
    功能说明:获取经纬度对应的屏幕坐标,坐标原点为地图左上角。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    latitude
    Number
    -
    纬度
    longitude
    Number
    -
    经度
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)
    object.success 回调函数参数:Object res
    属性
    类型
    说明
    x
    number
    x 坐标值
    y
    number
    y 坐标值

    .translateMarker

    该 方法 使用方式为 MapContext.translateMarker(Object object)
    功能说明:平移 marker,iOS 以及 IDE 支持动画效果,Android 平台暂不支持。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    markerId
    number
    -
    指定 marker
    destination
    object
    -
    指定 marker 移动到的目标点
    animationEnd
    function
    -
    动画结束回调函数
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)
    destination 结构属性
    结构属性
    类型
    默认值
    必填
    说明
    longitude
    number
    -
    经度
    latitude
    number
    -
    纬度

    .updateGroundOverlay

    该 方法 使用方式为MapContext.updateGroundOverlay(Object object)
    功能说明:更新自定义图片图层。
    参数及说明:Object object
    属性
    类型
    默认值
    必填
    说明
    id
    String
    -
    图片图层 id
    src
    String
    -
    图片路径,支持网络图片、临时路径、代码包路径
    bounds
    Object
    -
    图片覆盖的经纬度范围
    visible
    Boolean
    true
    是否可见
    zIndex
    Number
    1
    图层绘制顺序
    opacity
    Number
    1
    图层透明度
    success
    function
    -
    接口调用成功的回调函数
    fail
    function
    -
    接口调用失败的回调函数
    complete
    function
    -
    接口调用结束的回调函数(调用成功、失败都会执行)
    bounds 的结构属性
    结构属性
    类型
    默认值
    必填
    说明
    southwest
    Object
    -
    西南角经纬度
    northeast
    Object
    -
    东北角经纬度
    southwest 结构属性
    结构属性
    类型
    默认值
    必填
    说明
    longitude
    number
    -
    经度
    latitude
    number
    -
    纬度
    northeast 结构属性
    结构属性
    类型
    默认值
    必填
    说明
    longitude
    number
    -
    经度
    latitude
    number
    -
    纬度
    
    
    联系我们

    联系我们,为您的业务提供专属服务。

    技术支持

    如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

    7x24 电话支持