6
6
// Copyright © 2017 Eric Internicola. All rights reserved.
7
7
//
8
8
9
+ import CoreLocation
9
10
import GeoTrackKit
10
11
import UIKit
11
12
@@ -48,27 +49,48 @@ extension TrackOverviewTableViewController {
48
49
}
49
50
50
51
override func tableView( _ tableView: UITableView , cellForRowAt indexPath: IndexPath ) -> UITableViewCell {
51
- if indexPath. section == 0 {
52
+ switch indexPath. section {
53
+ case 0 :
52
54
let cell = tableView. dequeueReusableCell ( withIdentifier: " TrackOverviewCell " , for: indexPath)
53
55
guard let overviewCell = cell as? TrackOverviewCell else {
54
56
return cell
55
57
}
56
58
overviewCell. analyzer = analyzer
57
59
58
60
return overviewCell
59
- }
60
- let cell = tableView. dequeueReusableCell ( withIdentifier: " LegSwitchCell " , for: indexPath)
61
+ default :
62
+ let cell = tableView. dequeueReusableCell ( withIdentifier: " LegSwitchCell " , for: indexPath)
63
+
64
+ guard let model = model, let legCell = cell as? LegSwitchCell else {
65
+ return cell
66
+ }
67
+
68
+ legCell. toggleSwitch. isOn = model. isVisible ( at: indexPath. row)
69
+ legCell. label. text = analyzer? . legs [ indexPath. row] . string
70
+ legCell. indexPath = indexPath
71
+ legCell. model = model
61
72
62
- guard let model = model, let legCell = cell as? LegSwitchCell else {
63
73
return cell
64
74
}
75
+ }
76
+
77
+ override func tableView( _ tableView: UITableView , didSelectRowAt indexPath: IndexPath ) {
78
+ guard indexPath. section != 0 , let analyzer = analyzer, indexPath. row < analyzer. legs. count else {
79
+ return
80
+ }
81
+ let leg = analyzer. legs [ indexPath. row]
82
+
83
+ guard let points = leg. points ( from: analyzer. track) else {
84
+ return
85
+ }
65
86
66
- legCell. toggleSwitch. isOn = model. isVisible ( at: indexPath. row)
67
- legCell. label. text = analyzer? . legs [ indexPath. row] . string
68
- legCell. indexPath = indexPath
69
- legCell. model = model
87
+ let name = " \( leg. isAscent ? " Ascent " : " Descent " ) # \( indexPath. row / 2 + 1 ) "
88
+ let track = GeoTrack ( points: points, name: name, description: " " )
70
89
71
- return cell
90
+ let trackMapVC = TrackMapViewController . loadFromStoryboard ( )
91
+ trackMapVC. model = UIGeoTrack ( with: track)
92
+ navigationController? . pushViewController ( trackMapVC, animated: true )
93
+ tableView. cellForRow ( at: indexPath) ? . setSelected ( false , animated: true )
72
94
}
73
95
74
96
}
@@ -77,6 +99,14 @@ extension TrackOverviewTableViewController {
77
99
78
100
extension Leg {
79
101
102
+ var isAscent : Bool {
103
+ return direction == . upward
104
+ }
105
+
106
+ var isDescent : Bool {
107
+ return direction == . downward
108
+ }
109
+
80
110
var string : String {
81
111
var result = String ( index) + " - "
82
112
result += String ( endIndex) + " , "
@@ -87,4 +117,14 @@ extension Leg {
87
117
return result
88
118
}
89
119
120
+ /// Gets you the points for this leg from the track.
121
+ /// - Parameter track: The track that you want the points for.
122
+ func points( from track: GeoTrack ) -> [ CLLocation ] ? {
123
+ guard index < track. points. count, endIndex < track. points. count, index < endIndex else {
124
+ return nil
125
+ }
126
+
127
+ return Array ( track. points [ index... endIndex] )
128
+ }
129
+
90
130
}
0 commit comments