[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.
This commit is contained in:
Minh Nguyễn
2015-12-18 13:17:48 -08:00
committed by Minh Nguyễn
parent 925687ab06
commit a68589b6c7
5 changed files with 161 additions and 61 deletions

View File

@@ -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;
}