tanghaolin
2022-07-27 fd4d1d9296ba620de15b47bd1d58383d46ecb626
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// text/mapTrajectory.js
Page({
  data: {
    curPosiInfo: null, //位置信息 // latitude: 0, longitude: 0,//经纬度
    markers: null,
    polyline: [{
      points: [
        { id: 0, latitude: 31.11325, longitude: 121.38206 },
        { id: 1, latitude: 31.11305, longitude: 121.38186 },
        { id: 2, latitude: 31.11285, longitude: 121.38206 },
        { id: 3, latitude: 31.11265, longitude: 121.38186 },
        { id: 4, latitude: 31.11255, longitude: 121.38206 },
        { id: 5, latitude: 31.11245, longitude: 121.38186 },
        { id: 6, latitude: 31.11225, longitude: 121.38206 },
        { id: 7, latitude: 31.11205, longitude: 121.38186 }
      ],
      color: '#F11D36',
      width: 2,
      dottedLine: false
    }]
  },
  onLoad: function (options) {
    var title = options.name;
    //console.log(options)//
    if(title!="" || title!=undefined){
      wx.setNavigationBarTitle({
        title: title + '巡检记录',
      });
    }
  },
  onShow: function () {
    var that=this;
    that.getlocation();
    that.setUpIcon();
  },
  getlocation: function () {
    var that=this;
    wx.getLocation({
      type: 'gcj02',
      success: function (res) {
        that.setData({
          curPosiInfo:res
        })
      },
      fail:function(res){console.log(res)}
    });
  },
 
  setUpIcon:function(){
    var that = this;
    var getlocation = that.data.polyline[0].points;//获取轨迹坐标
    var startlocation = getlocation[0];//获取轨迹起点坐标
    var endlocation = getlocation[getlocation.length - 1];//获取轨迹终点坐标
    var markers = [];
    for (var i = 0; i <getlocation.length;i++){
      if (i != 0 && i != 7 && ((i+1) % 3)==0){//去掉第一条和最后一条 轨迹分
        var center = {};
        center.id = getlocation[i].id;
        center.latitude = getlocation[i].latitude;
        center.longitude = getlocation[i].longitude;
        center.iconPath = "/images/icons/center.png"
        markers.push(center);
      }
    }
    console.log('打印被3整除的点:',markers)
 
    /**设置起点终点图标 */
    //起点
    var start = {};
    start.id = startlocation.id;
    start.latitude = startlocation.latitude;
    start.longitude = startlocation.longitude;
    start.iconPath = "/images/icons/start.png"
    markers.push(start);
 
    //终点
    var end = {};
    end.id = endlocation.id;
    end.latitude = endlocation.latitude;
    end.longitude = endlocation.longitude;
    end.iconPath = "/images/icons/end.png"
    markers.push(end);
 
    
 
    console.log(getlocation, startlocation, endlocation)
    console.log(start, end, markers)
    that.setData({
      markers: markers
    })
  },
 
  onShareAppMessage: function () {}
})