-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add pitch argument to cameraThatFits functions #12213
Changes from 3 commits
cf43870
073e497
74a166a
6de4b0a
8e04e6b
d72d77b
3c273bc
f5f7397
3946841
92dac01
0dca9d8
2dab59c
aa4dc6a
28d2cd7
cd5828c
71720d0
d862574
110c70b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -926,6 +926,23 @@ MGL_EXPORT IB_DESIGNABLE | |
*/ | ||
- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets; | ||
|
||
/** | ||
Returns the camera that best fits the given coordinate bounds, optionally with | ||
some additional padding on each side. | ||
|
||
@param bounds The coordinate bounds to fit to the receiver’s viewport. | ||
@param direction The direction of the viewport, measured in degrees clockwise from true north. | ||
@param pitch The viewing angle of the camera, measured in degrees. A value of | ||
`0` results in a camera pointed straight down at the map. Angles greater | ||
than `0` result in a camera angled toward the horizon. | ||
@param insets The minimum padding (in screen points) that would be visible | ||
around the returned camera object if it were set as the receiver’s camera. | ||
@return A camera object centered on the same location as the coordinate bounds | ||
with zoom level as high (close to the ground) as possible while still | ||
including the entire coordinate bounds. | ||
*/ | ||
- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds direction:(CLLocationDirection)direction pitch:(CGFloat)pitch edgePadding:(UIEdgeInsets)insets; | ||
|
||
/** | ||
Returns the camera that best fits the given shape, with the specified direction, | ||
optionally with some additional padding on each side. | ||
|
@@ -940,6 +957,22 @@ MGL_EXPORT IB_DESIGNABLE | |
*/ | ||
- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets; | ||
|
||
/** | ||
Returns the camera that best fits the given shape, with the specified direction and pitch, | ||
optionally with some additional padding on each side. | ||
|
||
@param shape The shape to fit to the receiver’s viewport. | ||
@param direction The direction of the viewport, measured in degrees clockwise from true north. | ||
@param pitch The viewing angle of the camera, measured in degrees. A value of | ||
`0` results in a camera pointed straight down at the map. Angles greater | ||
than `0` result in a camera angled toward the horizon. | ||
@param insets The minimum padding (in screen points) that would be visible | ||
around the returned camera object if it were set as the receiver’s camera. | ||
@return A camera object centered on the shape's center with zoom level as high | ||
(close to the ground) as possible while still including the entire shape. | ||
*/ | ||
- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction pitch:(CGFloat)pitch edgePadding:(UIEdgeInsets)insets; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are some problems with the design of this API:
|
||
|
||
/** | ||
Returns the point in this view’s coordinate system on which to "anchor" in | ||
response to a user-initiated gesture. | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3348,14 +3348,30 @@ - (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edg | |||||||||||||||||
return [self cameraForCameraOptions:cameraOptions]; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets { | ||||||||||||||||||
- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds direction:(CLLocationDirection)direction pitch:(CGFloat)pitch edgePadding:(UIEdgeInsets)insets | ||||||||||||||||||
{ | ||||||||||||||||||
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); | ||||||||||||||||||
padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); | ||||||||||||||||||
mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), padding, direction, pitch); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does mapbox-gl-native/platform/ios/src/MGLMapView.mm Lines 3400 to 3407 in 3946841
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before clamping, we need to check for |
||||||||||||||||||
return [self cameraForCameraOptions:cameraOptions]; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets { | ||||||||||||||||||
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); | ||||||||||||||||||
padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); | ||||||||||||||||||
|
||||||||||||||||||
mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction); | ||||||||||||||||||
|
||||||||||||||||||
return [self cameraForCameraOptions:cameraOptions]; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction pitch:(CGFloat)pitch edgePadding:(UIEdgeInsets)insets { | ||||||||||||||||||
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); | ||||||||||||||||||
padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); | ||||||||||||||||||
|
||||||||||||||||||
mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction, pitch); | ||||||||||||||||||
|
||||||||||||||||||
return [self cameraForCameraOptions:cameraOptions]; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
- (MGLMapCamera *)cameraForCameraOptions:(const mbgl::CameraOptions &)cameraOptions | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -364,13 +364,13 @@ void Map::setLatLngZoom(const LatLng& latLng, double zoom, const EdgeInsets& pad | |
impl->onUpdate(); | ||
} | ||
|
||
CameraOptions Map::cameraForLatLngBounds(const LatLngBounds& bounds, const EdgeInsets& padding, optional<double> bearing) const { | ||
CameraOptions Map::cameraForLatLngBounds(const LatLngBounds& bounds, const EdgeInsets& padding, optional<double> bearing, optional<double> pitch) const { | ||
return cameraForLatLngs({ | ||
bounds.northwest(), | ||
bounds.southwest(), | ||
bounds.southeast(), | ||
bounds.northeast(), | ||
}, padding, bearing); | ||
}, padding, bearing, pitch); | ||
} | ||
|
||
CameraOptions cameraForLatLngs(const std::vector<LatLng>& latLngs, const Transform& transform, const EdgeInsets& padding) { | ||
|
@@ -426,26 +426,41 @@ CameraOptions cameraForLatLngs(const std::vector<LatLng>& latLngs, const Transfo | |
return options; | ||
} | ||
|
||
CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const EdgeInsets& padding, optional<double> bearing) const { | ||
if(bearing) { | ||
double angle = -*bearing * util::DEG2RAD; // Convert to radians | ||
Transform transform(impl->transform.getState()); | ||
transform.setAngle(angle); | ||
CameraOptions options = mbgl::cameraForLatLngs(latLngs, transform, padding); | ||
options.angle = angle; | ||
return options; | ||
} else { | ||
CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const EdgeInsets& padding, optional<double> bearing, optional<double> pitch) const { | ||
|
||
if (!bearing && !pitch) { | ||
return mbgl::cameraForLatLngs(latLngs, impl->transform, padding); | ||
} | ||
|
||
Transform transform(impl->transform.getState()); | ||
|
||
if (bearing) { | ||
double angle = -*bearing * util::DEG2RAD; // Convert to radians | ||
transform.setAngle(angle); | ||
} | ||
if (pitch) { | ||
transform.setPitch(*pitch); | ||
} | ||
|
||
CameraOptions options = mbgl::cameraForLatLngs(latLngs, transform, padding); | ||
|
||
if (bearing) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Angle and pitch can be set on |
||
options.angle = transform.getAngle(); | ||
} | ||
if (pitch) { | ||
options.angle = transform.getAngle(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should set pitch here. |
||
} | ||
|
||
return options; | ||
} | ||
|
||
CameraOptions Map::cameraForGeometry(const Geometry<double>& geometry, const EdgeInsets& padding, optional<double> bearing) const { | ||
CameraOptions Map::cameraForGeometry(const Geometry<double>& geometry, const EdgeInsets& padding, optional<double> bearing, optional<double> pitch) const { | ||
|
||
std::vector<LatLng> latLngs; | ||
forEachPoint(geometry, [&](const Point<double>& pt) { | ||
latLngs.push_back({ pt.y, pt.x }); | ||
}); | ||
return cameraForLatLngs(latLngs, padding, bearing); | ||
return cameraForLatLngs(latLngs, padding, bearing, pitch); | ||
} | ||
|
||
LatLngBounds Map::latLngBoundsForCamera(const CameraOptions& camera) const { | ||
|
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 sentence should indicate that the method lets the developer specify a direction and pitch.