CCHMapClusterController.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // CCHMapClusterController.h
  3. // CCHMapClusterController
  4. //
  5. // Copyright (C) 2013 Claus Höfele
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. //
  25. #import <Foundation/Foundation.h>
  26. #import <MapKit/MapKit.h>
  27. @protocol CCHMapClusterControllerDelegate;
  28. @protocol CCHMapClusterer;
  29. @protocol CCHMapAnimator;
  30. /**
  31. Controller to cluster annotations. Automatically updates clustering when user zooms or pans the map.
  32. */
  33. @interface CCHMapClusterController : NSObject
  34. /** Clustered annotations. */
  35. @property (nonatomic, copy, readonly) NSSet *annotations;
  36. /** Map view to display clustered annotations. */
  37. @property (nonatomic, readonly) MKMapView *mapView;
  38. /** Multiplier to extend visible area that's included for clustering (default: 0.5). */
  39. @property (nonatomic) double marginFactor;
  40. /** Cell size in [points] (default: 60). */
  41. @property (nonatomic) double cellSize;
  42. /** The current zoom level of the visible map region. A zoom level of 0 means that the entire map fits
  43. the screen width. The value increases while zooming in. */
  44. @property (nonatomic, readonly) double zoomLevel;
  45. /** The maximum zoom level before clustering will be disabled and each annotation on the map will
  46. have a unique location (default: `DBL_MAX`). */
  47. @property (nonatomic) double maxZoomLevelForClustering;
  48. /** The minimum number of unique locations before a cell gets clustered (default: 0). */
  49. @property (nonatomic) NSUInteger minUniqueLocationsForClustering;
  50. /** Delegate to configure cluster annotations. */
  51. @property (nonatomic, weak) id<CCHMapClusterControllerDelegate> delegate;
  52. /** Strategy for positioning cluster annotations (default: `CCHCenterOfMassMapClusterer`). */
  53. @property (nonatomic, weak) id<CCHMapClusterer> clusterer;
  54. /** Reuse existing cluster annotations for a cell (default: `YES`). */
  55. @property (nonatomic) BOOL reuseExistingClusterAnnotations;
  56. /** Strategy for animating cluster annotations in and out (default: `CCHFadeInOutMapAnimator`). */
  57. @property (nonatomic, weak) id<CCHMapAnimator> animator;
  58. /** Displays the grid used for clustering. */
  59. @property (nonatomic, getter = isDebuggingEnabled) BOOL debuggingEnabled;
  60. /**
  61. Initializes the cluster controller.
  62. @param mapView `MKMapView` to use to display clusters.
  63. */
  64. - (instancetype)initWithMapView:(MKMapView *)mapView;
  65. /**
  66. Adds annotations and immediately updates clustering.
  67. @param annotations Annotations to add.
  68. @param completionHandler Called when the clustering finished updating.
  69. */
  70. - (void)addAnnotations:(NSArray *)annotations withCompletionHandler:(void (^)(void))completionHandler;
  71. /**
  72. Removes annotations and immediately updates clustering.
  73. @param annotations Annotations to add.
  74. @param completionHandler Called when the clustering finished updating.
  75. */
  76. - (void)removeAnnotations:(NSArray *)annotations withCompletionHandler:(void (^)(void))completionHandler;
  77. /**
  78. Zooms to the position of the cluster that contains the given annotation and selects the cluster's annotation view.
  79. @param annotation The annotation to look for. Uses `isEqual:` to check for a matching annotation previously added with `addAnnotations:withCompletionHandler:`.
  80. @param latitudinalMeters North-to-south distance used for zooming.
  81. @param longitudinalMeters East-to-west distance used for zooming.
  82. */
  83. - (void)selectAnnotation:(id<MKAnnotation>)annotation andZoomToRegionWithLatitudinalMeters:(CLLocationDistance)latitudinalMeters longitudinalMeters:(CLLocationDistance)longitudinalMeters;
  84. @end