PageRenderTime 19ms CodeModel.GetById 1ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 1ms

/samples/MapTestbedFlipMaps/Classes/FlipsideViewController.m

http://github.com/route-me/route-me
Objective C | 106 lines | 65 code | 27 blank | 14 comment | 1 complexity | d666f83eaf9ffe2f743116479113a49d MD5 | raw file
  1//
  2//  FlipsideViewController.m
  3//  MapTestbed : Diagnostic map
  4//
  5
  6#import "FlipsideViewController.h"
  7#import "MapTestbedAppDelegate.h"
  8#import "RMMarker.h"
  9#import "RMMarkerManager.h"
 10
 11
 12@implementation FlipsideViewController
 13
 14@synthesize mapView;
 15@synthesize infoTextView;
 16
 17- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
 18    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
 19        // Custom initialization
 20    }
 21    return self;
 22}
 23
 24
 25// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
 26- (void)viewDidLoad {
 27    [super viewDidLoad];
 28    [mapView setDelegate:self];
 29    [self updateInfo];
 30    
 31    RMMarkerManager *markerManager = [mapView markerManager];
 32	NSAssert(markerManager, @"null markerManager returned");
 33    RMMarker *marker = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"marker-blue.png"]
 34											 anchorPoint:CGPointMake(0.5, 1.0)];
 35	[marker setTextForegroundColor:[UIColor blueColor]];
 36	[marker changeLabelUsingText:@"Hello"];
 37	[markerManager addMarker:marker AtLatLong:[[mapView contents] mapCenter]];
 38	[marker release];
 39}
 40
 41
 42/*
 43 // Override to allow orientations other than the default portrait orientation.
 44 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 45 // Return YES for supported orientations
 46 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 47 }
 48*/
 49
 50
 51- (void)didReceiveMemoryWarning {
 52    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
 53    // Release anything that's not essential, such as cached data
 54}
 55
 56- (void)viewDidAppear:(BOOL)animated {
 57    [self updateInfo];
 58}
 59
 60- (void)dealloc {
 61    self.infoTextView = nil; 
 62    self.mapView = nil; 
 63    [super dealloc];
 64}
 65
 66- (void)updateInfo {
 67	RMMapContents *contents = self.mapView.contents;
 68    CLLocationCoordinate2D mapCenter = [contents mapCenter];
 69    
 70    float routemeMetersPerPixel = [contents metersPerPixel]; 
 71	double truescaleDenominator =  [contents scaleDenominator];
 72    
 73    [infoTextView setText:[NSString stringWithFormat:@"Latitude : %f\nLongitude : %f\nZoom level : %.2f\nMeter per pixel : %.1f\nTrue scale : 1:%.0f", 
 74                           mapCenter.latitude, 
 75                           mapCenter.longitude, 
 76                           contents.zoom, 
 77                           routemeMetersPerPixel,
 78                           truescaleDenominator]];
 79}
 80
 81#pragma mark -
 82#pragma mark Delegate methods
 83
 84- (void)mapView:(RMMapView *)map didDragMarker:(RMMarker *)marker withEvent:(UIEvent *)event 
 85{
 86   CGPoint position = [[[event allTouches] anyObject] locationInView:mapView];
 87   
 88	RMMarkerManager *markerManager = [mapView markerManager];
 89
 90	NSLog(@"New location: X:%lf Y:%lf", [marker projectedLocation].easting, [marker projectedLocation].northing);
 91	CGRect rect = [marker bounds];
 92	
 93	[markerManager moveMarker:marker AtXY:CGPointMake(position.x,position.y +rect.size.height/3)];
 94
 95}
 96
 97- (void) afterMapMove: (RMMapView*) map {
 98    [self updateInfo];
 99}
100
101- (void) afterMapZoom: (RMMapView*) map byFactor: (float) zoomFactor near:(CGPoint) center {
102    [self updateInfo];
103}
104
105
106@end