收藏
评论

小程序开发新能力解读 - 2022.02官方

快速知悉

  • 图片编辑接口 wx.editImage
  • map 组件新增能力

- 新增绘制圆弧

- 限制地图显示范围

- polyline 展示文字接口

- map 组件多边形支持设置虚线

  • camera 支持镜像模式和录像时长参数


1、图片编辑接口 wx.editImage(Object object)

使用介绍:配合 wx.chooseImage 选择图片,对图片进行编辑。

示例代码:

 wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success (res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        wx.editImage({
          src: tempFilePaths[0], // 演示本地路径,也支持代码包路径
          success(res){
            console.log("成功")
          }
        })
      }
    })



2、map 组件新增能力

2.1 新增绘制圆弧 MapContext.addArc(Object object)

使用介绍:弧线是由一组经纬度点和夹角角度绘制而成,在地图上绘制弧线由 Arc 类定义实现。

示例代码:

//增加圆弧 
  addArc() {
    const that = this
    wx.createSelectorQuery().select('#mapId').context(function(res){
      that.mapCtx = res.context// 节点对应的 Context 对象。
    }).exec()
      this.mapCtx.addArc({
        id: 0,
        start: {
          latitude: 23.099594,
          longitude: 203.328520,
        },//起点
        pass: {
          latitude: 53.090994,
          longitude: 153.324520,
        },//途径点
        end: {
          latitude: 83.080094,
          longitude: 213.321520,
        },//终点
        // angle: 30,
        width: 10,
        color: '#ff0000',
        complete(res) {
          console.log('addArc ', res)
        }
      })
    },
//删除圆弧
 removeArc() {
	const that = this
    wx.createSelectorQuery().select('#mapId').context(function(res){
      that.mapCtx = res.context// 节点对应的 Context 对象。
    }).exec()
     this.mapCtx.removeArc({
      id: 0,
      complete(res) {
        console.log('removeArc ', res)
      }
    })
  },


2.2 限制地图显示范围 MapContext.setBoundary(Object object)

使用介绍:限制地图的显示范围。此接口同时会限制地图的最小缩放整数级别。

示例代码:

setBoundary() {
 	 const that = this
     wx.createSelectorQuery().select('#mapId').context(function(res){
     that.mapCtx = res.context// 节点对应的 Context 对象。
    }).exec()
   this.mapCtx.setBoundary({
      southwest: {
        latitude: 39.744154,
        longitude: 116.124115
      },//西南角经纬度
      northeast: {
        latitude: 40.104336,
        longitude: 116.691284,
      },//东北角经纬度
      complete(res) {
        console.log('setBoundary ', res)
      }
    })
  },


2.3 polyline 展示文字接口

使用介绍:在折线线段上面绘制文字,可以用来显示路名。

示例代码:

textStyle:{
   textColor:'#00ff00',//文本颜色
   strokeColor:'#00ff00',//描边颜色
   fontSize:16//文本大小
 },
segmentTexts:[
 {
   name:"第1段",//名称
   startIndex:0,//起点
   endIndex:1,//终点
  },
  {
  name:"第2段",//名称
  startIndex:1,//起点
  endIndex:2,//终点
 }]

官方文档   

2.4 map 组件多边形支持设置虚线

使用介绍:[0, 0] 为实线,[10, 10] 表示十个像素的实线和十个像素的空白(如此反复)组成的虚线,默认为 [0, 0] 。

示例代码:

polygons: [{
      points: [{
        longitude: 118.082771,
        latitude: 24.494959
      }, {
        longitude: 118.117447,
        latitude: 24.486836
      },{
		longitude: 118.117447,
        latitude: 24.486836
	}
],
      dashArray:[5,5]//边线虚线(数组类型)


    }]

官方文档


3、camera 支持镜像模式和录像时长参数  selfieMirror / timeout

3.1镜像模式

使用介绍:拍摄照片或者录像,selfieMirror 设置为 true 时开启镜像。

示例代码:

startRecord() {//开始录像
	this.ctx = wx.createCameraContext()
    this.ctx.startRecord({
      selfieMirror:true,//开启镜像模式
      success: (res) => {
        console.log('startRecord')
      }
    })
  },
 takePhoto() {//拍摄照片
	this.ctx = wx.createCameraContext()
    this.ctx.takePhoto({
      quality: 'high',
	  selfieMirror:true,//开启镜像模式
      success: (res) => {
        this.setData({
          src: res.tempImagePath
        })
      }
    })
  },

  

3.2 录制时长参数

使用介绍:开始录像,timeout 是录制时长上限。

示例代码:

startRecord() {
	this.ctx = wx.createCameraContext()
    this.ctx.startRecord({
	timeout:30,//录制时长上限
      success: (res) => {
        console.log('startRecord')
      }
    })
最后一次编辑于  2022-03-02
赞 3
收藏

10 个评论

  • 王迪
    王迪
    2022-11-12

    你好,请问我使用了polyline的文字功能,但是实际没有效果,请问这里面还需要什么额外配置吗?比如版本之类的


    2022-11-12
    赞同 2
    回复
  • ¿仝?
    ¿仝?
    2022-02-28

    map组件 去年要是出来了 能省不少事呢!!!

    2022-02-28
    赞同 2
    回复
  • 陈式坚
    陈式坚
    2022-02-26

    图片接口这个合理而且很需要


    后续希望扩展更多能力,比如最常见的裁剪功能

    可以直接设定一个高宽比例,然后调起后直接进入裁剪界面进行操作

    这样觉得是解放太多场景

    2022-02-26
    赞同 2
    回复
  • 柠檬
    柠檬
    2022-03-05

    utf-8数据咋弄


    2022-03-05
    赞同 1
    回复
  • Shawn
    Shawn
    2023-01-13

    setBoundary在页面中可以使用,但是在组件中使用不生效,addGroundOverlay这个也是一样

    2023-01-13
    赞同
    回复
  • Frank
    Frank
    2022-06-04

    wx.editImage要是能再完善下,支持一些配置项,就太棒辣

    2022-06-04
    赞同
    回复
  • 青衣女倌
    青衣女倌
    2022-03-14

    已阅

    2022-03-14
    赞同
    回复
  • NULL
    NULL
    2022-03-01

    图片编辑接口不错

    2022-03-01
    赞同
    回复
  • 八九
    八九
    2022-03-01

    已阅

    2022-03-01
    赞同
    回复
  • 小张
    小张
    2022-02-25

    图片编辑接口不错

    2022-02-25
    赞同
    回复
登录 后发表内容

小程序开发新能力解读

课程标签