//
//  MapConfig.m
//  Agence
//
//  Created by Olivier Savard on 11-01-28.
//  Copyright 2011 OSInfo Informatique. All rights reserved.
//

#import "MapConfig.h"
#import "PickerViewController.h"
#import "AgenceAppDelegate.h"
#import "MapViewController.h"


@implementation MapConfig




@synthesize picker;
@synthesize pickerData;
@synthesize locationCentre;



-(IBAction)buttonPressed
{
	NSInteger row = [picker selectedRowInComponent:0];
	AgenceAppDelegate * appDelegate = (AgenceAppDelegate *)[[UIApplication sharedApplication] delegate];
	CLLocationCoordinate2D centre;
	switch (row) {
		case 0:
		{
			centre.latitude = 45.766667;
			centre.longitude = -74;
		}
			break;
		case 1:
		{
			centre.latitude = 45.9;
			centre.longitude = -74.166667;
		}
			break;
		case 2:
		{
			centre.latitude = 46.033333;
			centre.longitude = -74.283333;
		}
			break;
		default:
			break;
	}
	appDelegate.locationCentre = centre;
	MapViewController *map = [[MapViewController alloc]initWithNibName:@"MapViewController" bundle:nil];
	map.title = [pickerData objectAtIndex:row];
	[self.navigationController pushViewController:map animated:YES];
	[map release];
}

-(void)viewWillAppear{
	[picker selectRow:1 inComponent:0 animated:YES];
}

- (void)viewDidLoad {
	self.title = @"Région";
	NSArray *array = [[NSArray alloc] initWithObjects:@"St-Jérôme",@"St-Sauveur", @"Ste-Agathe", nil];	
	self.pickerData = array;
	[picker selectRow:1 inComponent:0 animated:YES];
	

	[array release];
    [super viewDidLoad];
}


/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations.
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
	self.picker = nil;
    self.pickerData = nil;
	[super viewDidUnload];
}


- (void)dealloc {
	[picker release];
	[pickerData release];
    [super dealloc];
}

#pragma mark -
#pragma mark Picker Data Source Methods
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
	return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
	return [pickerData count];
}

#pragma mark Picker Delegate Methods
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
	return [pickerData objectAtIndex:row];
}


@end
