Adjust zoom factor and target zoom to remain between minZoom and maxZoom
Showing
2 changed files
with
14 additions
and
0 deletions
@@ -480,8 +480,17 @@ | @@ -480,8 +480,17 @@ | ||
480 | return; | 480 | return; |
481 | } | 481 | } |
482 | // clamp zoom to remain below or equal to maxZoom after zoomAfter will be applied | 482 | // clamp zoom to remain below or equal to maxZoom after zoomAfter will be applied |
483 | + // Set targetZoom to maxZoom so the map zooms to its maximum | ||
483 | if(targetZoom > [self maxZoom]){ | 484 | if(targetZoom > [self maxZoom]){ |
484 | zoomFactor = exp2f([self maxZoom] - [self zoom]); | 485 | zoomFactor = exp2f([self maxZoom] - [self zoom]); |
486 | + targetZoom = [self maxZoom]; | ||
487 | + } | ||
488 | + | ||
489 | + // clamp zoom to remain above or equal to minZoom after zoomAfter will be applied | ||
490 | + // Set targetZoom to minZoom so the map zooms to its maximum | ||
491 | + if(targetZoom < [self minZoom]){ | ||
492 | + zoomFactor = 1/exp2f([self zoom] - [self minZoom]); | ||
493 | + targetZoom = [self minZoom]; | ||
485 | } | 494 | } |
486 | 495 | ||
487 | if ([self shouldZoomToTargetZoom:targetZoom withZoomFactor:zoomFactor]) | 496 | if ([self shouldZoomToTargetZoom:targetZoom withZoomFactor:zoomFactor]) |
@@ -293,6 +293,11 @@ | @@ -293,6 +293,11 @@ | ||
293 | _zoomFactor = exp2f([self.contents maxZoom] - [self.contents zoom]); | 293 | _zoomFactor = exp2f([self.contents maxZoom] - [self.contents zoom]); |
294 | } | 294 | } |
295 | 295 | ||
296 | + // clamp zoom to remain above or equal to minZoom after zoomAfter will be applied | ||
297 | + if(targetZoom < [self.contents minZoom]){ | ||
298 | + zoomFactor = 1/exp2f([self.contents zoom] - [self.contents minZoom]); | ||
299 | + } | ||
300 | + | ||
296 | //bools for syntactical sugar to understand the logic in the if statement below | 301 | //bools for syntactical sugar to understand the logic in the if statement below |
297 | BOOL zoomAtMax = ([self.contents zoom] == [self.contents maxZoom]); | 302 | BOOL zoomAtMax = ([self.contents zoom] == [self.contents maxZoom]); |
298 | BOOL zoomAtMin = ([self.contents zoom] == [self.contents minZoom]); | 303 | BOOL zoomAtMin = ([self.contents zoom] == [self.contents minZoom]); |
-
Please register or login to post a comment