diff options
Diffstat (limited to 'platform/ios/src/MGLMapView.mm')
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 257167227f..1ccd5ce355 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -58,6 +58,7 @@ #import "MGLStyle_Private.h" #import "MGLStyleLayer_Private.h" #import "MGLMapboxEvents.h" +#import "MGLSDKUpdateChecker.h" #import "MGLCompactCalloutView.h" #import "MGLAnnotationContainerView.h" #import "MGLAnnotationContainerView_Private.h" @@ -350,6 +351,14 @@ public: return self; } ++ (void)initialize +{ + if (self == [MGLMapView self]) + { + [MGLSDKUpdateChecker checkForUpdates]; + } +} + + (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingStyle { return [NSSet setWithObject:@"styleURL"]; @@ -533,14 +542,11 @@ public: _decelerationRate = MGLMapViewDecelerationRateNormal; - if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) - { - _quickZoom = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleQuickZoomGesture:)]; - _quickZoom.numberOfTapsRequired = 1; - _quickZoom.minimumPressDuration = 0; - [_quickZoom requireGestureRecognizerToFail:doubleTap]; - [self addGestureRecognizer:_quickZoom]; - } + _quickZoom = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleQuickZoomGesture:)]; + _quickZoom.numberOfTapsRequired = 1; + _quickZoom.minimumPressDuration = 0; + [_quickZoom requireGestureRecognizerToFail:doubleTap]; + [self addGestureRecognizer:_quickZoom]; // observe app activity // @@ -1242,7 +1248,7 @@ public: if (![self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] || [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera]) { - _mbglMap->moveBy({ offset.x, offset.y }, MGLDurationInSecondsFromTimeInterval(self.decelerationRate)); + _mbglMap->moveBy({ offset.x, offset.y }, MGLDurationFromTimeInterval(self.decelerationRate)); } } @@ -1351,7 +1357,7 @@ public: } else { if (drift) { - _mbglMap->setScale(newScale, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationInSecondsFromTimeInterval(duration)); + _mbglMap->setScale(newScale, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationFromTimeInterval(duration)); } } @@ -1422,7 +1428,7 @@ public: if (![self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] || [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera]) { - _mbglMap->setBearing(newDegrees, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationInSecondsFromTimeInterval(decelerationRate)); + _mbglMap->setBearing(newDegrees, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationFromTimeInterval(decelerationRate)); [self notifyGestureDidEndWithDrift:YES]; @@ -1513,14 +1519,18 @@ public: return nil; } } - + // Handle the case of an offset annotation view by converting the tap point to be the geo location // of the annotation itself that the view represents for (MGLAnnotationView *view in self.annotationContainerView.annotationViews) { if (view.centerOffset.dx != 0 || view.centerOffset.dy != 0) { if (CGRectContainsPoint(view.frame, tapPoint)) { - NSAssert(view.annotation, @"Annotation's view annotation property should not be nil."); + if (!view.annotation) { + [NSException raise:NSInvalidArgumentException + format:@"Annotation view's annotation property should not be nil."]; + } + CGPoint annotationPoint = [self convertCoordinate:view.annotation.coordinate toPointToView:self]; tapPoint = annotationPoint; } @@ -1563,7 +1573,7 @@ public: [self trackGestureEvent:MGLEventGestureDoubleTap forRecognizer:doubleTap]; mbgl::ScreenCoordinate center(gesturePoint.x, gesturePoint.y); - _mbglMap->setZoom(newZoom, center, MGLDurationInSecondsFromTimeInterval(MGLAnimationDuration)); + _mbglMap->setZoom(newZoom, center, MGLDurationFromTimeInterval(MGLAnimationDuration)); __weak MGLMapView *weakSelf = self; @@ -1601,7 +1611,7 @@ public: [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera]) { mbgl::ScreenCoordinate center(gesturePoint.x, gesturePoint.y); - _mbglMap->setZoom(newZoom, center, MGLDurationInSecondsFromTimeInterval(MGLAnimationDuration)); + _mbglMap->setZoom(newZoom, center, MGLDurationFromTimeInterval(MGLAnimationDuration)); __weak MGLMapView *weakSelf = self; @@ -1991,10 +2001,7 @@ public: // Update the annotation’s backing geometry to match the annotation model object. Any associated annotation view is also moved by side effect. However, -updateAnnotationViews disables the view’s animation actions, because it can’t distinguish between moves due to the viewport changing and moves due to the annotation’s coordinate changing. _mbglMap->updateAnnotation(annotationTag, mbgl::SymbolAnnotation { point, symbolName.UTF8String }); - if (annotationTag == _selectedAnnotationTag) - { - [self deselectAnnotation:annotation animated:YES]; - } + [self updateCalloutView]; } } else if ([keyPath isEqualToString:@"coordinates"] && [object isKindOfClass:[MGLMultiPoint class]]) @@ -2011,13 +2018,7 @@ public: { // Update the annotation’s backing geometry to match the annotation model object. _mbglMap->updateAnnotation(annotationTag, [annotation annotationObjectWithDelegate:self]); - - // We don't current support shape multipoint annotation selection, but let's make sure - // deselection is handled just to avoid problems in the future. - if (annotationTag == _selectedAnnotationTag) - { - [self deselectAnnotation:annotation animated:YES]; - } + [self updateCalloutView]; } } } @@ -2431,7 +2432,7 @@ public: mbgl::AnimationOptions animationOptions; if (duration) { - animationOptions.duration.emplace(MGLDurationInSecondsFromTimeInterval(duration)); + animationOptions.duration.emplace(MGLDurationFromTimeInterval(duration)); animationOptions.easing.emplace(MGLUnitBezierForMediaTimingFunction(function)); } if (completion) @@ -2486,7 +2487,7 @@ public: _mbglMap->setZoom(zoomLevel, MGLEdgeInsetsFromNSEdgeInsets(self.contentInset), - MGLDurationInSecondsFromTimeInterval(duration)); + MGLDurationFromTimeInterval(duration)); } - (void)setMinimumZoomLevel:(double)minimumZoomLevel @@ -2595,7 +2596,7 @@ public: mbgl::AnimationOptions animationOptions; if (duration > 0) { - animationOptions.duration.emplace(MGLDurationInSecondsFromTimeInterval(duration)); + animationOptions.duration.emplace(MGLDurationFromTimeInterval(duration)); animationOptions.easing.emplace(MGLUnitBezierForMediaTimingFunction(function)); } if (completion) @@ -2658,13 +2659,13 @@ public: { _mbglMap->setBearing(direction, MGLEdgeInsetsFromNSEdgeInsets(self.contentInset), - MGLDurationInSecondsFromTimeInterval(duration)); + MGLDurationFromTimeInterval(duration)); } else { CGPoint centerPoint = self.userLocationAnnotationViewCenter; _mbglMap->setBearing(direction, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, - MGLDurationInSecondsFromTimeInterval(duration)); + MGLDurationFromTimeInterval(duration)); } } @@ -2709,7 +2710,7 @@ public: mbgl::AnimationOptions animationOptions; if (duration > 0) { - animationOptions.duration.emplace(MGLDurationInSecondsFromTimeInterval(duration)); + animationOptions.duration.emplace(MGLDurationFromTimeInterval(duration)); animationOptions.easing.emplace(MGLUnitBezierForMediaTimingFunction(function)); } if (completion) @@ -2759,7 +2760,7 @@ public: mbgl::AnimationOptions animationOptions; if (duration >= 0) { - animationOptions.duration = MGLDurationInSecondsFromTimeInterval(duration); + animationOptions.duration = MGLDurationFromTimeInterval(duration); } if (peakAltitude >= 0) { @@ -3067,7 +3068,7 @@ public: return annotationContext.annotation; } -/// Returns the annotation tag assigned to the given annotation. Relatively expensive. +/// Returns the annotation tag assigned to the given annotation. - (MGLAnnotationTag)annotationTagForAnnotation:(id <MGLAnnotation>)annotation { if ( ! annotation || annotation == self.userLocation @@ -3107,7 +3108,7 @@ public: NSAssert([annotation conformsToProtocol:@protocol(MGLAnnotation)], @"annotation should conform to MGLAnnotation"); // adding the same annotation object twice is a no-op - if ([self.annotations containsObject:annotation]) + if (_annotationTagsByAnnotation.count(annotation) != 0) { continue; } |