uniapp 根据条件判断,绘制线段 map

 var itemArr = [{
      lat: "123",
      lng: "123",
      posTm: 1,
    }, {
      lat: "456",
      lng: "456",
      posTm: 2,
    }, {
      lat: "789",
      lng: "789",
      posTm: 5,
    }, {
      lat: "321",
      lng: "321",
      posTm: 8,
    }, {
      lat: "654",
      lng: "654",
      posTm: 10,
    }, {
      lat: "987",
      lng: "987",
      posTm: 8,
    }]
    let polyline = [];
    let _data = [];
    let ps = {
      points: _data,
      color: "#2B97FD",
      width: 5,
      arrowLine: true,
      dottedLine: false
    };
    polyline = polyline.concat(ps);
    for (var i = 0; i < itemArr.length; i++) {
      if (i != 0 && itemArr[i].posTm - itemArr[i - 1].posTm > 1) {//数组后一位减前一位的差大于1
        _data = [];
         ps = {
          points: _data,
          color: "#2B97FD",
          width: 5,
          arrowLine: true,
          dottedLine: false
        };
        polyline = polyline.concat(ps);
        _data.push({
          latitude: itemArr[i].lat,
          longitude: itemArr[i].lng,
        })
      } else {
        _data.push({
          latitude: itemArr[i].lat,
          longitude: itemArr[i].lng,
        })
      }
    }
    console.log(polyline)

打印结果
uniapp 根据条件判断,绘制线段 map_第1张图片

你可能感兴趣的:(前端,javascript,vue,js)