Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Fix up ::flyTo code.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-mapbox committed Dec 1, 2015
1 parent 0ab2f21 commit c788cea
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/mbgl/map/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ void Transform::_easeTo(CameraOptions options, const double new_scale, const dou

void Transform::flyTo(CameraOptions options) {
LatLng latLng = options.center ? *options.center : getLatLng();
LatLng startLatLng = getLatLng();
double zoom = options.zoom ? *options.zoom : getZoom();
double angle = options.angle ? *options.angle : getAngle();
if (std::isnan(latLng.latitude) || std::isnan(latLng.longitude) || std::isnan(zoom)) {
Expand Down Expand Up @@ -338,13 +339,22 @@ void Transform::flyTo(CameraOptions options) {
double s = k * S;
double us = u(s);

state.scale = startS + std::log2(1 / w(s));
state.x = xn * us;
state.y = yn * us;
//First calculate the desired latlng
double desiredLat = startLatLng.latitude + (latLng.latitude - startLatLng.latitude) * us;
double desiredLng = startLatLng.longitude + (latLng.longitude - startLatLng.longitude) * us;

//Now calculate desired zoom
state.scale = startS - w(s);

//Now set values
const double new_scaled_tile_size = state.scale * util::tileSize;
state.Bc = new_scaled_tile_size / 360;
state.Cc = new_scaled_tile_size / util::M2PI;

const double f2 = std::fmin(std::fmax(std::sin(util::DEG2RAD * desiredLat), -m), m);
state.x = -desiredLng * state.Bc;
state.y = 0.5 * state.Cc * std::log((1 + f2) / (1 - f2));

if (angle != startA) {
state.angle = util::wrap(util::interpolate(startA, angle, k), -M_PI, M_PI);
}
Expand Down

0 comments on commit c788cea

Please sign in to comment.