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

Commit b7223f2

Browse files
committed
[ios, osx] Avoid transition to current camera
Fixes #2456.
1 parent d668c0f commit b7223f2

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

platform/darwin/MGLMapCamera.mm

+24
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,28 @@ - (NSString *)description
9898
NSStringFromClass([self class]), self, _centerCoordinate.latitude, _centerCoordinate.longitude, _altitude, _heading, _pitch];
9999
}
100100

101+
- (BOOL)isEqual:(id)other
102+
{
103+
if ( ! [other isKindOfClass:[self class]])
104+
{
105+
return NO;
106+
}
107+
if (other == self)
108+
{
109+
return YES;
110+
}
111+
112+
MGLMapCamera *otherCamera = other;
113+
return (_centerCoordinate.latitude == otherCamera.centerCoordinate.latitude
114+
&& _centerCoordinate.longitude == otherCamera.centerCoordinate.longitude
115+
&& _altitude == otherCamera.altitude
116+
&& _pitch == otherCamera.pitch && _heading == otherCamera.heading);
117+
}
118+
119+
- (NSUInteger)hash
120+
{
121+
return (@(_centerCoordinate.latitude).hash + @(_centerCoordinate.longitude).hash
122+
+ @(_altitude).hash + @(_pitch).hash + @(_heading).hash);
123+
}
124+
101125
@end

platform/ios/src/MGLMapView.mm

+10
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,11 @@ - (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration a
17501750

17511751
- (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion
17521752
{
1753+
if ([self.camera isEqual:camera])
1754+
{
1755+
return;
1756+
}
1757+
17531758
_mbglMap->cancelTransitions();
17541759
mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera];
17551760
if (duration > 0)
@@ -1778,6 +1783,11 @@ - (void)flyToCamera:(MGLMapCamera *)camera completionHandler:(nullable void (^)(
17781783

17791784
- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion
17801785
{
1786+
if ([self.camera isEqual:camera])
1787+
{
1788+
return;
1789+
}
1790+
17811791
_mbglMap->cancelTransitions();
17821792
mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera];
17831793
if (duration >= 0)

platform/osx/src/MGLMapView.mm

+6
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,9 @@ - (void)setCamera:(MGLMapCamera *)camera animated:(BOOL)animated {
946946

947947
- (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion {
948948
_mbglMap->cancelTransitions();
949+
if ([self.camera isEqual:camera]) {
950+
return;
951+
}
949952

950953
mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera];
951954
if (duration > 0) {
@@ -974,6 +977,9 @@ - (void)flyToCamera:(MGLMapCamera *)camera completionHandler:(nullable void (^)(
974977

975978
- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion {
976979
_mbglMap->cancelTransitions();
980+
if ([self.camera isEqual:camera]) {
981+
return;
982+
}
977983

978984
mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera];
979985
if (duration >= 0) {

0 commit comments

Comments
 (0)