-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSMTurnInstruction.m
136 lines (118 loc) · 5.1 KB
/
SMTurnInstruction.m
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
//
// SMTurnInstructions.m
// I Bike CPH
//
// Created by Petra Markovic on 1/28/13.
// Copyright (C) 2013 City of Copenhagen. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
//
#import "SMTurnInstruction.h"
@implementation SMTurnInstruction
@synthesize drivingDirection= _drivingDirection;
NSString *icons[] = {
@"no icon",
@"up",
@"right-ward",
@"right",
@"right",
@"u-turn",
@"left",
@"left",
@"left-ward",
@"location",
@"up",
@"roundabout",
@"roundabout",
@"roundabout",
@"up",
@"flag",
@"walk",
@"bike",
@"near-destination",
};
- (CLLocation *)getLocation {
return self.loc;
// if (waypoints && self.waypointsIndex >= 0 && self.waypointsIndex < waypoints.count)
// return [waypoints objectAtIndex:self.waypointsIndex];
// return nil;
}
// Returns full direction names for abbreviations N NE E SE S SW W NW
NSString *directionString(NSString *abbreviation) {
NSString * s = translateString([@"direction_" stringByAppendingString:abbreviation]);
return s;
}
// Returns only string representation of the driving direction
- (void)generateDescriptionString {
NSString *key = [@"direction_" stringByAppendingFormat:@"%d", self.drivingDirection];
if (self.routeType == SMRouteTypeBike || self.routeType == SMRouteTypeWalk) {
NSString *desc = [NSString stringWithFormat:translateString(key), translateString([@"direction_number_" stringByAppendingString:self.ordinalDirection])];
self.descriptionString = desc;
} else {
self.descriptionString = [NSString stringWithFormat:translateString(key), self.routeLineDestination];
}
}
- (void)generateStartDescriptionString {
if (self.routeType == SMRouteTypeBike || self.routeType == SMRouteTypeWalk) {
NSString *key = [@"first_direction_" stringByAppendingFormat:@"%d", self.drivingDirection];
NSString *desc = [NSString stringWithFormat:translateString(key), translateString([@"direction_" stringByAppendingString:self.directionAbrevation]), translateString([@"direction_number_" stringByAppendingString:self.ordinalDirection])];
self.descriptionString = desc;
} else {
NSString *key = [@"direction_" stringByAppendingFormat:@"%d", self.drivingDirection];
self.descriptionString = [NSString stringWithFormat:translateString(key), self.routeLineStart,self.routeLineName, self.routeLineDestination];
}
}
- (void)generateShortDescriptionString {
self.shortDescriptionString = self.wayName;
}
// Returns only string representation of the driving direction including wayname
- (void)generateFullDescriptionString {
NSString *key = [@"direction_" stringByAppendingFormat:@"%d", self.drivingDirection];
if (self.routeType == SMRouteTypeBike || self.routeType == SMRouteTypeWalk) {
if (self.drivingDirection != 0 && self.drivingDirection != 15 && self.drivingDirection != 100) {
self.fullDescriptionString = [NSString stringWithFormat:@"%@ %@", translateString(key), self.wayName];
return;
}
self.fullDescriptionString = [NSString stringWithFormat:@"%@", translateString(key)];
} else if(self.drivingDirection == 18) {
self.fullDescriptionString = [NSString stringWithFormat:translateString(key), self.routeLineStart, self.routeLineName, self.routeLineDestination];
} else if (self.drivingDirection == 19) {
self.fullDescriptionString = [NSString stringWithFormat:translateString(key), self.routeLineDestination];
}
}
- (UIImage *)directionIcon {
return [UIImage imageNamed:self.imageName];
}
// Full textual representation of the object, used mainly for debugging
- (NSString *)description {
return [NSString stringWithFormat:@"%@ %@ [SMTurnInstruction: %d, %d, %@, %@, %f, (%f, %f)]",
[self descriptionString],
self.wayName,
self.lengthInMeters,
self.timeInSeconds,
self.lengthWithUnit,
self.directionAbrevation,
self.azimuth,
[self getLocation].coordinate.latitude, [self getLocation].coordinate.longitude];
}
-(void)setDrivingDirection:(TurnDirection)drivingDirection {
_drivingDirection = drivingDirection;
self.imageName = icons[self.drivingDirection];
}
- (void)setRouteType:(SMRouteType)routeType {
_routeType = routeType;
if (self.drivingDirection == 18 || self.drivingDirection == 19) { // For public transport, override icon.
switch (self.routeType) {
case SMRouteTypeSTrain: self.imageName = @"STrainDirection"; break;
case SMRouteTypeTrain: self.imageName = @"TrainDirection"; break;
case SMRouteTypeBus: self.imageName = @"BusDirection"; break;
case SMRouteTypeFerry: self.imageName = @"FerryDirection"; break;
case SMRouteTypeMetro: self.imageName = @"MetroDirection"; break;
case SMRouteTypeWalk: self.imageName = @"WalkDirection"; break;
default: break;
}
}
}
@end