-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add pitch argument to cameraThatFits functions #12213
Changes from 17 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 | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3348,14 +3348,37 @@ - (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edg | |||||||||||||||||
return [self cameraForCameraOptions:cameraOptions]; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets { | ||||||||||||||||||
- (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets | ||||||||||||||||||
{ | ||||||||||||||||||
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); | ||||||||||||||||||
padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); | ||||||||||||||||||
|
||||||||||||||||||
CGFloat pitch = camera.pitch < 0 ? _mbglMap->getPitch() : camera.pitch; | ||||||||||||||||||
CLLocationDirection direction = camera.heading < 0 ? _mbglMap->getBearing() : camera.heading; | ||||||||||||||||||
|
||||||||||||||||||
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]; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction); | ||||||||||||||||||
- (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingShape:(MGLShape *)shape edgePadding:(UIEdgeInsets)insets { | ||||||||||||||||||
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); | ||||||||||||||||||
padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); | ||||||||||||||||||
|
||||||||||||||||||
CGFloat pitch = camera.pitch < 0 ? _mbglMap->getPitch() : camera.pitch; | ||||||||||||||||||
CLLocationDirection direction = camera.heading < 0 ? _mbglMap->getBearing() : camera.heading; | ||||||||||||||||||
|
||||||||||||||||||
mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction, pitch); | ||||||||||||||||||
|
||||||||||||||||||
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 *)cameraForCameraOptions:(const mbgl::CameraOptions &)cameraOptions | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1275,6 +1275,30 @@ - (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edg | |
return [self cameraForCameraOptions:cameraOptions]; | ||
} | ||
|
||
- (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(NSEdgeInsets)insets | ||
{ | ||
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); | ||
padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets); | ||
|
||
CGFloat pitch = camera.pitch < 0 ? _mbglMap->getPitch() : camera.pitch; | ||
CLLocationDirection direction = camera.heading < 0 ? _mbglMap->getBearing() : camera.heading; | ||
|
||
mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), padding, direction, pitch); | ||
return [self cameraForCameraOptions:cameraOptions]; | ||
} | ||
|
||
- (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingShape:(MGLShape *)shape edgePadding:(NSEdgeInsets)insets { | ||
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); | ||
padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets); | ||
|
||
CGFloat pitch = camera.pitch < 0 ? _mbglMap->getPitch() : camera.pitch; | ||
CLLocationDirection direction = camera.heading < 0 ? _mbglMap->getBearing() : camera.heading; | ||
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. When possible, use existing property getters to ensure that normalization is applied consistently: MGLMapCamera *currentCamera = self.camera;
CGFloat pitch = camera.pitch < 0 ? currentCamera.pitch : camera.pitch;
CLLocationDirection direction = camera.heading < 0 ? currentCamera.heading : camera.heading; (There’s also an ×4 |
||
|
||
mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction, pitch); | ||
|
||
return [self cameraForCameraOptions: cameraOptions]; | ||
} | ||
|
||
- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(NSEdgeInsets)insets { | ||
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); | ||
padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets); | ||
|
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,37 @@ 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) { | ||
double pitchAsRadian = *pitch * util::DEG2RAD; // Convert to radians | ||
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. Unlike bearing, negative does not work here. Does this look right to you @asheemmamoowala? 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. Yes thats correct. Bearing is counter clockwise from North, |
||
transform.setPitch(pitchAsRadian); | ||
} | ||
|
||
CameraOptions options = mbgl::cameraForLatLngs(latLngs, transform, padding); | ||
options.angle = transform.getAngle(); | ||
options.pitch = transform.getPitch(); | ||
|
||
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.
Is there a need for a
-camera:fittingCoordinateBounds:edgePadding:
as well?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.
Sure, will add.