Skip to content

Commit 1465076

Browse files
committed
You can now view each leg separately.
1 parent ae66e0a commit 1465076

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

GeoTrackKitExample/GeoTrackKitExample/Views/ReferenceTrack/LegSwitchCell.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class LegSwitchCell: UITableViewCell {
1717
var indexPath: IndexPath?
1818
weak var model: UIGeoTrack?
1919

20+
override func prepareForReuse() {
21+
super.prepareForReuse()
22+
setSelected(false, animated: false)
23+
}
24+
2025
@IBAction func didToggleSwitch(_ sender: UISwitch) {
2126
guard let indexPath = indexPath else {
2227
return assertionFailure("IndexPath not set on cell")

GeoTrackKitExample/GeoTrackKitExample/Views/ReferenceTrack/TrackOverviewTableViewController.swift

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// Copyright © 2017 Eric Internicola. All rights reserved.
77
//
88

9+
import CoreLocation
910
import GeoTrackKit
1011
import UIKit
1112

@@ -48,27 +49,48 @@ extension TrackOverviewTableViewController {
4849
}
4950

5051
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
51-
if indexPath.section == 0 {
52+
switch indexPath.section {
53+
case 0:
5254
let cell = tableView.dequeueReusableCell(withIdentifier: "TrackOverviewCell", for: indexPath)
5355
guard let overviewCell = cell as? TrackOverviewCell else {
5456
return cell
5557
}
5658
overviewCell.analyzer = analyzer
5759

5860
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
6172

62-
guard let model = model, let legCell = cell as? LegSwitchCell else {
6373
return cell
6474
}
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+
}
6586

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: "")
7089

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)
7294
}
7395

7496
}
@@ -77,6 +99,14 @@ extension TrackOverviewTableViewController {
7799

78100
extension Leg {
79101

102+
var isAscent: Bool {
103+
return direction == .upward
104+
}
105+
106+
var isDescent: Bool {
107+
return direction == .downward
108+
}
109+
80110
var string: String {
81111
var result = String(index) + " - "
82112
result += String(endIndex) + ", "
@@ -87,4 +117,14 @@ extension Leg {
87117
return result
88118
}
89119

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+
90130
}

0 commit comments

Comments
 (0)