diff --git a/platform/darwin/MGLMapCamera.mm b/platform/darwin/MGLMapCamera.mm index 6ebd16ce775..e32ef5a10c1 100644 --- a/platform/darwin/MGLMapCamera.mm +++ b/platform/darwin/MGLMapCamera.mm @@ -98,4 +98,28 @@ - (NSString *)description NSStringFromClass([self class]), self, _centerCoordinate.latitude, _centerCoordinate.longitude, _altitude, _heading, _pitch]; } +- (BOOL)isEqual:(id)other +{ + if ( ! [other isKindOfClass:[self class]]) + { + return NO; + } + if (other == self) + { + return YES; + } + + MGLMapCamera *otherCamera = other; + return (_centerCoordinate.latitude == otherCamera.centerCoordinate.latitude + && _centerCoordinate.longitude == otherCamera.centerCoordinate.longitude + && _altitude == otherCamera.altitude + && _pitch == otherCamera.pitch && _heading == otherCamera.heading); +} + +- (NSUInteger)hash +{ + return (@(_centerCoordinate.latitude).hash + @(_centerCoordinate.longitude).hash + + @(_altitude).hash + @(_pitch).hash + @(_heading).hash); +} + @end diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 7dbce7d2e33..84b82a64047 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1750,6 +1750,11 @@ - (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration a - (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion { + if ([self.camera isEqual:camera]) + { + return; + } + _mbglMap->cancelTransitions(); mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera]; if (duration > 0) @@ -1778,6 +1783,11 @@ - (void)flyToCamera:(MGLMapCamera *)camera completionHandler:(nullable void (^)( - (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion { + if ([self.camera isEqual:camera]) + { + return; + } + _mbglMap->cancelTransitions(); mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera]; if (duration >= 0) diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm index e0d44a2717d..b0f402ff7a2 100644 --- a/platform/osx/src/MGLMapView.mm +++ b/platform/osx/src/MGLMapView.mm @@ -946,6 +946,9 @@ - (void)setCamera:(MGLMapCamera *)camera animated:(BOOL)animated { - (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion { _mbglMap->cancelTransitions(); + if ([self.camera isEqual:camera]) { + return; + } mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera]; if (duration > 0) { @@ -974,6 +977,9 @@ - (void)flyToCamera:(MGLMapCamera *)camera completionHandler:(nullable void (^)( - (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion { _mbglMap->cancelTransitions(); + if ([self.camera isEqual:camera]) { + return; + } mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera]; if (duration >= 0) {