Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios, osx] Avoid transition to current camera
Browse files Browse the repository at this point in the history
Fixes #2456.
  • Loading branch information
1ec5 committed Dec 20, 2015
1 parent d668c0f commit b7223f2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
24 changes: 24 additions & 0 deletions platform/darwin/MGLMapCamera.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions platform/osx/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b7223f2

Please sign in to comment.