收藏
回答

polyline为什么数据写死可以显示,但是使用setData赋值就不显示?




Marker = [];
//引用腾讯地图微信小程序JSAPI模块
let QQMapWX = require('../../pages/libs/qqmap-wx-jssdk.min.js');
//用于保存BMap.search接口返回的数据
var wxMarkerData = [];
var arr = [];
Page({
  /**
   * 页面的初始数据
   *         { latitude: "31.79453053831718", longitude: "120.02379165275012"},
        { latitude: "31.792017041269684", longitude: "120.02106965196045"},
        { latitude: "31.804600509310646", longitude: "120.0229725240544"}
 
   *
   */
   
  data: {
    date: '2019-08-13',
    height: 'auto',
    markers: [],
    latitude: '',
    longitude: '',
    centerX: "",
    centerY: "",
    text: '',
    timer: "",
    plain: true,
    polyline: [{
      points: [],
      color: "#FF0000DD",
      width: 5,
      dottedLine: false
    }],
    points: [],
    pointsInfo: [],
    playIndex: 0,
    flag: false,
    speed: 500,
    flag: false,
    enableSatellite: false,
    startTime: '08 : 40',
    endTime: '08 : 50'
  },
 
  btnclick: function(e) {
    var that = this;
    wx.getLocation({
      success: function(res) {
        console.log(res)
      },
    })
  },
  // 点击时间跳转到添加时段页面
  timeTrack: function(e) {
    console.log(e)
    wx.navigateTo({
      url: '../pickTime/pickTime',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  regionchange(e) {
    //console.log(e.type)
  },
  markertap(e) {
    //console.log(e.markerId)
  },
  controltap(e) {
    //console.log(e.controlId)
  },
  onReady: function() {
    //使用wx.createMapContext获取 map上下文
    let that = this;
    this.mapCtx = wx.createMapContext('myMap');
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // 保证wx.getSystemInfo的回调函数中能够使用this
    var that = this;
    let qqMap = new QQMapWX({
      key: "'"
    })
    //调用wx.getSystemInfo接口,然后动态绑定组件高度
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          height: res.windowHeight
        })
      },
    });
    wx.request({
      url: 'http:',
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }, // 默认值
      data: {
        startTime: '2019-07-08 19:10:00',
        endTime: '2019-07-08 19:11:00',
      },
      success: function(res) {
        //清洗数据
 
        console.log(res);
        for (let i = 0; i < res.data.data.length; i++) {
          let obj = {};
          obj.latitude = res.data.data[i].lat;
          obj.longitude = res.data.data[i].lon;
          that.data.points.push(obj);
        }
        // console.log(that.data.points);
        that.setData({
          // swiper: json,
          markers: [{
            iconPath: "/images/car.png",
            id: 0,
            callout: {
              content: "测试\n 时间:11:20 \n速度:180km/h",
              fontSize: '32',
              padding: true,
              color: '#444',
              display: 'ALWAYS',
              textAlign: 'center',
              borderRadius: 15
            },
            latitude: that.data.points[that.data.points.length - 1].latitude,
            longitude: that.data.points[that.data.points.length - 1].longitude,
            width: 30,
            height: 30
          }],
          polyline: [{
            // pointsInfo: "测试",
            points: that.data.points,
            color: "red",
            width: 10,
            dottedLine: true
          }],
          latitude: that.data.points[that.data.points.length - 1].latitude,
          longitude: that.data.points[that.data.points.length - 1].longitude,
        });
        // console.log(that.data.polyline)
      },
      fail: function(res) {
        console.log("获取数据失败")
        console.log(res)
      }
    });
  },
  getmarkers: function(markerArr) {
    let arr = [];
    for (let i = 0; i < markerArr.length; i++) {
      let location = this.createMarkert(markerArr[i]);
      arr.push(location);
    }
    return arr
  },
  /**
   * 构造可使用数据
   */
  createMarkert: function(marker) {
    var lat = marker.lat;
    var lon = marker.lon;
    var point = {
      iconPath: "../../images/marker_red.png",
      id: marker.sn || 0,
      callout: {
        content: marker.title,
        fontSize: '32',
        padding: true,
        color: '#444',
        display: 'ALWAYS',
        textAlign: 'center',
        borderRadius: 15
      },
      latitude: lat,
      longitude: lon,
      width: 15,
      height: 15
    }
    return point;

  },

})


回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容
问题标签