Blame view

HDFwear/Motion/EndMotionVC.swift 24.1 KB
f2cf74c7   yangbin   1.0.20(4)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
  //
  //  EndMotionVC.swift
  //  Twear
  //
  //  Created by yangbin on 2022/1/2.
  //
  
  import UIKit
  import Charts
  //import HCKalmanFilter
  
  class EndMotionVC: UIViewController {
  
      
      private lazy var mapView: MAMapView = MAMapView()
      @IBOutlet weak var distanceLabel: UILabel!
      
      @IBOutlet weak var stepChartView: LineChartView!
      @IBOutlet weak var altitudeChartView: LineChartView!
      
      @IBOutlet weak var maxSpeedLabel: UILabel!
      @IBOutlet weak var minSpeedLabel: UILabel!
      @IBOutlet weak var timeLabel: UILabel!
      @IBOutlet weak var calorieLabel: UILabel!
      @IBOutlet weak var scrollView: UIScrollView!
      @IBOutlet weak var dateLabel: UILabel!
      @IBOutlet weak var stepsLabel: UILabel!
      @IBOutlet weak var stepCadenceLabel: UILabel!
      @IBOutlet weak var stepStrideLabel: UILabel!
      @IBOutlet weak var altitudeLabel: UILabel!
      @IBOutlet weak var altitudeLabel1: UILabel!
      @IBOutlet weak var minAltitudeLabel: UILabel!
      @IBOutlet weak var maxAltitudeLabel: UILabel!
      
      @IBOutlet weak var totalStepLabel: UILabel!
      @IBOutlet weak var averageStepLabel: UILabel!
      @IBOutlet weak var maxStepLabel: UILabel!
      @IBOutlet weak var averageSpeedLabel: UILabel!
      @IBOutlet weak var averagePaceLabel: UILabel!
      @IBOutlet weak var avatarImageView: UIImageView!
      @IBOutlet weak var motionTypeLabel: UILabel!
      @IBOutlet weak var mapBackView: UIView!
      
      @IBOutlet weak var unitLabel: UILabel!
      @IBOutlet weak var altiUnitLabel: UILabel!
      @IBOutlet weak var detailView: UIView!
      @IBOutlet weak var altitudeView: UIView!
      @IBOutlet weak var stepView: UIView!
      
      @IBOutlet weak var detailBottomLayout: NSLayoutConstraint!
      @IBOutlet weak var detailHeightLayout: NSLayoutConstraint!
      @IBOutlet weak var topLayout: NSLayoutConstraint!
      
      @IBOutlet weak var detailLabel1: UILabel!
      @IBOutlet weak var detailLabel2: UILabel!
      @IBOutlet weak var detailLabel3: UILabel!
      @IBOutlet weak var detailLabel4: UILabel!
      @IBOutlet weak var detailLabel5: UILabel!
      @IBOutlet weak var detailLabel6: UILabel!
      @IBOutlet weak var detailLabel7: UILabel!
      @IBOutlet weak var detailLabel8: UILabel!
  //    var hcKalmanFilter: HCKalmanAlgorithm?
      var date: Date!
      var distance: Float!
      var length: Int!
      var calorie: Float!
      var altitude: Double = 0
      var motionType: TrainType = .running
      var coordinateArray: [CLLocationCoordinate2D] = []
      var speedArray: [Float] = []
      var stepCadenceArray: [Int] = []
      var altitudeArray: [Double] = []
      
      let user = UserInfo
      
      var isRecordPresent: Bool = false
      
      override func viewDidAppear(_ animated: Bool) {
          super.viewDidAppear(animated)
          let polyline = MAPolyline(coordinates: &self.coordinateArray, count: UInt(self.coordinateArray.count))
          let padding = UIEdgeInsets(top: 5, left: 5, bottom: 300, right: 5)
          mapView.setVisibleMapRect(polyline!.boundingMapRect, edgePadding: padding, animated: true)
      }
      
      override func viewDidLoad() {
          super.viewDidLoad()
          initMapView()
          topLayout.constant = SCREEN_HEIGHT-272
          
          timeLabel.toTimeType3(length: length)
          calorieLabel.text = String(format:"%.2f", calorie) + LocString("千卡")
          
          dateLabel.text = date.toString(.custom("yyyy.MM.dd HH:mm"))
          let step = distanceToStep(distance)
          stepsLabel.text = "\(step)\(LocString("步"))"
          stepCadenceLabel.text = "\(Int(step*60/length))\(LocString("步/分钟"))"
          totalStepLabel.text = "\(step)"
          maxStepLabel.text = "\(stepCadenceArray.max() ?? 0)"
          averageStepLabel.text = "\(Int(step*60/length))"
          
          detailLabel1.text = LocString("步频(步/分钟)")
          detailLabel2.text = LocString("总步数")
          detailLabel3.text = LocString("最大步频")
          detailLabel4.text = LocString("平均步频")
          detailLabel5.text = LocString("累计爬升")
          detailLabel6.text = LocString("最高海拔")
          detailLabel7.text = LocString("最低海拔")
          detailLabel8.text = LocString("累计爬山")
          
          if user.distanceUnit == 0 {
              unitLabel.text = LocString("公里")
              distanceLabel.text = String(format:"%.2f", distance/1000)
              if let maxSpeed = speedArray.max() {
                  maxSpeedLabel.text = "\(String(format:"%02d", Int(maxSpeed)/60))\(String(format:"%02d", Int(maxSpeed)%60))″"
              }
              if let minSpeed = speedArray.max() {
                  maxSpeedLabel.text = "\(String(format:"%02d", Int(minSpeed)/60))\(String(format:"%02d", Int(minSpeed)%60))″"
              }
               let avgPace = speedArray.average()
                  averagePaceLabel.text = "\(String(format:"%02d", Int(avgPace)/60))\(String(format:"%02d", Int(avgPace)%60))″/\(LocString("公里"))"
              
              averageSpeedLabel.text = "\(String(format:"%.2f", distance/1000/(Float(length)/3600)))\(LocString("公里/小时"))"
              
              
              if step > 0 {
                  stepStrideLabel.text = "\(Int(distance)*100/step)\(LocString("厘米"))"
              }
              
              altitudeLabel.text = String(format:"%.2f", altitude) + LocString("米")
              altitudeLabel1.text = String(format:"%.2f", altitude)
              minAltitudeLabel.text =  String(format:"%.2f", altitudeArray.min() ?? 0)
              maxAltitudeLabel.text =  String(format:"%.2f", altitudeArray.max() ?? 0)
              altiUnitLabel.text = LocString("海拔(米)")
          } else {
              unitLabel.text = LocString("英里")
              distanceLabel.text = (distance/1000).mileString()
              if let maxSpeed = speedArray.max() {
                  maxSpeedLabel.text = "\(String(format:"%02d", Int(maxSpeed/0.6213)/60))\(String(format:"%02d", Int(maxSpeed/0.6213)%60))″"
              }
              if let minSpeed = speedArray.max() {
                  maxSpeedLabel.text = "\(String(format:"%02d", Int(minSpeed/0.6213)/60))\(String(format:"%02d", Int(minSpeed/0.6213)%60))″"
              }
               let avgPace = speedArray.average()
                  averagePaceLabel.text = "\(String(format:"%02d", Int(avgPace/0.6213)/60))\(String(format:"%02d", Int(avgPace/0.6213)%60))″/\(LocString("英里"))"
              
              averageSpeedLabel.text = "\(String(format:"%.2f", distance/1000*0.6213/(Float(length)/60)))\(LocString("英里/小时"))"
              
              
              if step > 0 {
                  stepStrideLabel.text = "\(Int(distance*0.3937)*100/step)\(LocString("英寸"))"
              }
              
              altitudeLabel.text = String(format:"%.2f", altitude*3.281) + LocString("英尺")
              altitudeLabel1.text = String(format:"%.2f", altitude*3.281)
              minAltitudeLabel.text =  String(format:"%.2f", (altitudeArray.min() ?? 0) * 3.281)
              maxAltitudeLabel.text =  String(format:"%.2f", (altitudeArray.max() ?? 0) * 3.281)
              altiUnitLabel.text = LocString("海拔(英尺)")
          }
    
          
          
          if let image = UIImage.getImageFromPath("avatar") {
              avatarImageView.image = image
          } else {
              avatarImageView.image = UIImage(named: UserInfo.gender == 1 ? "avatar_male" : "avatar_female")
          }
          var motionTypeText = "户外跑步"
          switch motionType {
          case .run_indoor:
              motionTypeText = "室内跑步"
          case .walking:
              motionTypeText = "步行"
          case .bicycle:
              motionTypeText = "骑行"
          case .mountaineering:
              motionTypeText = "爬山"
          default:
              break
          }
          
          motionTypeLabel.text = LocString(motionTypeText)
          
          
          if motionType == .mountaineering {
              detailHeightLayout.constant = 350.5
              detailBottomLayout.constant = 690
              altitudeView.isHidden = false
          } else {
              if motionType == .bicycle {
                  detailHeightLayout.constant = 220.5
                  topLayout.constant = SCREEN_HEIGHT-222
                  detailBottomLayout.constant = 0
                  stepView.isHidden = true
              } else {
                  detailHeightLayout.constant = 318
                  detailBottomLayout.constant = 350
                  stepView.isHidden = false
              }
              altitudeView.isHidden = true
          }
          
          scrollView.delegate = self
          
          setupStepChartView()
          setupAltitudeChartView()
          // Do any additional setup after loading the view.
      }
      
      func initMapView() {
  //        MAMapView.updatePrivacyShow(.didShow, privacyInfo: .didContain)
  //        MAMapView.updatePrivacyAgree(.didAgree)
          
          mapView.showsUserLocation = false
  //        mapView.userTrackingMode = .follow
          mapView.showsCompass = false
          mapView.zoomLevel = 16
          mapView.mapLanguage = (AppSettings.shared.language == .Chinese) ? 0 : 1
          mapView.delegate =                                                                                                                                                                                                          self
  
  //        let tool = MASmoothPathTool()
  //        tool.intensity = 3
  //        tool.threshHold = 0.3
  //        tool.noiseThreshhold = 10
  //
  //        self.smoothedTracePoints = tool.pathOptimize(self.origTracePoints)
          
  //        if hcKalmanFilter == nil {
  //        var coorArray: [CLLocationCoordinate2D] = []
  //
  //        let location = CLLocation.init(latitude: coordinateArray.first!.latitude, longitude: coordinateArray.first!.longitude)
  //        self.hcKalmanFilter = HCKalmanAlgorithm(initialLocation: location)
  //        hcKalmanFilter?.rValue = 40
  //        hcKalmanFilter?.resetKalman(newStartLocation: location)
  //        coorArray.append(location.coordinate)
  //        for (i, coor) in coordinateArray.enumerated() {
  //            if i != 0 {
  //                let loc = CLLocation.init(latitude: coor.latitude, longitude: coor.longitude)
  //                let kalmanLocation = hcKalmanFilter?.processState(currentLocation: loc)
  //                print("\(loc.coordinate)--\(kalmanLocation!.coordinate)")
  //                coorArray.append(kalmanLocation!.coordinate)
  //                sleep(2)
  //            }
  //        }
  //        print("完成!")
  //        } else {
  //            let kalmanLocation = hcKalmanFilter?.processState(currentLocation: location)
  ////            print("\(kalmanLocation?.coordinate) ---  \(location.coordinate)")
  //            self.coordinateArray.append(kalmanLocation!.coordinate)
  //            self.locationArray.append(kalmanLocation!)
  //        }
          
  //        coordinateArray = coorArray
          let polyline = MAPolyline(coordinates: &coordinateArray, count: UInt(coordinateArray.count))
          if motionType != .run_indoor {
              mapView.add(polyline)
              setPointAnnotation()
          }
          
  
          
          let padding = UIEdgeInsets(top: 5, left: 5, bottom: 25, right: 5)
          mapView.setVisibleMapRect(polyline!.boundingMapRect, edgePadding: padding, animated: true)
          
          mapView.frame = mapBackView.bounds
          mapBackView.addSubview(mapView)
          mapBackView.sendSubviewToBack(mapView)
    
      }
      
      func setPointAnnotation() {
          if coordinateArray.count > 1 {
              let startPoint = MAPointAnnotation()
              startPoint.coordinate = coordinateArray.first!
              startPoint.title = "起点"
              mapView.addAnnotation(startPoint)
              
              let stopPoint = MAPointAnnotation()
              stopPoint.coordinate = coordinateArray.last!
              stopPoint.title = "终点"
              mapView.addAnnotation(stopPoint)
          }
      }
      
      @IBAction func back(_ sender: Any) {
          if !isRecordPresent {
          presentingViewController?.presentingViewController?.dismiss(animated: true, completion: nil)
          } else {
              presentingViewController?.dismiss(animated: true, completion: nil)
          }
      }
      
      @IBAction func share(_ sender: Any) {
          self.mapView.takeSnapshot(in: view.bounds) { mapImage, status in
             
              UIGraphicsBeginImageContextWithOptions(self.detailView.bounds.size, false, UIScreen.main.scale)
              self.detailView.layer.render(in: UIGraphicsGetCurrentContext()!)
              let detailImage = UIGraphicsGetImageFromCurrentImageContext()!
              UIGraphicsEndImageContext()
              
              UIGraphicsBeginImageContextWithOptions(self.stepView.bounds.size, false, UIScreen.main.scale)
              self.stepView.layer.render(in: UIGraphicsGetCurrentContext()!)
              let stepImage = UIGraphicsGetImageFromCurrentImageContext()!
              UIGraphicsEndImageContext()
              
              UIGraphicsBeginImageContextWithOptions(self.altitudeView.bounds.size, false, UIScreen.main.scale)
              self.altitudeView.layer.render(in: UIGraphicsGetCurrentContext()!)
              let altitudeImage = UIGraphicsGetImageFromCurrentImageContext()!
              UIGraphicsEndImageContext()
              
             
              
              // union image
              let imageSize = self.scrollView.contentSize
              let backImageRect = CGRect(x: 0, y: 0, width: self.scrollView.contentSize.width, height: self.scrollView.contentSize.height)
              let backImage = UIImage.getImageWithColor(UIColor.rgbColorFromHex(0xF2F2F2), rect: backImageRect)
  //            let imageSize = self.mapView.bounds.size
              UIGraphicsBeginImageContextWithOptions(imageSize, false, UIScreen.main.scale)
              backImage.draw(in: backImageRect)
              mapImage?.draw(in: self.mapView.bounds)
              detailImage.draw(in: self.detailView.frame)
              stepImage.draw(in: self.stepView.frame)
              altitudeImage.draw(in: self.altitudeView.frame)
              let image = UIGraphicsGetImageFromCurrentImageContext()!
              
              UIGraphicsEndImageContext()
  //            self.transitionToDetail(with: image)
              let shareView = ShareView(image)
              shareView.show()
          }
          
      }
      
  //    func captureAction() -> UIImage? {
  //        // map image
  //        
  ////        self.mapView.takeSnapshot(in: view.bounds) { image, status in
  ////            ret
  ////        }
  //        return self.mapView.takeSnapshot(in: view.bounds)
  ////        takeSnapshot(in: self.mapView.bounds)
  ////        // result image
  ////        let s = self.view.bounds.size
  ////        UIGraphicsBeginImageContextWithOptions(s, false, UIScreen.main.scale)
  ////        self.view.layer.render(in: UIGraphicsGetCurrentContext()!)
  ////        let resultImage = UIGraphicsGetImageFromCurrentImageContext()!
  ////        UIGraphicsEndImageContext()
  ////        // union image
  ////        let imageSize = self.mapView.bounds.size
  ////        UIGraphicsBeginImageContextWithOptions(imageSize, false, UIScreen.main.scale)
  ////        mapImage?.draw(in: self.mapView.bounds)
  ////        resultImage.draw(in: self.view.frame)
  ////        let image = UIGraphicsGetImageFromCurrentImageContext()!
  ////        UIGraphicsEndImageContext()
  ////        self.transitionToDetail(with: image)
  //    }
      
      
      
      private func distanceToStep(_ distance: Float) -> Int {
          let user = UserInfo
          if user.gender == 1 {
              return Int (distance * 100 / 0.4 / Float(user.height))
          } else {
              return Int (distance * 100 / 0.35 / Float(user.height))
          }
      }
      
      private func setupStepChartView() {
          if stepCadenceArray.count < 2 {
              return
          }
          stepChartView.chartDescription?.enabled = false //图描述
          stepChartView.legend.enabled = false //左下角图例
          stepChartView.setScaleEnabled(false) //可滑动
          stepChartView.rightAxis.enabled = false //不绘制右边轴的信息
          
          let leftAxis = stepChartView.leftAxis
          leftAxis.labelTextColor = ChartsTextColor
          leftAxis.labelFont = ChartsTextFont(11)
          leftAxis.yOffset = -5
          leftAxis.xOffset = -1
          leftAxis.gridLineDashLengths = [2.0, 2.0]  //设置虚线样式的网格线
          leftAxis.gridColor = LineColor
          leftAxis.gridLineWidth = 1
          leftAxis.axisLineWidth = 0
          leftAxis.drawGridLinesBehindDataEnabled = false
          leftAxis.labelPosition = .insideChart
          
          leftAxis.axisMinimum = 0 //设置左侧Y轴最小值
          leftAxis.axisMaximum = max(Double(stepCadenceArray.max() ?? 220) + 20, 140)
          leftAxis.granularity = 60
          
          let litmitLine = ChartLimitLine(limit: 0, label: "")
          litmitLine.lineWidth = 1
          litmitLine.lineColor = LineColor
          leftAxis.addLimitLine(litmitLine)
          leftAxis.drawLimitLinesBehindDataEnabled = false  //设置限制线绘制在折线图的后面
          
          
          let xAxis = stepChartView.xAxis
          xAxis.granularity = 1 //间隔
          xAxis.labelPosition = .bottom
          xAxis.labelFont = ChartsTextFont(11)
          xAxis.labelTextColor = ChartsTextColor
          xAxis.drawGridLinesBehindDataEnabled = false
          xAxis.axisLineColor = LineColor
          xAxis.axisLineWidth = 1
          xAxis.gridLineDashLengths = [6, 666]
          xAxis.gridColor = LineColor
          xAxis.drawAxisLineEnabled = false
          
          let XValues = (0..<stepCadenceArray.count-1).map { (i) -> String in
              return "\(i)"
          }
          xAxis.valueFormatter = IndexAxisValueFormatter(values: XValues)
          xAxis.labelCount = 5
          xAxis.enabled = false
          xAxis.axisMinimum = -Double(stepCadenceArray.count)/20
          xAxis.axisMaximum = Double(stepCadenceArray.count)-1 + Double(stepCadenceArray.count)/20
          
          var dataEntries = [ChartDataEntry]()
          
          for (i, cadence) in stepCadenceArray.enumerated() {
              if cadence > 0 {
                  dataEntries.append(ChartDataEntry(x: Double(i), y: Double(cadence)))
              }
          }
          
          let dataSet = LineChartDataSet(entries: dataEntries)
          dataSet.drawCirclesEnabled = false
          dataSet.drawValuesEnabled = false
          dataSet.highlightEnabled = false//选中拐点,是否开启高亮效果(显示十字线)
          dataSet.highlightLineWidth = 1
          dataSet.highlightColor = UIColor.rgbColorFromHex(0xD90009)// 十字线颜色
          dataSet.drawHorizontalHighlightIndicatorEnabled = false
          dataSet.mode = .horizontalBezier
          dataSet.setColor(UIColor.rgbColorFromHex(0xE8AF1C))
          dataSet.lineWidth = 1
          
          
          dataSet.drawFilledEnabled = true //填充绘制
          let gradientColors = [UIColor.rgbColorFromHex(0xFFCE12).cgColor, UIColor.rgbColorFromHex(0xFFFEFB).cgColor]
          let gradient = CGGradient(colorsSpace: nil, colors: gradientColors as CFArray, locations: [1.0, 0.0])
          dataSet.fillAlpha = 1
          dataSet.fill = Fill(linearGradient: gradient!, angle: 90)
          stepChartView.data = LineChartData(dataSets: [dataSet])
      }
      
      private func setupAltitudeChartView() {
          if altitudeArray.count < 2 {
              return
          }
          altitudeChartView.chartDescription?.enabled = false //图描述
          altitudeChartView.legend.enabled = false //左下角图例
          altitudeChartView.setScaleEnabled(false) //可滑动
          altitudeChartView.rightAxis.enabled = false //不绘制右边轴的信息
          
          let leftAxis = altitudeChartView.leftAxis
          leftAxis.labelTextColor = ChartsTextColor
          leftAxis.labelFont = ChartsTextFont(11)
          leftAxis.yOffset = -5
          leftAxis.xOffset = -1
          leftAxis.gridLineDashLengths = [2.0, 2.0]  //设置虚线样式的网格线
          leftAxis.gridColor = LineColor
          leftAxis.gridLineWidth = 1
          leftAxis.axisLineWidth = 0
          leftAxis.drawGridLinesBehindDataEnabled = false
          leftAxis.labelPosition = .insideChart
          let space = altitude/10
          leftAxis.axisMinimum = min((altitudeArray.min() ?? space) - space, 0)//设置左侧Y轴最小值
          leftAxis.axisMaximum = max(altitudeArray.max() ?? 100 + space, 100)
          leftAxis.granularity = 60
          
          let litmitLine = ChartLimitLine(limit: 0, label: "")
          litmitLine.lineWidth = 1
          litmitLine.lineColor = LineColor
          leftAxis.addLimitLine(litmitLine)
          leftAxis.drawLimitLinesBehindDataEnabled = false  //设置限制线绘制在折线图的后面
          
          
          let xAxis = altitudeChartView.xAxis
          xAxis.granularity = 1 //间隔
          xAxis.labelPosition = .bottom
          xAxis.labelFont = ChartsTextFont(11)
          xAxis.labelTextColor = ChartsTextColor
          xAxis.drawGridLinesBehindDataEnabled = false
          xAxis.axisLineColor = LineColor
          xAxis.axisLineWidth = 1
          xAxis.gridLineDashLengths = [6, 666]
          xAxis.gridColor = LineColor
          xAxis.drawAxisLineEnabled = false
          
          let XValues = (0..<altitudeArray.count-1).map { (i) -> String in
              return "\(i)"
          }
          xAxis.valueFormatter = IndexAxisValueFormatter(values: XValues)
          xAxis.labelCount = 5
          xAxis.enabled = false
          xAxis.axisMinimum = -Double(altitudeArray.count)/20
          xAxis.axisMaximum = Double(altitudeArray.count)-1 + Double(altitudeArray.count)/20
          
          var dataEntries = [ChartDataEntry]()
          
          for (i, altitude) in altitudeArray.enumerated() {
  //            if altitude > 0 {
                  dataEntries.append(ChartDataEntry(x: Double(i), y: altitude))
  //            }
          }
          
          let dataSet = LineChartDataSet(entries: dataEntries)
          dataSet.drawCirclesEnabled = false
          dataSet.drawValuesEnabled = false
          dataSet.highlightEnabled = false//选中拐点,是否开启高亮效果(显示十字线)
          dataSet.highlightLineWidth = 1
          dataSet.highlightColor = UIColor.rgbColorFromHex(0xD90009)// 十字线颜色
          dataSet.drawHorizontalHighlightIndicatorEnabled = false
          dataSet.mode = .horizontalBezier
          dataSet.setColor(UIColor.rgbColorFromHex(0x08BBB2))
          dataSet.lineWidth = 1
          
          
          dataSet.drawFilledEnabled = true //填充绘制
          let gradientColors = [UIColor.rgbColorFromHex(0x12DDE1).cgColor, UIColor.rgbColorFromHex(0xFFFEFB).cgColor]
          let gradient = CGGradient(colorsSpace: nil, colors: gradientColors as CFArray, locations: [1.0, 0.0])
          dataSet.fillAlpha = 1
          dataSet.fill = Fill(linearGradient: gradient!, angle: 90)
          altitudeChartView.data = LineChartData(dataSets: [dataSet])
      }
      
      
      deinit {
          print("deinit\(NSStringFromClass(type(of: self)))!!!!!!!")
      }
  
  }
  
  extension EndMotionVC: UIScrollViewDelegate {
      
      func scrollViewDidScroll(_ scrollView: UIScrollView) {
  //        print(scr)
      }
  }
  
  extension EndMotionVC: MAMapViewDelegate {
      func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! {
          if let poly = overlay as? MAPolyline {
              let polylineView = MAPolylineRenderer(polyline: poly)
              polylineView!.lineWidth = 6
              polylineView!.strokeColor = UIColor(red: 4 / 255.0, green:  181 / 255.0, blue:  108 / 255.0, alpha: 1.0)
              polylineView!.lineJoinType = kMALineJoinRound
              polylineView!.lineCapType = kMALineCapRound
              return polylineView
          } else {
              return nil
          }
      }
      
      func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! {
          if annotation is MAPointAnnotation {
              let pointReuseIndetifier = "pointReuseIndetifier"
  //            let customAnnotation = annotation as! CustomPointAnnotation
              var annotationView: MAAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIndetifier)
              
              if annotationView == nil {
                  annotationView = MAAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIndetifier)
              }
              if annotation.title == "起点" {
                  annotationView?.image = UIImage(named: "start_point")
              }
              if annotation.title == "终点" {
                  annotationView?.image = UIImage(named: "stop_point")
              }
              annotationView?.centerOffset = CGPoint(x: 0, y: -7.5);
              return annotationView
          }
          return nil
      }
  }