summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorFredrik Karlsson <bjorn.fredrik.karlsson@gmail.com>2016-06-14 10:36:41 +0200
committerGitHub <noreply@github.com>2016-06-14 10:36:41 +0200
commita557e1e2c9f76a9b01d2a973a9a162e14525a669 (patch)
tree4acfbab5d11ce337952b2d4b734e646b7fc4629d /platform
parent19c34fe1f05c6a7af1d7c0492a52454934223857 (diff)
downloadqtlocation-mapboxgl-a557e1e2c9f76a9b01d2a973a9a162e14525a669.tar.gz
[ios] fixes #5127, #5128, #5130 added enabled and selected property to MGLAnnotationView (#5297)
[ios] fixes #5127, #5128, #5130 added enabled and selected property to MGLAnnotationView
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/app/MBXAnnotationView.m8
-rw-r--r--platform/ios/src/MGLAnnotationView.h20
-rw-r--r--platform/ios/src/MGLAnnotationView.mm13
-rw-r--r--platform/ios/src/MGLMapView.mm30
-rw-r--r--platform/ios/src/MGLMapViewDelegate.h21
5 files changed, 90 insertions, 2 deletions
diff --git a/platform/ios/app/MBXAnnotationView.m b/platform/ios/app/MBXAnnotationView.m
index 890881a316..f3afe936d5 100644
--- a/platform/ios/app/MBXAnnotationView.m
+++ b/platform/ios/app/MBXAnnotationView.m
@@ -25,4 +25,12 @@
}
}
+- (void)setSelected:(BOOL)selected animated:(BOOL)animated
+{
+ [super setSelected:selected animated:animated];
+
+ self.layer.borderColor = selected ? [UIColor blackColor].CGColor : [UIColor whiteColor].CGColor;
+ self.layer.borderWidth = selected ? 2.0 : 0;
+}
+
@end
diff --git a/platform/ios/src/MGLAnnotationView.h b/platform/ios/src/MGLAnnotationView.h
index 5b8091e7b4..acf270dfcb 100644
--- a/platform/ios/src/MGLAnnotationView.h
+++ b/platform/ios/src/MGLAnnotationView.h
@@ -41,6 +41,26 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign, getter=isFlat) BOOL flat;
/**
+ Defaults to NO and becomes YES when the view is tapped on.
+
+ Selecting another view will first deselect the currently selected view.
+ This property should not be changed directly.
+ */
+@property (nonatomic, assign, getter=isSelected) BOOL selected;
+
+/**
+ Subclasses may override this method in order to customize appearance.
+ This method should not be called directly.
+ */
+- (void)setSelected:(BOOL)selected animated:(BOOL)animated;
+
+/*
+ This property defaults to YES. Setting it to NO will cause the annotation view to ignore all touch events.
+ Subclasses may use this property to customize the appearance.
+ */
+@property (nonatomic, assign, getter=isEnabled) BOOL enabled;
+
+/**
Setting this property to YES will cause the annotation view to shrink as it approaches the horizon and grow as it moves away from the
horizon when the associated map view is tilted. Conversely, setting this property to NO will ensure that the annotation view maintains
a constant size even when the map view is tilted. To maintain consistency with annotation representations that are not backed by an
diff --git a/platform/ios/src/MGLAnnotationView.mm b/platform/ios/src/MGLAnnotationView.mm
index 31657dbf4e..1a95beb23d 100644
--- a/platform/ios/src/MGLAnnotationView.mm
+++ b/platform/ios/src/MGLAnnotationView.mm
@@ -22,6 +22,7 @@
{
_reuseIdentifier = [reuseIdentifier copy];
_scalesWithViewingDistance = YES;
+ _enabled = YES;
}
return self;
}
@@ -37,6 +38,18 @@
self.center = self.center;
}
+- (void)setSelected:(BOOL)selected
+{
+ [self setSelected:selected animated:NO];
+}
+
+- (void)setSelected:(BOOL)selected animated:(BOOL)animated
+{
+ [self willChangeValueForKey:@"selected"];
+ _selected = selected;
+ [self didChangeValueForKey:@"selected"];
+}
+
- (void)setCenter:(CGPoint)center
{
[self setCenter:center pitch:0];
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 6549ca16ec..90e0186429 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -3382,17 +3382,22 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
// By default attempt to use the GL annotation image frame as the positioning rect.
CGRect positioningRect = [self positioningRectForCalloutForAnnotationWithTag:annotationTag];
+ MGLAnnotationView *annotationView = nil;
+
if (annotation != self.userLocation)
{
MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(annotationTag);
- MGLAnnotationView *annotationView = annotationContext.annotationView;
- if (annotationView)
+ annotationView = annotationContext.annotationView;
+
+ if (annotationView && annotationView.enabled)
{
// Annotations represented by views use the view frame as the positioning rect.
positioningRect = annotationView.frame;
[annotationView.superview bringSubviewToFront:annotationView];
+
+ annotationView.selected = YES;
}
}
@@ -3474,6 +3479,11 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
[self.delegate mapView:self didSelectAnnotation:annotation];
}
+
+ if (annotationView && [self.delegate respondsToSelector:@selector(mapView:didSelectAnnotationView:)])
+ {
+ [self.delegate mapView:self didSelectAnnotationView:annotationView];
+ }
}
- (MGLCompactCalloutView *)calloutViewForAnnotation:(id <MGLAnnotation>)annotation
@@ -3546,6 +3556,17 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
// dismiss popup
[self.calloutViewForSelectedAnnotation dismissCalloutAnimated:animated];
+
+ // deselect annotation view
+ MGLAnnotationView *annotationView = nil;
+ MGLAnnotationTag annotationTag = [self annotationTagForAnnotation:annotation];
+
+ if (annotationTag != MGLAnnotationTagNotFound)
+ {
+ MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(annotationTag);
+ annotationView = annotationContext.annotationView;
+ annotationView.selected = NO;
+ }
// clean up
self.calloutViewForSelectedAnnotation = nil;
@@ -3556,6 +3577,11 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
[self.delegate mapView:self didDeselectAnnotation:annotation];
}
+
+ if (annotationView && [self.delegate respondsToSelector:@selector(mapView:didDeselectAnnotationView:)])
+ {
+ [self.delegate mapView:self didDeselectAnnotationView:annotationView];
+ }
}
}
diff --git a/platform/ios/src/MGLMapViewDelegate.h b/platform/ios/src/MGLMapViewDelegate.h
index 39eb43d4ca..0833b7ace3 100644
--- a/platform/ios/src/MGLMapViewDelegate.h
+++ b/platform/ios/src/MGLMapViewDelegate.h
@@ -279,6 +279,27 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)mapView:(MGLMapView *)mapView didDeselectAnnotation:(id <MGLAnnotation>)annotation;
+
+/**
+ Tells the delegate that one of its annotation views was selected.
+
+ You can use this method to track changes in the selection state of annotation views.
+
+ @param mapView The map view containing the annotation.
+ @param annotationView The annotation view that was selected.
+ */
+- (void)mapView:(MGLMapView *)mapView didSelectAnnotationView:(MGLAnnotationView *)annotationView;
+
+/**
+ Tells the delegate that one of its annotation views was deselected.
+
+ You can use this method to track changes in the selection state of annotation views.
+
+ @param mapView The map view containing the annotation.
+ @param annotationView The annotation view that was deselected.
+ */
+- (void)mapView:(MGLMapView *)mapView didDeselectAnnotationView:(MGLAnnotationView *)annotationView;
+
@end
NS_ASSUME_NONNULL_END