收藏
回答

bindregionchange调用后台接口数据动态修改markers死循环

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug map 客户端 7.0.3 2.3.0

- 当前 Bug 的表现(可附上截图)


- 预期表现


- 复现路径


- 提供一个最简复现 Demo


使用map组件,用bindregionchange视图改变去调用后台接口数据动态修改markers,出现重复调用死循环,期望效果是:视图改变动态修改markers不去再触发bindregionchange事件


onScaleRegion(e) {
    let etype = e.type;
    // 只捕捉移动后的点的信息
    if (etype === 'end') {
      // 获取可视区域的东北和西南的坐标
      this.getRegion()
    }
  }

getRegion() {
    let that = this
    this.mapCtx = wx.createMapContext('map')
    that.mapCtx.getRegion({
      success: function(res) {
        let northeast = app.request.qqMapTransBaiduMap(res.northeast.latitude, res.northeast.longitude)
        let southwest = app.request.qqMapTransBaiduMap(res.southwest.latitude, res.southwest.longitude)
        that.mapCtx.getScale({
          success: (scale) => {
            // 调用后台接口,更新markers
            that.getData(northeast, southwest, scale.scale)
          }
        })
      }
    })
  },
getData(northeast, southwest, scale) {
    let that = this
    let param = {
      beginLat: southwest.lat,
      beginLng: southwest.lng,
      endLat: northeast.lat,
      endLng: northeast.lng,
      level: that.getLevel(scale)
    }
    if (param.level === 'list') {
      param.lat = that.data.latitude
      param.lng = that.data.longitude
    }
    app.request.get('/xxx', param).then(data => {
      wx.showToast({
        title: 'test',
        mask: true
      })
      let arr = (data.records || []).map((item, index) => {
        let result = app.request.baiduMapTransQQMap(item.lat, item.lng)
        return {
          id: index,
          latitude: result.lat,
          longitude: result.lng,
          iconPath: '../../image/pos.png',
          width: 30,
          height: 30,
          callout: {
            content: item.storeName,
            padding: 5,
            borderRadius: 5,
            display:'BYCLICK',
            textAlign:'center',
            bgColor: '#FFFFFF'
          }
        }
      })
      that.setData({
        markers: arr
      })
    })
  },


最后一次编辑于  2019-02-28
回答关注问题邀请回答
收藏
登录 后发表内容