[ios] fixes #5127, #5128, #5130 added enabled and selected property to MGLAnnotationView
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -40,6 +40,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
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user