From 42f2da291a41af5248e3c9ccea9531c511f04dee Mon Sep 17 00:00:00 2001 From: Roberto Arreaza Date: Tue, 9 Sep 2014 15:17:35 +0200 Subject: [PATCH] -added minLatitudeDeltaToCluster property, defining the new way to set a zoom level to perform clustering. the reason behind this is because Longitude distances vary too much depending on the latitude value, but latitude does not, thus making it a more suitable value to use for the task. -deprecated the previous minLongitudeDeltaToCluster so that in the next version it will be completely removed (for now it takes both latitude and longitude values into account, to keep version compatibility). --- OCMapView/OCMapView.h | 11 +++++++++-- OCMapView/OCMapView.m | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/OCMapView/OCMapView.h b/OCMapView/OCMapView.h index cbcc9fa..016c4d4 100644 --- a/OCMapView/OCMapView.h +++ b/OCMapView/OCMapView.h @@ -6,6 +6,7 @@ // #import +#import #import "OCDistance.h" #import "OCAnnotation.h" @@ -52,10 +53,16 @@ default: 0.2*/ @property(nonatomic, assign) BOOL clusterByGroupTag; // -/// Defines the "zoom" from where the map should start clustering. +/// Defines the "zoom" from where the map should start clustering, referenced by Longitude. /** If the map is zoomed below this value it won't cluster. default: 0.0 (no min. zoom)*/ -@property(nonatomic, assign) CLLocationDegrees minLongitudeDeltaToCluster; +@property(nonatomic, assign) CLLocationDegrees minLongitudeDeltaToCluster DEPRECATED_MSG_ATTRIBUTE("Use minLatitudeDeltaToCluster instead."); + +// +/// Defines the "zoom" from where the map should start clustering, referenced by Latitude. +/** If the map is zoomed below this value it won't cluster. + default: 0.0 (no min. zoom)*/ +@property(nonatomic, assign) CLLocationDegrees minLatitudeDeltaToCluster; // /// Defines how many annotations are needed to build a cluster diff --git a/OCMapView/OCMapView.m b/OCMapView/OCMapView.m index e3f1ff4..f48f726 100644 --- a/OCMapView/OCMapView.m +++ b/OCMapView/OCMapView.m @@ -47,6 +47,7 @@ - (void)sharedInit _clusteringMethod = OCClusteringMethodBubble; _clusterSize = 0.2; _minLongitudeDeltaToCluster = 0.0; + _minLatitudeDeltaToCluster = 0.0; _minimumAnnotationCountPerCluster = 0; _clusteringEnabled = YES; _clusterByGroupTag = NO; @@ -59,6 +60,7 @@ - (void)sharedInit @"clusterSize", @"clusterByGroupTag", @"minLongitudeDeltaToCluster", + @"minLatitudeDeltaToCluster", @"minimumAnnotationCountPerCluster", @"clusterInvisibleViews", @"annotationsToIgnore"]; @@ -168,7 +170,7 @@ - (void)doClusteringNow // Cluster annotations, when enabled and map is above the minimum zoom NSArray *clusteredAnnotations; - if (_clusteringEnabled && (self_region.span.longitudeDelta > _minLongitudeDeltaToCluster)) + if (_clusteringEnabled && (self_region.span.longitudeDelta > _minLongitudeDeltaToCluster) && (self_region.span.latitudeDelta > _minLatitudeDeltaToCluster) ) { //calculate cluster radius CLLocationDistance clusterRadius = self_region.span.longitudeDelta * _clusterSize;