Skip to content

Commit

Permalink
Merge pull request #7 from rl1987/master
Browse files Browse the repository at this point in the history
Slight improvements.
  • Loading branch information
RVLVR committed May 14, 2012
2 parents 3f5afa8 + b45ae25 commit 3a31304
Showing 1 changed file with 55 additions and 21 deletions.
76 changes: 55 additions & 21 deletions REVClusterMap/REVMapViewController.m
Expand Up @@ -78,6 +78,28 @@ - (void)loadView

}

- (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) {
Expand All @@ -90,43 +112,55 @@ - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnno
MKAnnotationView *annView;

if( [pin nodeCount] > 0 ){
annView = (REVClusterAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"cluster"];
pin.title = @"___";

annView = (REVClusterAnnotationView*)
[mapView dequeueReusableAnnotationViewWithIdentifier:@"cluster"];

if( !annView )
annView = (REVClusterAnnotationView*)[[[REVClusterAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"cluster"] autorelease];
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 = YES;

[(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 = [[[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)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
- (void)mapView:(MKMapView *)mapView
didSelectAnnotationView:(MKAnnotationView *)view
{
// Return YES for supported orientations
return YES;
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

0 comments on commit 3a31304

Please sign in to comment.