Authored by Justin R. Miller

fixes #92: properly order user location annotations & disallow gestures

@@ -22,4 +22,6 @@ @@ -22,4 +22,6 @@
22 22
23 - (void)moveLayersBy:(CGPoint)delta; 23 - (void)moveLayersBy:(CGPoint)delta;
24 24
  25 +- (CALayer *)overlayHitTest:(CGPoint)point;
  26 +
25 @end 27 @end
@@ -10,8 +10,14 @@ @@ -10,8 +10,14 @@
10 #import "RMMarker.h" 10 #import "RMMarker.h"
11 #import "RMAnnotation.h" 11 #import "RMAnnotation.h"
12 #import "RMPixel.h" 12 #import "RMPixel.h"
  13 +#import "RMMapView.h"
13 14
14 @implementation RMMapOverlayView 15 @implementation RMMapOverlayView
  16 +{
  17 + RMAnnotation *_userLocationAnnotation;
  18 + RMAnnotation *_accuracyCircleAnnotation;
  19 + RMAnnotation *_trackingHaloAnnotation;
  20 +}
15 21
16 + (Class)layerClass 22 + (Class)layerClass
17 { 23 {
@@ -58,4 +64,30 @@ @@ -58,4 +64,30 @@
58 [self.layer scrollPoint:CGPointMake(-delta.x, -delta.y)]; 64 [self.layer scrollPoint:CGPointMake(-delta.x, -delta.y)];
59 } 65 }
60 66
  67 +- (CALayer *)overlayHitTest:(CGPoint)point
  68 +{
  69 + RMMapView *mapView = ((RMMapView *)self.superview);
  70 +
  71 + if ( ! _userLocationAnnotation)
  72 + _userLocationAnnotation = (RMAnnotation *)mapView.userLocation;
  73 +
  74 + if ( ! _accuracyCircleAnnotation)
  75 + for (RMAnnotation *annotation in mapView.annotations)
  76 + if ([annotation.annotationType isEqualToString:kRMAccuracyCircleAnnotationTypeName])
  77 + _accuracyCircleAnnotation = annotation;
  78 +
  79 + if ( ! _trackingHaloAnnotation)
  80 + for (RMAnnotation *annotation in mapView.annotations)
  81 + if ([annotation.annotationType isEqualToString:kRMTrackingHaloAnnotationTypeName])
  82 + _trackingHaloAnnotation = annotation;
  83 +
  84 + _userLocationAnnotation.layer.hidden = _accuracyCircleAnnotation.layer.hidden = _trackingHaloAnnotation.layer.hidden = YES;
  85 +
  86 + CALayer *hit = [self.layer hitTest:point];
  87 +
  88 + _userLocationAnnotation.layer.hidden = _accuracyCircleAnnotation.layer.hidden = _trackingHaloAnnotation.layer.hidden = NO;
  89 +
  90 + return hit;
  91 +}
  92 +
61 @end 93 @end
@@ -1343,7 +1343,7 @@ @@ -1343,7 +1343,7 @@
1343 1343
1344 - (void)handleSingleTap:(UIGestureRecognizer *)recognizer 1344 - (void)handleSingleTap:(UIGestureRecognizer *)recognizer
1345 { 1345 {
1346 - CALayer *hit = [_overlayView.layer hitTest:[recognizer locationInView:self]]; 1346 + CALayer *hit = [_overlayView overlayHitTest:[recognizer locationInView:self]];
1347 1347
1348 if ( ! hit) 1348 if ( ! hit)
1349 { 1349 {
@@ -1393,7 +1393,7 @@ @@ -1393,7 +1393,7 @@
1393 1393
1394 - (void)handleDoubleTap:(UIGestureRecognizer *)recognizer 1394 - (void)handleDoubleTap:(UIGestureRecognizer *)recognizer
1395 { 1395 {
1396 - CALayer *hit = [_overlayView.layer hitTest:[recognizer locationInView:self]]; 1396 + CALayer *hit = [_overlayView overlayHitTest:[recognizer locationInView:self]];
1397 1397
1398 if ( ! hit) 1398 if ( ! hit)
1399 { 1399 {
@@ -1450,7 +1450,7 @@ @@ -1450,7 +1450,7 @@
1450 if ([recognizer isKindOfClass:[UIPanGestureRecognizer class]]) 1450 if ([recognizer isKindOfClass:[UIPanGestureRecognizer class]])
1451 { 1451 {
1452 // check whether our custom pan gesture recognizer should start recognizing the gesture 1452 // check whether our custom pan gesture recognizer should start recognizing the gesture
1453 - CALayer *hit = [_overlayView.layer hitTest:[recognizer locationInView:_overlayView]]; 1453 + CALayer *hit = [_overlayView overlayHitTest:[recognizer locationInView:_overlayView]];
1454 1454
1455 if ([hit isEqual:_overlayView.layer]) 1455 if ([hit isEqual:_overlayView.layer])
1456 return NO; 1456 return NO;
@@ -2789,6 +2789,7 @@ @@ -2789,6 +2789,7 @@
2789 accuracyCircleAnnotation.annotationType = kRMAccuracyCircleAnnotationTypeName; 2789 accuracyCircleAnnotation.annotationType = kRMAccuracyCircleAnnotationTypeName;
2790 accuracyCircleAnnotation.clusteringEnabled = NO; 2790 accuracyCircleAnnotation.clusteringEnabled = NO;
2791 accuracyCircleAnnotation.layer = [[RMCircle alloc] initWithView:self radiusInMeters:newLocation.horizontalAccuracy]; 2791 accuracyCircleAnnotation.layer = [[RMCircle alloc] initWithView:self radiusInMeters:newLocation.horizontalAccuracy];
  2792 + accuracyCircleAnnotation.layer.zPosition = -MAXFLOAT;
2792 accuracyCircleAnnotation.isUserLocationAnnotation = YES; 2793 accuracyCircleAnnotation.isUserLocationAnnotation = YES;
2793 2794
2794 ((RMCircle *)accuracyCircleAnnotation.layer).lineColor = [UIColor colorWithRed:0.378 green:0.552 blue:0.827 alpha:0.7]; 2795 ((RMCircle *)accuracyCircleAnnotation.layer).lineColor = [UIColor colorWithRed:0.378 green:0.552 blue:0.827 alpha:0.7];
@@ -2822,6 +2823,7 @@ @@ -2822,6 +2823,7 @@
2822 // create image marker 2823 // create image marker
2823 // 2824 //
2824 trackingHaloAnnotation.layer = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"TrackingDotHalo.png"]]; 2825 trackingHaloAnnotation.layer = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"TrackingDotHalo.png"]];
  2826 + trackingHaloAnnotation.layer.zPosition = -MAXFLOAT + 1;
2825 trackingHaloAnnotation.isUserLocationAnnotation = YES; 2827 trackingHaloAnnotation.isUserLocationAnnotation = YES;
2826 2828
2827 [CATransaction begin]; 2829 [CATransaction begin];
@@ -25,6 +25,8 @@ @@ -25,6 +25,8 @@
25 25
26 layer = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"TrackingDot.png"]]; 26 layer = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"TrackingDot.png"]];
27 27
  28 + layer.zPosition = -MAXFLOAT + 2;
  29 +
28 annotationType = [kRMUserLocationAnnotationTypeName retain]; 30 annotationType = [kRMUserLocationAnnotationTypeName retain];
29 31
30 clusteringEnabled = NO; 32 clusteringEnabled = NO;