Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions REMarkerClusterer/REMarkerClusterer.m
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,9 @@ - (void)clusterize:(BOOL)animated
NSMutableArray *remainingAnnotations = [NSMutableArray arrayWithCapacity:0];

for (RECluster *cluster in ((self.markerAnnotations.count > _clusters.count) ? self.markerAnnotations : _clusters)) {
if ([cluster isKindOfClass:[MKUserLocation class]])
continue;
NSInteger numberOfMarkers = 1;
NSMutableArray *posiblesArrays = [NSMutableArray arrayWithCapacity:0];
for (RECluster *cluster2 in ((self.markerAnnotations.count <= _clusters.count)?self.markerAnnotations:_clusters)) {
if ([cluster2 isKindOfClass:[MKUserLocation class]])
continue;
NSInteger markers = [cluster markersInClusterFromMarkers:cluster2.markers];
if(markers >= numberOfMarkers){
[posiblesArrays addObject:cluster2];
Expand Down Expand Up @@ -369,8 +365,6 @@ - (void)clusterize:(BOOL)animated
NSMutableDictionary *mergeators = [NSMutableDictionary dictionaryWithCapacity:0];

for (RECluster *cluster in ((self.markerAnnotations.count <= _clusters.count) ? self.markerAnnotations : _clusters)) {
if ([cluster isKindOfClass:[MKUserLocation class]])
continue;
[mergeators setObject:cluster forKey:cluster.coordinateTag];
}

Expand Down Expand Up @@ -422,7 +416,7 @@ - (NSArray *)markerAnnotations
{
NSMutableArray *annotations = [NSMutableArray array];
for (NSObject *annotation in self.mapView.annotations) {
if ([annotation isKindOfClass:[MKUserLocation class]])
if (![annotation isKindOfClass:[RECluster class]])
continue;

[annotations addObject:annotation];
Expand Down Expand Up @@ -472,7 +466,7 @@ - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnot
return [_delegate mapView:mapView viewForAnnotation:annotation];
}

if ([annotation isKindOfClass:[MKUserLocation class]])
if (![annotation isKindOfClass:[RECluster class]])
return nil;

static NSString *pinID = @"REMarkerClustererPin";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ - (void)segmentedControlChanged:(UISegmentedControl *)segmentedControl

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
if (![view.annotation isKindOfClass:[RECluster class]])
return;

RECluster *cluster = view.annotation;
NSString *message;

Expand All @@ -112,20 +115,21 @@ - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view cal
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
to have custom pin views as goes below:
*/
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(RECluster *)annotation
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
if (![annotation isKindOfClass:[RECluster class]])
return nil;

static NSString *pinID;
static NSString *defaultPinID = @"REDefaultPin";
static NSString *clusterPinID = @"REClusterPin";
static NSString *markerPinID = @"REMarkerPin";

NSArray *markers = ((RECluster *)annotation).markers;
if (self.segmentedControl.selectedSegmentIndex == 0) {
pinID = defaultPinID;
} else {
pinID = annotation.markers.count == 1 ? markerPinID : clusterPinID;
pinID = markers.count == 1 ? markerPinID : clusterPinID;
}

MKPinAnnotationView *pinView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:pinID];
Expand All @@ -141,7 +145,7 @@ - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(RECluster
pinView.canShowCallout = YES;

if (self.segmentedControl.selectedSegmentIndex == 1) {
pinView.image = [UIImage imageNamed:annotation.markers.count == 1 ? @"Pin_Red" : @"Pin_Purple"];
pinView.image = [UIImage imageNamed:markers.count == 1 ? @"Pin_Red" : @"Pin_Purple"];
}
}

Expand Down