Browse files

Cluster zooms in when tapped.

  • Loading branch information...
1 parent 50ffc0e commit b45ae2508adeca04f8cade4a25d9134a19c4093f @rl1987 rl1987 committed Apr 28, 2012
Showing with 53 additions and 21 deletions.
  1. +53 −21 REVClusterMap/REVMapViewController.m
View
74 REVClusterMap/REVMapViewController.m
@@ -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) {
@@ -90,19 +112,28 @@ - (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;
@@ -112,23 +143,24 @@ - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnno
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 b45ae25

Please sign in to comment.