CCHMapClusterAnnotation.m 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // CCHMapClusterAnnotation.m
  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 "CCHMapClusterAnnotation.h"
  26. #import "CCHMapClusterControllerDelegate.h"
  27. #import "CCHMapClusterControllerUtils.h"
  28. @implementation CCHMapClusterAnnotation
  29. - (NSString *)title
  30. {
  31. if (_title == nil && [self.delegate respondsToSelector:@selector(mapClusterController:titleForMapClusterAnnotation:)]) {
  32. _title = [self.delegate mapClusterController:self.mapClusterController titleForMapClusterAnnotation:self];
  33. }
  34. return _title;
  35. }
  36. - (NSString *)subtitle
  37. {
  38. if (_subtitle == nil && [self.delegate respondsToSelector:@selector(mapClusterController:subtitleForMapClusterAnnotation:)]) {
  39. _subtitle = [self.delegate mapClusterController:self.mapClusterController subtitleForMapClusterAnnotation:self];
  40. }
  41. return _subtitle;
  42. }
  43. - (BOOL)isCluster
  44. {
  45. return (self.annotations.count > 1);
  46. }
  47. - (BOOL)isUniqueLocation
  48. {
  49. return CCHMapClusterControllerIsUniqueLocation(self.annotations);
  50. }
  51. - (BOOL)isOneLocation
  52. {
  53. return [self isUniqueLocation];
  54. }
  55. - (MKMapRect)mapRect
  56. {
  57. MKMapPoint clusterPoint = MKMapPointForCoordinate(self.coordinate);
  58. MKMapRect mapRect = MKMapRectMake(clusterPoint.x, clusterPoint.y, 0.1, 0.1);
  59. for (id<MKAnnotation> annotation in self.annotations)
  60. {
  61. MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
  62. MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0.1, 0.1);
  63. mapRect = MKMapRectUnion(mapRect, pointRect);
  64. }
  65. return mapRect;
  66. }
  67. @end