diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-01-13 14:43:45 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-01-14 00:40:45 -0800 |
commit | 02d00662fba34c43f7802adccfa8da0fe4a83f7f (patch) | |
tree | 9e7af8fb7c593d5a6f5661092d73e38bb4196b4e /src | |
parent | 8bad15bf8785bf7d47eef9f1bf3ab86cfa393481 (diff) | |
download | qtlocation-mapboxgl-02d00662fba34c43f7802adccfa8da0fe4a83f7f.tar.gz |
[core] Moved camera methods next to each other
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/transform.cpp | 190 | ||||
-rw-r--r-- | src/mbgl/map/transform.hpp | 10 |
2 files changed, 104 insertions, 96 deletions
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index ab93b84fc0..ca914ee681 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -64,7 +64,7 @@ bool Transform::resize(const std::array<uint16_t, 2> size) { } } -#pragma mark - Position +#pragma mark - Camera /** * Change any combination of center, zoom, bearing, and pitch, without @@ -75,99 +75,6 @@ void Transform::jumpTo(const CameraOptions& camera) { easeTo(camera); } -void Transform::moveBy(const PrecisionPoint& offset, const Duration& duration) { - if (!_validPoint(offset)) { - return; - } - - PrecisionPoint centerOffset = { - offset.x, - -offset.y, - }; - PrecisionPoint centerPoint = state.latLngToPoint(state.getLatLng()) - centerOffset; - - CameraOptions camera; - camera.center = state.pointToLatLng(centerPoint); - easeTo(camera, duration); -} - -void Transform::setLatLng(const LatLng& latLng, const Duration& duration) { - if (!latLng) { - return; - } - - CameraOptions camera; - camera.center = latLng; - easeTo(camera, duration); -} - -void Transform::setLatLng(const LatLng& latLng, const PrecisionPoint& point, const Duration& duration) { - if (!latLng || !point) { - return; - } - - auto coord = state.latLngToCoordinate(latLng); - auto coordAtPoint = state.pointToCoordinate(point); - auto coordCenter = state.pointToCoordinate({ state.width / 2.0f, state.height / 2.0f }); - - float columnDiff = coordAtPoint.column - coord.column; - float rowDiff = coordAtPoint.row - coord.row; - - auto newLatLng = state.coordinateToLatLng({ - coordCenter.column - columnDiff, - coordCenter.row - rowDiff, - coordCenter.zoom - }); - - setLatLng(newLatLng, duration); -} - -void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const Duration& duration) { - if (!latLng || std::isnan(zoom)) { - return; - } - - CameraOptions camera; - camera.center = latLng; - camera.zoom = zoom; - easeTo(camera, duration); -} - - -#pragma mark - Zoom - -void Transform::scaleBy(double ds, const PrecisionPoint& center, const Duration& duration) { - if (std::isnan(ds)) { - return; - } - - double scale = util::clamp(state.scale * ds, state.min_scale, state.max_scale); - setScale(scale, center, duration); -} - -void Transform::setZoom(double zoom, const Duration& duration) { - setScale(state.zoomScale(zoom), {NAN, NAN}, duration); -} - -double Transform::getZoom() const { - return state.getZoom(); -} - -double Transform::getScale() const { - return state.scale; -} - -void Transform::setScale(double scale, const PrecisionPoint& anchor, const Duration& duration) { - if (std::isnan(scale)) { - return; - } - - CameraOptions camera; - camera.zoom = state.scaleZoom(scale); - camera.anchor = anchor; - easeTo(camera, duration); -} - /** * Change any combination of center, zoom, bearing, and pitch, with a smooth animation * between old and new values. The map will retain the current values for any options @@ -489,6 +396,101 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima }, duration); }; +#pragma mark - Position + +void Transform::moveBy(const PrecisionPoint& offset, const Duration& duration) { + if (!_validPoint(offset)) { + return; + } + + PrecisionPoint centerOffset = { + offset.x, + -offset.y, + }; + PrecisionPoint centerPoint = state.latLngToPoint(state.getLatLng()) - centerOffset; + + CameraOptions camera; + camera.center = state.pointToLatLng(centerPoint); + easeTo(camera, duration); +} + +void Transform::setLatLng(const LatLng& latLng, const Duration& duration) { + if (!latLng) { + return; + } + + CameraOptions camera; + camera.center = latLng; + easeTo(camera, duration); +} + +void Transform::setLatLng(const LatLng& latLng, const PrecisionPoint& point, const Duration& duration) { + if (!latLng || !point) { + return; + } + + auto coord = state.latLngToCoordinate(latLng); + auto coordAtPoint = state.pointToCoordinate(point); + auto coordCenter = state.pointToCoordinate({ state.width / 2.0f, state.height / 2.0f }); + + float columnDiff = coordAtPoint.column - coord.column; + float rowDiff = coordAtPoint.row - coord.row; + + auto newLatLng = state.coordinateToLatLng({ + coordCenter.column - columnDiff, + coordCenter.row - rowDiff, + coordCenter.zoom + }); + + setLatLng(newLatLng, duration); +} + +void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const Duration& duration) { + if (!latLng || std::isnan(zoom)) { + return; + } + + CameraOptions camera; + camera.center = latLng; + camera.zoom = zoom; + easeTo(camera, duration); +} + + +#pragma mark - Zoom + +void Transform::scaleBy(double ds, const PrecisionPoint& center, const Duration& duration) { + if (std::isnan(ds)) { + return; + } + + double scale = util::clamp(state.scale * ds, state.min_scale, state.max_scale); + setScale(scale, center, duration); +} + +void Transform::setZoom(double zoom, const Duration& duration) { + setScale(state.zoomScale(zoom), {NAN, NAN}, duration); +} + +double Transform::getZoom() const { + return state.getZoom(); +} + +double Transform::getScale() const { + return state.scale; +} + +void Transform::setScale(double scale, const PrecisionPoint& anchor, const Duration& duration) { + if (std::isnan(scale)) { + return; + } + + CameraOptions camera; + camera.zoom = state.scaleZoom(scale); + camera.anchor = anchor; + easeTo(camera, duration); +} + #pragma mark - Angle void Transform::rotateBy(const PrecisionPoint& first, const PrecisionPoint& second, const Duration& duration) { diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp index 69b09e5a4b..d708d45faf 100644 --- a/src/mbgl/map/transform.hpp +++ b/src/mbgl/map/transform.hpp @@ -24,10 +24,16 @@ public: // Map view bool resize(std::array<uint16_t, 2> size); + // Camera + + /** Instantaneously, synchronously applies the given camera options. */ void jumpTo(const CameraOptions&); + /** Asynchronously transitions all specified camera options linearly along + an optional time curve. */ void easeTo(const CameraOptions&, const AnimationOptions& = {}); - /** Smoothly zooms out, pan, and zoom back into the given camera along a - great circle, as though the viewer is aboard a supersonic jetcopter. */ + /** Asynchronously zooms out, pans, and zooms back into the given camera + along a great circle, as though the viewer is riding a supersonic + jetcopter. */ void flyTo(const CameraOptions&, const AnimationOptions& = {}); // Position |