CameraOptions

Plumbed camera options all the way through to MGLMapView. Added a method that lets you specify a direction in addition to center point and zoom level.

Added Map::jumpTo() for parity with mapbox-gl-js. Replaced usage of Map::setLatLng() and Map::setLatLngZoom() with Map::jumpTo() or Map::easeTo() within MGLMapView. Replaced MGLMapView.pitch with MGLMapCamera for setting all supported degrees of freedom simultaneously. Simultaneously move and rotate with course.

Support customizable timing functions on iOS.

iosapp now persists an archived MGLMapCamera instead of separate viewpoint properties and also synchronizes user defaults on termination. This change implements persistence entirely in Objective-C, eliminating the use of the Objective-C++ implementation.

Fixes #1643, fixes #1834. Ref #1581.
This commit is contained in:
Minh Nguyễn
2015-07-30 15:34:49 -07:00
committed by Justin R. Miller
parent 584c36f348
commit 0a172a21fd
16 changed files with 589 additions and 204 deletions

View File

@@ -9,6 +9,7 @@
#include <mbgl/util/projection.hpp>
#include <mbgl/util/thread.hpp>
#include <mbgl/util/math.hpp>
namespace mbgl {
@@ -114,6 +115,18 @@ void Map::setGestureInProgress(bool inProgress) {
update(Update::Repaint);
}
#pragma mark -
void Map::jumpTo(CameraOptions options) {
transform->jumpTo(options);
update(Update::Repaint);
}
void Map::easeTo(CameraOptions options) {
transform->easeTo(options);
update(options.zoom ? Update::Zoom : Update::Repaint);
}
#pragma mark - Position
void Map::moveBy(double dx, double dy, const Duration& duration) {
@@ -131,9 +144,11 @@ LatLng Map::getLatLng() const {
}
void Map::resetPosition() {
transform->setAngle(0);
transform->setLatLng(LatLng(0, 0));
transform->setZoom(0);
CameraOptions options;
options.angle = 0;
options.center = LatLng(0, 0);
options.zoom = 0;
transform->jumpTo(options);
update(Update::Zoom);
}
@@ -168,25 +183,26 @@ void Map::setLatLngZoom(LatLng latLng, double zoom, const Duration& duration) {
update(Update::Zoom);
}
void Map::fitBounds(LatLngBounds bounds, EdgeInsets padding, const Duration& duration) {
CameraOptions Map::cameraForLatLngBounds(LatLngBounds bounds, EdgeInsets padding) {
AnnotationSegment segment = {
{bounds.ne.latitude, bounds.sw.longitude},
bounds.sw,
{bounds.sw.latitude, bounds.ne.longitude},
bounds.ne,
};
fitBounds(segment, padding, duration);
return cameraForLatLngs(segment, padding);
}
void Map::fitBounds(AnnotationSegment segment, EdgeInsets padding, const Duration& duration) {
if (segment.empty()) {
return;
CameraOptions Map::cameraForLatLngs(std::vector<LatLng> latLngs, EdgeInsets padding) {
CameraOptions options;
if (latLngs.empty()) {
return options;
}
// Calculate the bounds of the possibly rotated shape with respect to the viewport.
vec2<> nePixel = {-INFINITY, -INFINITY};
vec2<> swPixel = {INFINITY, INFINITY};
for (LatLng latLng : segment) {
for (LatLng latLng : latLngs) {
vec2<> pixel = pixelForLatLng(latLng);
swPixel.x = std::min(swPixel.x, pixel.x);
nePixel.x = std::max(nePixel.x, pixel.x);
@@ -214,7 +230,9 @@ void Map::fitBounds(AnnotationSegment segment, EdgeInsets padding, const Duratio
vec2<> centerPixel = (paddedNEPixel + paddedSWPixel) * 0.5;
LatLng centerLatLng = latLngForPixel(centerPixel);
setLatLngZoom(centerLatLng, zoom, duration);
options.center = centerLatLng;
options.zoom = zoom;
return options;
}
void Map::resetZoom() {
@@ -270,8 +288,8 @@ void Map::resetNorth() {
#pragma mark - Pitch
void Map::setPitch(double pitch) {
transform->setPitch(std::min(pitch, 60.0) * M_PI / 180);
void Map::setPitch(double pitch, const Duration& duration) {
transform->setPitch(util::clamp(pitch, 0., 60.) * M_PI / 180, duration);
update(Update::Repaint);
}