diff options
author | Bobby Sudekum <bobby@mapbox.com> | 2018-07-02 16:30:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-02 16:30:18 -0700 |
commit | 4286d5869c9af0513298b8b31d36744a3243bff4 (patch) | |
tree | 8db8172a0bc9320fb79d9060bddede7cca7ee1b3 /src | |
parent | 29e25356e355d466a60297117f3e7c010825a7ff (diff) | |
download | qtlocation-mapboxgl-4286d5869c9af0513298b8b31d36744a3243bff4.tar.gz |
Add pitch argument to cameraThatFits functions (#12213)
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/map.cpp | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index ea35560e97..c177299485 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -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 + 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 { |