Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 3a313042de
Fetching contributors…

Cannot retrieve contributors at this time

167 lines (121 sloc) 4.798 kb
//
//
// ___ _____ ______ __ _ _________
// / _ \/ __/ | / / __ \/ /| | / / __/ _ \
// / , _/ _/ | |/ / /_/ / /_| |/ / _// , _/
// /_/|_/___/ |___/\____/____/___/___/_/|_|
//
// Created by Bart Claessens. bart (at) revolver . be
//
#import "REVMapViewController.h"
#import "REVClusterMap.h"
#import "REVClusterAnnotationView.h"
#define BASE_RADIUS .5 // = 1 mile
#define MINIMUM_LATITUDE_DELTA 0.20
#define BLOCKS 4
#define MINIMUM_ZOOM_LEVEL 100000
@implementation REVMapViewController
- (void)dealloc
{
[_mapView release], _mapView = nil;
[super dealloc];
}
- (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.
}
#pragma mark - View lifecycle
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
[super loadView];
CGRect viewBounds = [[UIScreen mainScreen] applicationFrame];
_mapView = [[REVClusterMapView alloc] initWithFrame:viewBounds];
_mapView.delegate = self;
[self.view addSubview:_mapView];
CLLocationCoordinate2D coordinate;
coordinate.latitude = 51.22;
coordinate.longitude = 4.39625;
_mapView.region = MKCoordinateRegionMakeWithDistance(coordinate, 5000, 5000);
NSMutableArray *pins = [NSMutableArray array];
for(int i=0;i<50;i++) {
CGFloat latDelta = rand()*0.125/RAND_MAX - 0.02;
CGFloat lonDelta = rand()*0.130/RAND_MAX - 0.08;
CGFloat lat = 51.21992;
CGFloat lng = 4.39625;
CLLocationCoordinate2D newCoord = {lat+latDelta, lng+lonDelta};
REVClusterPin *pin = [[REVClusterPin alloc] init];
pin.title = [NSString stringWithFormat:@"Pin %i",i+1];;
pin.subtitle = [NSString stringWithFormat:@"Pin %i subtitle",i+1];
pin.coordinate = newCoord;
[pins addObject:pin];
[pin release];
}
[_mapView addAnnotations:pins];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[_mapView removeAnnotations:_mapView.annotations];
_mapView.frame = self.view.bounds;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
#pragma mark -
#pragma mark Map view delegate
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if([annotation class] == MKUserLocation.class) {
//userLocation = annotation;
return nil;
}
REVClusterPin *pin = (REVClusterPin *)annotation;
MKAnnotationView *annView;
if( [pin nodeCount] > 0 ){
pin.title = @"___";
annView = (REVClusterAnnotationView*)
[mapView dequeueReusableAnnotationViewWithIdentifier:@"cluster"];
if( !annView )
annView = (REVClusterAnnotationView*)
[[[REVClusterAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:@"cluster"] autorelease];
annView.image = [UIImage imageNamed:@"cluster.png"];
[(REVClusterAnnotationView*)annView setClusterText:
[NSString stringWithFormat:@"%i",[pin nodeCount]]];
annView.canShowCallout = NO;
} else {
annView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"pin"];
if( !annView )
annView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:@"pin"] autorelease];
annView.image = [UIImage imageNamed:@"pinpoint.png"];
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-6.0, 0.0);
}
return annView;
}
- (void)mapView:(MKMapView *)mapView
didSelectAnnotationView:(MKAnnotationView *)view
{
NSLog(@"REVMapViewController mapView didSelectAnnotationView:");
if (![view isKindOfClass:[REVClusterAnnotationView class]])
return;
CLLocationCoordinate2D centerCoordinate = [(REVClusterPin *)view.annotation coordinate];
MKCoordinateSpan newSpan =
MKCoordinateSpanMake(mapView.region.span.latitudeDelta/2.0,
mapView.region.span.longitudeDelta/2.0);
//mapView.region = MKCoordinateRegionMake(centerCoordinate, newSpan);
[mapView setRegion:MKCoordinateRegionMake(centerCoordinate, newSpan)
animated:YES];
}
@end
Jump to Line
Something went wrong with that request. Please try again.