Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get clustered annotations when tapping a cluster pin? #5

Open
jk opened this issue Jan 23, 2012 · 1 comment
Open

Get clustered annotations when tapping a cluster pin? #5

jk opened this issue Jan 23, 2012 · 1 comment

Comments

@jk
Copy link

jk commented Jan 23, 2012

Hi there,

I really owe you a beer for putting up REVClusterMap on Github, saved me a lot of time. Thank you.

I've got two views, one is your REVClusterMapView and the other one is a list of annotations. I want to replace the annotations when tapping a cluster pin with its clustered annotations.

I thought I had to implement this in

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view

which wasn't called until I seted the title attribute of the cluster annotations (MKAnnotation documentation says that you have to set the title attribute to show a callout and therefor call the delegate method).

Ok, the delegate method gets called but now I'm a bit lost how to access the clustered annotations within the cluster pin. I've found the RVSAnnotationCollection, so I think this should be possible, can you give me a hint?

@thechrisoshow
Copy link

In order to zoom in on the clustered view and show the unclustered pins I did something like the following:

// In REVClusterAnnotationView
-(MKMapRect)zoomRect {
  MKMapRect zoomRect = MKMapRectNull;
  REVClusterPin *clusterPin = (REVClusterPin *)self.annotation;
  for (id <MKAnnotation> annotation in clusterPin.nodes) {
    MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
    MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0.1, 0.1);
    if (MKMapRectIsNull(zoomRect)) {
      zoomRect = pointRect;
    } else {
      zoomRect = MKMapRectUnion(zoomRect, pointRect);
    }
  }
  return zoomRect;
}

// in your controller
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {

  if (![view isKindOfClass:[REVClusterAnnotationView class]])
    return;

  REVClusterAnnotationView *clusterView = (REVClusterAnnotationView *)view;
    MKMapRect zoomRect = [clusterView zoomRect];

  UIEdgeInsets insets;

  if (IS_IPHONE_5) {
    insets = UIEdgeInsetsMake(120.0, 30.0, 30.0, 30.0);
  } else {
    insets = UIEdgeInsetsMake(60.0, 30.0, 30.0, 30.0);
  }

    [mapView setVisibleMapRect:zoomRect edgePadding:insets animated:NO];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants