diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2015-12-18 13:17:48 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2015-12-19 20:48:34 -0800 |
commit | a68589b6c7ace5d3fc9f03a1c44ae2f26c15df7e (patch) | |
tree | 370d3387035a2a032ac68192c7372e7fe14e087b /src/mbgl/map/transform_state.cpp | |
parent | 925687ab06892528f25fd4a79d27a55560634d96 (diff) | |
download | qtlocation-mapboxgl-a68589b6c7ace5d3fc9f03a1c44ae2f26c15df7e.tar.gz |
[core] Refined and commented flyTo
Rewrote the flyTo implementation to more closely match GL JS’s implementation and the paper on which it is based.
Rewrote CameraOptions documentation. Only document units for generic types like double. The semantics of LatLng and Duration are already baked into the types; one just needs to look up the types’ definitions. Also, the […) is set notation, so the braces are supposed to be mismatched.
Fixes #3296.
Diffstat (limited to 'src/mbgl/map/transform_state.cpp')
-rw-r--r-- | src/mbgl/map/transform_state.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index f608edb10b..ccc5ab365a 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -4,6 +4,7 @@ #include <mbgl/util/box.hpp> #include <mbgl/util/tile_coordinate.hpp> #include <mbgl/util/interpolate.hpp> +#include <mbgl/util/math.hpp> using namespace mbgl; @@ -370,4 +371,32 @@ void TransformState::constrain(double& scale_, double& x_, double& y_) const { y_ = std::max(-max_y, std::min(y_, max_y)); } +void TransformState::setLatLngZoom(const LatLng &latLng, double zoom) { + double newScale = zoomScale(zoom); + const double newWorldSize = newScale * util::tileSize; + Bc = newWorldSize / 360; + Cc = newWorldSize / util::M2PI; + + const double m = 1 - 1e-15; + const double f = util::clamp(std::sin(util::DEG2RAD * latLng.latitude), -m, m); + + PrecisionPoint point = { + -latLng.longitude * Bc, + 0.5 * Cc * std::log((1 + f) / (1 - f)), + }; + setScalePoint(newScale, point); +} + +void TransformState::setScalePoint(const double newScale, const PrecisionPoint &point) { + double constrainedScale = newScale; + PrecisionPoint constrainedPoint = point; + constrain(constrainedScale, constrainedPoint.x, constrainedPoint.y); + + scale = constrainedScale; + x = constrainedPoint.x; + y = constrainedPoint.y; + Bc = worldSize() / 360; + Cc = worldSize() / util::M2PI; +} + |