PageRenderTime 33ms CodeModel.GetById 14ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/samples/MapTestbed/Classes/MapTestbedAppDelegate.m

http://github.com/route-me/route-me
Objective C | 150 lines | 114 code | 27 blank | 9 comment | 0 complexity | 4f1a4907bcb8bb418a7f54a5faf6813a MD5 | raw file
  1//
  2//  MapTestbedAppDelegate.m
  3//  MapTestbed : Diagnostic map
  4//
  5
  6#import "MapTestbedAppDelegate.h"
  7#import "RootViewController.h"
  8#import "MainViewController.h"
  9
 10#import "RMPath.h"
 11#import "RMMarker.h"
 12#import "RMMarkerManager.h"
 13
 14@implementation MapTestbedAppDelegate
 15
 16
 17@synthesize window;
 18@synthesize rootViewController;
 19
 20-(RMMapContents *)mapContents
 21{
 22	return self.rootViewController.mainViewController.mapView.contents;
 23}
 24-(void)performTestPart2
 25{
 26	// a bug exists that offsets the path when we execute this moveToLatLong
 27	CLLocationCoordinate2D pt;
 28	pt.latitude = 48.86600492029781f;
 29	pt.longitude = 2.3194026947021484f;
 30	
 31	[self.mapContents moveToLatLong: pt];
 32}
 33
 34
 35-(void)performTestPart3
 36{
 37	// path returns to correct position after this zoom
 38	CLLocationCoordinate2D northeast, southwest;
 39	northeast.latitude = 48.885875363989435f;
 40	northeast.longitude = 2.338285446166992f;
 41	southwest.latitude = 48.860406466081656f;
 42	southwest.longitude = 2.2885894775390625;
 43	
 44	[self.mapContents zoomWithLatLngBoundsNorthEast:northeast SouthWest:southwest];
 45}	
 46
 47
 48- (void)performTest
 49{
 50	NSLog(@"testing paths");
 51	RMMapContents *mapContents = [self mapContents];
 52
 53	UIImage *xMarkerImage = [UIImage imageNamed:@"marker-X.png"];
 54	
 55	// if we zoom with bounds after the paths are created, nothing is displayed on the map
 56	CLLocationCoordinate2D northeast, southwest;
 57	northeast.latitude = 48.885875363989435f;
 58	northeast.longitude = 2.338285446166992f;
 59	southwest.latitude = 48.860406466081656f;
 60	southwest.longitude = 2.2885894775390625;
 61	[mapContents zoomWithLatLngBoundsNorthEast:northeast SouthWest:southwest];
 62	
 63	CLLocationCoordinate2D one, two, three, four;
 64	one.latitude = 48.884238608729035f;
 65	one.longitude = 2.297086715698242f;
 66	two.latitude = 48.878481319827735f;
 67	two.longitude = 2.294340133666992f;
 68	three.latitude = 48.87351371451778f;
 69	three.longitude = 2.2948551177978516f;
 70	four.latitude = 48.86600492029781f;
 71	four.longitude = 2.3194026947021484f;
 72	
 73	// draw a green path south down an avenue and southeast on Champs-Elysees
 74	RMPath *testPath, *testRegion;
 75	testPath = [[RMPath alloc] initWithContents:mapContents];
 76	[testPath setLineColor:[UIColor greenColor]];
 77	[testPath setFillColor:[UIColor clearColor]];
 78	[testPath setLineWidth:4.0f];
 79    [testPath setShadowColor:[UIColor colorWithWhite:0.0 alpha:0.8]];
 80    [testPath setShadowBlur:4.0];
 81    [testPath setShadowOffset:CGSizeMake(0, 4)];
 82	[testPath addLineToLatLong:one];
 83	[testPath addLineToLatLong:two];
 84	[testPath addLineToLatLong:three];
 85	[testPath addLineToLatLong:four];
 86	[[mapContents overlay] addSublayer:testPath];
 87	[testPath release];
 88
 89	RMMarker *newMarker;
 90	newMarker = [[RMMarker alloc] initWithUIImage:xMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
 91	[mapContents.markerManager addMarker:[newMarker autorelease] AtLatLong:one];
 92	newMarker = [[RMMarker alloc] initWithUIImage:xMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
 93	[mapContents.markerManager addMarker:[newMarker autorelease] AtLatLong:two];
 94	newMarker = [[RMMarker alloc] initWithUIImage:xMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
 95	[mapContents.markerManager addMarker:[newMarker autorelease] AtLatLong:three];
 96	newMarker = [[RMMarker alloc] initWithUIImage:xMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
 97	[mapContents.markerManager addMarker:[newMarker autorelease] AtLatLong:four];
 98	
 99	CLLocationCoordinate2D r1, r2, r3, r4;
100	r1.latitude = 48.86637615203047f;
101	r1.longitude = 2.3236513137817383f;
102	r2.latitude = 48.86372241857954f;
103	r2.longitude = 2.321462631225586f;
104	r3.latitude = 48.86087090984738f;
105	r3.longitude = 2.330174446105957f;
106	r4.latitude = 48.86369418661614f;
107	r4.longitude = 2.332019805908203f;
108	
109	// draw a blue-filled rectangle on top of the Tuileries
110	testRegion = [[RMPath alloc] initWithContents:mapContents];
111	[testRegion setFillColor:[UIColor colorWithRed: 0.1 green:0.1 blue: 0.8 alpha: 0.5 ]];
112	[testRegion setLineColor:[UIColor blueColor]];
113	[testRegion setLineWidth:2.0f];
114	[testRegion addLineToLatLong:r1];
115	[testRegion addLineToLatLong:r2];
116	[testRegion addLineToLatLong:r3];
117	[testRegion addLineToLatLong:r4];
118	[testRegion closePath];
119	[[mapContents overlay] addSublayer:testRegion];
120	[testRegion release];
121	newMarker = [[RMMarker alloc] initWithUIImage:xMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
122	[mapContents.markerManager addMarker:[newMarker autorelease] AtLatLong:r1];
123	newMarker = [[RMMarker alloc] initWithUIImage:xMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
124	[mapContents.markerManager addMarker:[newMarker autorelease] AtLatLong:r2];
125	newMarker = [[RMMarker alloc] initWithUIImage:xMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
126	[mapContents.markerManager addMarker:[newMarker autorelease] AtLatLong:r3];
127	newMarker = [[RMMarker alloc] initWithUIImage:xMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
128	[mapContents.markerManager addMarker:[newMarker autorelease] AtLatLong:r4];
129	
130	[self performSelector:@selector(performTestPart2) withObject:nil afterDelay:3.0f]; 
131	[self performSelector:@selector(performTestPart3) withObject:nil afterDelay:7.0f]; 
132}
133
134- (void)applicationDidFinishLaunching:(UIApplication *)application {
135    
136    [window addSubview:[rootViewController view]];
137    [window makeKeyAndVisible];
138	
139	[self performSelector:@selector(performTest) withObject:nil afterDelay:0.25f]; 
140
141}
142
143
144- (void)dealloc {
145    [rootViewController release];
146    [window release];
147    [super dealloc];
148}
149
150@end