Skip to content

Commit

Permalink
Added support for display of single leg itineraries that contain step…
Browse files Browse the repository at this point in the history
…s for walking, biking, and driving.
  • Loading branch information
Aaron Sutula committed Oct 16, 2012
1 parent 3a9fb83 commit 460b36e
Show file tree
Hide file tree
Showing 11 changed files with 2,544 additions and 7 deletions.
6 changes: 6 additions & 0 deletions OpenTripPlanner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
9388194116193310002021EA /* MBProgressHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = 9388193F161927A6002021EA /* MBProgressHUD.m */; };
93B179C0162BBAB400F09EC6 /* OTPUnitFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 93B179BF162BBAB400F09EC6 /* OTPUnitFormatter.m */; };
93B179C3162BC69C00F09EC6 /* OTPUnitData.m in Sources */ = {isa = PBXBuildFile; fileRef = 93B179C2162BC69C00F09EC6 /* OTPUnitData.m */; };
93B179C6162D253000F09EC6 /* OTPStepCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 93B179C5162D252F00F09EC6 /* OTPStepCell.m */; };
CC088DE715F69E4900C6F372 /* OP.png in Resources */ = {isa = PBXBuildFile; fileRef = CC088DE615F69E4900C6F372 /* OP.png */; };
CC088DE915F6A3B400C6F372 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CC088DE815F6A3B400C6F372 /* MapKit.framework */; };
CC0A1F6416038F6B003085B2 /* FacingView.m in Sources */ = {isa = PBXBuildFile; fileRef = CC0A1F5516038F6B003085B2 /* FacingView.m */; };
Expand Down Expand Up @@ -188,6 +189,8 @@
93B179BF162BBAB400F09EC6 /* OTPUnitFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTPUnitFormatter.m; sourceTree = "<group>"; };
93B179C1162BC69B00F09EC6 /* OTPUnitData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTPUnitData.h; sourceTree = "<group>"; };
93B179C2162BC69C00F09EC6 /* OTPUnitData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTPUnitData.m; sourceTree = "<group>"; };
93B179C4162D252F00F09EC6 /* OTPStepCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTPStepCell.h; sourceTree = "<group>"; };
93B179C5162D252F00F09EC6 /* OTPStepCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTPStepCell.m; sourceTree = "<group>"; };
CC088DE215F6932500C6F372 /* RoutingCoverage.geojson */ = {isa = PBXFileReference; lastKnownFileType = text; path = RoutingCoverage.geojson; sourceTree = "<group>"; };
CC088DE615F69E4900C6F372 /* OP.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = OP.png; sourceTree = "<group>"; };
CC088DE815F6A3B400C6F372 /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -590,6 +593,8 @@
93B179BF162BBAB400F09EC6 /* OTPUnitFormatter.m */,
93B179C1162BC69B00F09EC6 /* OTPUnitData.h */,
93B179C2162BC69C00F09EC6 /* OTPUnitData.m */,
93B179C4162D252F00F09EC6 /* OTPStepCell.h */,
93B179C5162D252F00F09EC6 /* OTPStepCell.m */,
);
path = OpenTripPlanner;
sourceTree = "<group>";
Expand Down Expand Up @@ -869,6 +874,7 @@
CC23172B16276ABD00EE0F48 /* OTPDistanceBasedLegCell.m in Sources */,
93B179C0162BBAB400F09EC6 /* OTPUnitFormatter.m in Sources */,
93B179C3162BC69C00F09EC6 /* OTPUnitData.m in Sources */,
93B179C6162D253000F09EC6 /* OTPStepCell.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
1 change: 1 addition & 0 deletions OpenTripPlanner/Leg.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#import "Place.h"
#import "LegGeometry.h"
#import "Step.h"

struct OTPBounds {
CLLocationCoordinate2D swCorner;
Expand Down
42 changes: 38 additions & 4 deletions OpenTripPlanner/MainStoryboard_iPhone.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<gestureRecognizers/>
<prototypes>
<tableViewCell contentMode="scaleToFill" restorationIdentifier="OverviewCell" selectionStyle="blue" indentationWidth="10" reuseIdentifier="OverviewCell" id="VqF-va-TZO">
<tableViewCell contentMode="scaleToFill" restorationIdentifier="" selectionStyle="blue" indentationWidth="10" reuseIdentifier="OverviewCell" id="VqF-va-TZO">
<rect key="frame" x="0.0" y="22" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
Expand All @@ -166,7 +166,7 @@
</view>
<gestureRecognizers/>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" restorationIdentifier="DistanceBasedLegCell" selectionStyle="gray" indentationWidth="10" reuseIdentifier="DistanceBasedLegCell" rowHeight="60" id="IHW-ty-emz" customClass="OTPDistanceBasedLegCell">
<tableViewCell contentMode="scaleToFill" restorationIdentifier="" selectionStyle="gray" indentationWidth="10" reuseIdentifier="DistanceBasedLegCell" rowHeight="60" id="IHW-ty-emz" customClass="OTPDistanceBasedLegCell">
<rect key="frame" x="0.0" y="66" width="320" height="60"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
Expand Down Expand Up @@ -210,7 +210,7 @@
<outlet property="timeLabel" destination="gXi-6I-u1k" id="y77-OW-h0k"/>
</connections>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" restorationIdentifier="StopBasedLegCell" selectionStyle="gray" indentationWidth="10" reuseIdentifier="StopBasedLegCell" rowHeight="82" id="fOU-rm-GvD" customClass="OTPStopBasedLegCell">
<tableViewCell contentMode="scaleToFill" restorationIdentifier="" selectionStyle="gray" indentationWidth="10" reuseIdentifier="StopBasedLegCell" rowHeight="82" id="fOU-rm-GvD" customClass="OTPStopBasedLegCell">
<rect key="frame" x="0.0" y="126" width="320" height="82"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
Expand Down Expand Up @@ -303,7 +303,7 @@
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<gestureRecognizers/>
</tableViewCell>
<tableViewCell userInteractionEnabled="NO" contentMode="scaleToFill" restorationIdentifier="ArrivalFooter" selectionStyle="blue" indentationWidth="10" reuseIdentifier="ArrivalFooter" rowHeight="60" id="bSI-aJ-fM0">
<tableViewCell userInteractionEnabled="NO" contentMode="scaleToFill" restorationIdentifier="" selectionStyle="blue" indentationWidth="10" reuseIdentifier="ArrivalFooter" rowHeight="60" id="bSI-aJ-fM0">
<rect key="frame" x="0.0" y="235" width="320" height="60"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
Expand Down Expand Up @@ -351,6 +351,34 @@
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" indentationWidth="10" reuseIdentifier="StepCell" id="sry-5X-U7K" customClass="OTPStepCell">
<rect key="frame" x="0.0" y="339" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="320" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Zyf-Uu-iHD">
<rect key="frame" x="61" y="11" width="239" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="highlightedColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Icon" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="aqB-jM-HX5">
<rect key="frame" x="12" y="11" width="36" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="highlightedColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<connections>
<outlet property="instructionLabel" destination="Zyf-Uu-iHD" id="FEe-5Z-KyP"/>
</connections>
</tableViewCell>
</prototypes>
<sections/>
<connections>
Expand Down Expand Up @@ -672,6 +700,12 @@ AQABAAEAAQAB//+dkAEA//+PgAAE//+dkAEI//+dkAEMUERUAFBTVABQV1QAUFBUAAAAAAEAAAABA
<class className="OTPSearchBarWithActivity" superclassName="UISearchBar">
<source key="sourceIdentifier" type="project" relativePath="./Classes/OTPSearchBarWithActivity.h"/>
</class>
<class className="OTPStepCell" superclassName="UITableViewCell">
<source key="sourceIdentifier" type="project" relativePath="./Classes/OTPStepCell.h"/>
<relationships>
<relationship kind="outlet" name="instructionLabel" candidateClass="UILabel"/>
</relationships>
</class>
<class className="OTPStopBasedLegCell" superclassName="UITableViewCell">
<source key="sourceIdentifier" type="project" relativePath="./Classes/OTPStopBasedLegCell.h"/>
<relationships>
Expand Down
16 changes: 16 additions & 0 deletions OpenTripPlanner/OTPAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// Initialize RestKit
RKObjectManager* objectManager = [RKObjectManager managerWithBaseURLString:@"http://demo.opentripplanner.org/opentripplanner-api-webapp/ws"];

//RKObjectManager* objectManager = [RKObjectManager managerWithBaseURLString:@"http://sfbay.deployer.opentripplanner.org/opentripplanner-api-webapp/ws"];

// Enable automatic network activity indicator management
objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;

Expand All @@ -38,6 +40,19 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
@"geometry", @"geometry",
nil];

RKObjectMapping* stepMapping = [RKObjectMapping mappingForClass:[Step class]];
[stepMapping mapKeyPathsToAttributes:
@"distance", @"distance",
@"relativeDirection", @"relativeDirection",
@"streetName", @"streetName",
@"absoluteDirection", @"absoluteDirection",
@"exit", @"exit",
@"stayOn", @"stayOn",
@"bogusName", @"bogusName",
@"lon", @"lon",
@"lat", @"lat",
nil];

RKObjectMapping* legGeometryMapping = [RKObjectMapping mappingForClass:[LegGeometry class]];
[legGeometryMapping mapKeyPathsToAttributes:
@"length", @"length",
Expand All @@ -58,6 +73,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[legMapping mapKeyPath:@"to" toRelationship:@"to" withMapping:placeMapping];
[legMapping mapKeyPath:@"intermediateStops" toRelationship:@"intermediateStops" withMapping:placeMapping];
[legMapping mapKeyPath:@"legGeometry" toRelationship:@"legGeometry" withMapping:legGeometryMapping];
[legMapping mapKeyPath:@"steps" toRelationship:@"steps" withMapping:stepMapping];

RKObjectMapping* itineraryMapping = [RKObjectMapping mappingForClass:[Itinerary class]];
[itineraryMapping mapKeyPathsToAttributes:
Expand Down
1 change: 1 addition & 0 deletions OpenTripPlanner/OTPDirectionsInputViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ - (void)planTripFrom:(CLLocationCoordinate2D)startPoint to:(CLLocationCoordinate
@"time", timeString,
@"arriveBy", arriveBy,
@"routerId", @"req-241",
//@"routerId", @"req-92",
@"maxWalkDistance", @"840",
@"fromPlace", fromString,
@"toPlace", toString,
Expand Down
66 changes: 65 additions & 1 deletion OpenTripPlanner/OTPItineraryTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "OTPItineraryTableViewController.h"
#import "OTPStopBasedLegCell.h"
#import "OTPDistanceBasedLegCell.h"
#import "OTPStepCell.h"
#import "PPRevealSideViewController.h"
#import "UIView+Origami.h"
#import "OTPUnitData.h"
Expand All @@ -21,6 +22,8 @@ @interface OTPItineraryTableViewController ()
NSArray *_stopBasedModes;
NSArray *_transferModes;
NSDictionary *_modeDisplayStrings;
NSDictionary *_relativeDirectionDisplayStrings;
NSDictionary *_absoluteDirectionDisplayStrings;
}
@end

Expand Down Expand Up @@ -59,6 +62,30 @@ - (void)viewDidLoad
@"FUNICULAR" : @"Funicular",
@"TRANSFER" : @"Transfer"
};

_relativeDirectionDisplayStrings = @{
@"HARD_LEFT" : @"Hard left",
@"LEFT" : @"Left",
@"SLIGHTLY_LEFT" : @"Slight left",
@"CONTINUE" : @"Continue",
@"SLIGHTLY_RIGHT" : @"Slight right",
@"RIGHT" : @"Right",
@"HARD_RIGHT" : @"Hard right",
@"CIRCLE_CLOCKWISE" : @"Circle clockwise",
@"CIRCLE_COUNTERCLOCKWISE" : @"Circle counterclockwise",
@"ELEVATOR" : @"Elevator"
};

_absoluteDirectionDisplayStrings = @{
@"NORTH" : @"north",
@"NORTHEAST" : @"northeast",
@"EAST" : @"east",
@"SOUTHEAST" : @"southeast",
@"SOUTH" : @"south",
@"SOUTHWEST" : @"southwest",
@"WEST" : @"west",
@"NORTHWEST" : @"northwest"
};

// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
Expand Down Expand Up @@ -116,6 +143,10 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
// If we have a single leg with steps, it's a walk, bike, or drive itinierary
if (self.itinerary.legs.count == 1 && ((Leg *)[self.itinerary.legs objectAtIndex:0]).steps.count > 0) {
return ((Leg *)[self.itinerary.legs objectAtIndex:0]).steps.count + 1;
}
return self.itinerary.legs.count + 1;
}

Expand All @@ -131,6 +162,25 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
} else {

if (self.itinerary.legs.count == 1 && ((Leg *)[self.itinerary.legs objectAtIndex:0]).steps.count > 0) {
Leg *leg = [self.itinerary.legs objectAtIndex:0];
Step *step = [leg.steps objectAtIndex:indexPath.row-1];
OTPStepCell *cell = [tableView dequeueReusableCellWithIdentifier:@"StepCell"];
NSString *instruction;
if (indexPath.row == 1) {
instruction = [NSString stringWithFormat:@"%@ %@ on %@",
[_modeDisplayStrings objectForKey:leg.mode],
[_absoluteDirectionDisplayStrings objectForKey:step.absoluteDirection],
step.streetName];
} else {
instruction = [NSString stringWithFormat:@"%@ on %@",
[_relativeDirectionDisplayStrings objectForKey:step.relativeDirection],
step.streetName];
}
cell.instructionLabel.text = instruction;
return cell;
}

Leg *leg = [self.itinerary.legs objectAtIndex:indexPath.row-1];

if ([_distanceBasedModes containsObject:leg.mode]) {
Expand Down Expand Up @@ -161,7 +211,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

cell.instructionLabel.text = [NSString stringWithFormat:@"%@ towards %@", leg.route, leg.headsign];
cell.departureTimeLabel.text = [NSString stringWithFormat:@"%@", [dateFormatter stringFromDate:leg.startTime]];
cell.stopsLabel.text = [NSString stringWithFormat:@"%u stops", leg.intermediateStops.count];
cell.stopsLabel.text = [NSString stringWithFormat:@"%u stops", leg.intermediateStops.count+1];

cell.toLabel.text = [NSString stringWithFormat:@"Get off at %@", leg.to.name];

Expand All @@ -181,6 +231,10 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
return 44;
}

if (self.itinerary.legs.count == 1 && ((Leg *)[self.itinerary.legs objectAtIndex:0]).steps.count > 0) {
return 44;
}

Leg *leg = [self.itinerary.legs objectAtIndex:indexPath.row - 1];

if ([_distanceBasedModes containsObject:leg.mode]) {
Expand All @@ -200,13 +254,23 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
if (mapShowing) {
if (indexPath.row == 0) {
[self displayItineraryOverview];
} else if (self.itinerary.legs.count == 1 && ((Leg *)[self.itinerary.legs objectAtIndex:0]).steps.count > 0) {
Leg *leg = [self.itinerary.legs objectAtIndex:0];
Step *step = [leg.steps objectAtIndex:indexPath.row-1];
[self.mapView setZoom:16];
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(step.lat.doubleValue, step.lon.doubleValue) animated:YES];
} else {
[self displayLeg:[self.itinerary.legs objectAtIndex:indexPath.row - 1]];
}
} else {
[self.tableView showOrigamiTransitionWith:self.mapView NumberOfFolds:3 Duration:0.3 Direction:XYOrigamiDirectionFromLeft completion:^(BOOL finished) {
if (indexPath.row == 0) {
[self displayItineraryOverview];
} else if (self.itinerary.legs.count == 1 && ((Leg *)[self.itinerary.legs objectAtIndex:0]).steps.count > 0) {
Leg *leg = [self.itinerary.legs objectAtIndex:0];
Step *step = [leg.steps objectAtIndex:indexPath.row-1];
[self.mapView setZoom:16];
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(step.lat.doubleValue, step.lon.doubleValue) animated:YES];
} else {
[self displayLeg:[self.itinerary.legs objectAtIndex:indexPath.row - 1]];
}
Expand Down
Loading

0 comments on commit 460b36e

Please sign in to comment.