[core] Consolidated zoom and angle anchor logic

Made anchor a CameraOption for easeTo().
This commit is contained in:
Minh Nguyễn
2016-01-13 00:47:50 -08:00
committed by Minh Nguyễn
parent a3d4aeefec
commit 8bad15bf87
6 changed files with 90 additions and 35 deletions

View File

@@ -369,6 +369,26 @@ void TransformState::constrain(double& scale_, double& x_, double& y_) const {
y_ = std::max(-max_y, std::min(y_, max_y));
}
void TransformState::moveLatLng(const LatLng& latLng, const PrecisionPoint& anchor) {
if (!latLng || !anchor) {
return;
}
auto coord = latLngToCoordinate(latLng);
auto coordAtPoint = pointToCoordinate(anchor);
auto coordCenter = pointToCoordinate({ width / 2.0f, height / 2.0f });
float columnDiff = coordAtPoint.column - coord.column;
float rowDiff = coordAtPoint.row - coord.row;
auto newLatLng = coordinateToLatLng({
coordCenter.column - columnDiff,
coordCenter.row - rowDiff,
coordCenter.zoom
});
setLatLngZoom(newLatLng, coordCenter.zoom);
}
void TransformState::setLatLngZoom(const LatLng &latLng, double zoom) {
double newScale = zoomScale(zoom);
const double newWorldSize = newScale * util::tileSize;