-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Conversation
I think it’s too late for this feature to make the impending v3.3.0 final release, but we could easily backport it to v3.3.1 if it takes awhile to release v3.4.0. |
Note that this API does not affect programmatic movement of the viewport, such as via |
This method is called as soon as the user gesture is recognized. It is not | ||
called in response to a programmatic camera change, such as by setting the | ||
`centerCoordinate` property or calling `-flyToCamera:completionHandler:`. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add the standard, “this method is called many times during gesticulation so you should keep it as lightweight as possible”?
This only seems to prevent simple pans, so far. With the new delegate method set to always return |
Oh, you’re right! I took care of all the gesture recognizers for macOS but forgot to follow up for iOS. |
Another caveat about this approach is that, if the delegate decides to block the camera change, the camera actually does change (even sending the |
👍 |
3366aa8
to
11253ec
Compare
11253ec
to
ce3d847
Compare
Any chance to see this in v3.3.1 please? |
platform/ios/src/MGLMapView.mm
Outdated
return camera; | ||
} | ||
|
||
- (double)currentCameraZoom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is unnecessary; use self.zoomLevel
instead.
platform/ios/src/MGLMapView.mm
Outdated
return camera; | ||
} | ||
|
||
- (MGLMapCamera *)currentCameraWithEstimatedDegrees:(CGFloat)degrees anchorPoint:(CGPoint)anchorPoint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use CLLocationDirection
to represent the map’s rotation in degrees.
41c6a5b
to
97e99e8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for hanging in there – just a few nits related to coding style.
platform/ios/src/MGLMapView.mm
Outdated
// Calculates the final camera zoom, has no effect within current map camera. | ||
MGLMapCamera *toCamera; | ||
double zoom = log2(newScale); | ||
toCamera = [self cameraByZoomingToZoomLevel:zoom aroundAnchorPoint:centerPoint]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declare and set toCamera
on the same line.
platform/ios/src/MGLMapView.mm
Outdated
_mbglMap->moveBy({ delta.x, delta.y }); | ||
[pan setTranslation:CGPointZero inView:pan.view]; | ||
|
||
toCamera = [self cameraByPanningWithTranslation:delta panGesture:pan]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the declaration of toCamera
down to this line.
platform/ios/src/MGLMapView.mm
Outdated
|
||
// Calculates the final camera zoom, has no effect within current map camera. | ||
MGLMapCamera *toCamera; | ||
double zoom = log2(newScale); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: declare this a few lines further up to avoid saying log2(newScale)
twice.
platform/ios/src/MGLMapView.mm
Outdated
|
||
[self animateWithDelay:MGLAnimationDuration animations:^ | ||
|
||
MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel:newZoom aroundAnchorPoint:gesturePoint]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: s/newZoom/self.zoomLevel + 1/
e6cec13
to
a3e7277
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One nit left, but otherwise this is good to go.
platform/ios/src/MGLMapView.mm
Outdated
MGLMapCamera *toCamera = [self cameraByPanningWithTranslation:delta panGesture:pan]; | ||
|
||
if (![self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] || | ||
([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is redundant: !A || (A && C)
is equivalent to !A || C
.
My comments in #5584 (review) have been addressed; we’re OK with reporting metrics for aborted gestures; and @incanus’ nits have been addressed as well.
Added a way for the delegate to restrict where the user can move within the map using gestures. Fixes #2457.
… finger drag gestures
a3e7277
to
f9fe145
Compare
f9fe145
to
082e898
Compare
Added a way for the delegate to restrict where the user can move within the map using gestures. This approach allows the developer to restrict to a non-rectangular region or vary the region by zoom level or pitch as necessary, such as to prevent the user from seeing beyond a certain region regardless of the degree of tilt.
This PR intentionally keeps things simple to unblock some key use cases. Future improvements could include implementing a “rubber band” effect, allowing the delegate to “redirect” the camera to some other camera (#2457 (comment)), and automatically restricting the camera to downloaded regions (#5042).
Before we can land this feature:
Fixes #2457.
/cc @boundsj @frederoni @friedbunny