Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Get clustered annotations when tapping a cluster pin? #5

Open
jk opened this Issue · 1 comment

2 participants

@jk
jk commented

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

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
Something went wrong with that request. Please try again.