summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--benchmark/api/query.benchmark.cpp2
-rw-r--r--benchmark/api/render.benchmark.cpp2
-rw-r--r--bin/render.cpp8
-rw-r--r--include/mbgl/map/map.hpp17
-rwxr-xr-xplatform/android/src/native_map_view.cpp7
-rw-r--r--platform/glfw/main.cpp20
-rw-r--r--platform/ios/src/MGLMapView.mm31
-rw-r--r--platform/macos/src/MGLMapView.mm23
-rw-r--r--platform/node/src/node_map.cpp2
-rw-r--r--platform/qt/src/qmapboxgl.cpp14
-rw-r--r--src/mbgl/map/map.cpp39
-rw-r--r--test/api/annotations.test.cpp27
-rw-r--r--test/api/custom_geometry_source.test.cpp2
-rw-r--r--test/api/custom_layer.test.cpp2
-rw-r--r--test/api/query.test.cpp2
-rw-r--r--test/gl/context.test.cpp2
-rw-r--r--test/map/map.test.cpp37
-rw-r--r--test/map/prefetch.test.cpp2
-rw-r--r--test/util/memory.test.cpp4
19 files changed, 112 insertions, 131 deletions
diff --git a/benchmark/api/query.benchmark.cpp b/benchmark/api/query.benchmark.cpp
index 7694585526..8d060087de 100644
--- a/benchmark/api/query.benchmark.cpp
+++ b/benchmark/api/query.benchmark.cpp
@@ -23,7 +23,7 @@ public:
fileSource.setAccessToken("foobar");
map.getStyle().loadJSON(util::read_file("benchmark/fixtures/api/style.json"));
- map.setLatLngZoom({ 40.726989, -73.992857 }, 15); // Manhattan
+ map.jumpTo(CameraOptions().withCenter(LatLng { 40.726989, -73.992857 }).withZoom(15.0)); // Manhattan
map.getStyle().addImage(std::make_unique<style::Image>("test-icon",
decodeImage(util::read_file("benchmark/fixtures/api/default_marker.png")), 1.0));
diff --git a/benchmark/api/render.benchmark.cpp b/benchmark/api/render.benchmark.cpp
index a1b557777f..3362da1a4f 100644
--- a/benchmark/api/render.benchmark.cpp
+++ b/benchmark/api/render.benchmark.cpp
@@ -31,7 +31,7 @@ public:
static void prepare(Map& map, optional<std::string> json = {}) {
map.getStyle().loadJSON(json ? *json : util::read_file("benchmark/fixtures/api/style.json"));
- map.setLatLngZoom({ 40.726989, -73.992857 }, 15); // Manhattan
+ map.jumpTo(CameraOptions().withCenter(LatLng { 40.726989, -73.992857 }).withZoom(15.0)); // Manhattan
map.getStyle().addImage(std::make_unique<style::Image>("test-icon",
decodeImage(util::read_file("benchmark/fixtures/api/default_marker.png")), 1.0));
}
diff --git a/bin/render.cpp b/bin/render.cpp
index 1e7b210a4c..8fb7a8877f 100644
--- a/bin/render.cpp
+++ b/bin/render.cpp
@@ -91,9 +91,11 @@ int main(int argc, char *argv[]) {
}
map.getStyle().loadURL(style);
- map.setLatLngZoom({ lat, lon }, zoom);
- map.setBearing(bearing);
- map.setPitch(pitch);
+ map.jumpTo(CameraOptions()
+ .withCenter(LatLng { lat, lon })
+ .withZoom(zoom)
+ .withAngle(bearing)
+ .withPitch(pitch));
if (debug) {
map.setDebug(debug ? mbgl::MapDebugOptions::TileBorders | mbgl::MapDebugOptions::ParseStatus : mbgl::MapDebugOptions::NoDebug);
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 06772f2cd2..b05747df8d 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -64,7 +64,7 @@ public:
bool isPanning() const;
// Camera
- CameraOptions getCameraOptions(const EdgeInsets&) const;
+ CameraOptions getCameraOptions(const EdgeInsets& = {}) const;
void jumpTo(const CameraOptions&);
void easeTo(const CameraOptions&, const AnimationOptions&);
void flyTo(const CameraOptions&, const AnimationOptions&);
@@ -81,14 +81,7 @@ public:
void resetPosition(const EdgeInsets& = {});
// Zoom
- void scaleBy(double scale, optional<ScreenCoordinate> anchor, const AnimationOptions& animation);
- void setZoom(double zoom, const AnimationOptions& = {});
- void setZoom(double zoom, optional<ScreenCoordinate>, const AnimationOptions& = {});
- void setZoom(double zoom, const EdgeInsets&, const AnimationOptions& = {});
- double getZoom() const;
- void setLatLngZoom(const LatLng&, double zoom, const AnimationOptions& = {});
- void setLatLngZoom(const LatLng&, double zoom, const EdgeInsets&, const AnimationOptions& = {});
- void resetZoom();
+ void scaleBy(double scale, optional<ScreenCoordinate> anchor, const AnimationOptions& animation = {});
// Pitch
void pitchBy(double pitch, const AnimationOptions& animation = {});
@@ -159,9 +152,9 @@ public:
// Tile prefetching
//
// When loading a map, if `PrefetchZoomDelta` is set to any number greater than 0, the map will
- // first request a tile for `zoom = getZoom() - delta` in a attempt to display a full map at
- // lower resolution as quick as possible. It will get clamped at the tile source minimum zoom.
- // The default `delta` is 4.
+ // first request a tile for `zoom - delta` in a attempt to display a full map at lower
+ // resolution as quick as possible. It will get clamped at the tile source minimum zoom. The
+ // default `delta` is 4.
void setPrefetchZoomDelta(uint8_t delta);
uint8_t getPrefetchZoomDelta() const;
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index e8bc14c8c2..4755cc28c4 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -403,15 +403,16 @@ void NativeMapView::setPitch(jni::JNIEnv&, jni::jdouble pitch, jni::jlong durati
}
void NativeMapView::setZoom(jni::JNIEnv&, jni::jdouble zoom, jni::jdouble x, jni::jdouble y, jni::jlong duration) {
- map->setZoom(zoom, mbgl::ScreenCoordinate{x,y}, mbgl::AnimationOptions{mbgl::Milliseconds(duration)});
+ map->easeTo(mbgl::CameraOptions().withZoom(zoom).withAnchor(mbgl::ScreenCoordinate{ x, y }),
+ mbgl::AnimationOptions{ mbgl::Milliseconds(duration) });
}
jni::jdouble NativeMapView::getZoom(jni::JNIEnv&) {
- return map->getZoom();
+ return *map->getCameraOptions().zoom;
}
void NativeMapView::resetZoom(jni::JNIEnv&) {
- map->resetZoom();
+ map->jumpTo(mbgl::CameraOptions().withZoom(0.0));
}
void NativeMapView::setMinZoom(jni::JNIEnv&, jni::jdouble zoom) {
diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp
index 1bb2e13614..9963ca6884 100644
--- a/platform/glfw/main.cpp
+++ b/platform/glfw/main.cpp
@@ -117,9 +117,11 @@ int main(int argc, char *argv[]) {
style = std::string("file://") + style;
}
- map.setLatLngZoom(mbgl::LatLng(settings.latitude, settings.longitude), settings.zoom);
- map.setBearing(settings.bearing);
- map.setPitch(settings.pitch);
+ map.jumpTo(mbgl::CameraOptions()
+ .withCenter(mbgl::LatLng {settings.latitude, settings.longitude})
+ .withZoom(settings.zoom)
+ .withAngle(settings.bearing)
+ .withPitch(settings.pitch));
map.setDebug(mbgl::MapDebugOptions(settings.debug));
view->setOnlineStatusCallback([&settings, &fileSource]() {
@@ -172,12 +174,12 @@ int main(int argc, char *argv[]) {
view->run();
// Save settings
- mbgl::LatLng latLng = map.getLatLng();
- settings.latitude = latLng.latitude();
- settings.longitude = latLng.longitude();
- settings.zoom = map.getZoom();
- settings.bearing = map.getBearing();
- settings.pitch = map.getPitch();
+ mbgl::CameraOptions camera = map.getCameraOptions();
+ settings.latitude = camera.center->latitude();
+ settings.longitude = camera.center->longitude();
+ settings.zoom = *camera.zoom;
+ settings.bearing = *camera.angle;
+ settings.pitch = *camera.pitch;
settings.debug = mbgl::EnumType(map.getDebug());
settings.save();
mbgl::Log::Info(mbgl::Event::General,
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index f9ccab1422..aa57f75e16 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -1673,7 +1673,7 @@ public:
{
[self trackGestureEvent:MMEEventGesturePinchStart forRecognizer:pinch];
- self.scale = powf(2, self.mbglMap.getZoom());
+ self.scale = powf(2, [self zoomLevel]);
[self notifyGestureDidBegin];
}
@@ -1688,7 +1688,8 @@ public:
if ([self _shouldChangeFromCamera:oldCamera toCamera:toCamera])
{
- self.mbglMap.setZoom(newZoom, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
+ self.mbglMap.jumpTo(mbgl::CameraOptions().withZoom(newZoom).withAnchor(mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }));
+
// The gesture recognizer only reports the gesture’s current center
// point, so use the previous center point to anchor the transition.
// If the number of touches has changed, the remembered center point is
@@ -1747,7 +1748,7 @@ public:
{
if (drift)
{
- self.mbglMap.setZoom(zoom, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationFromTimeInterval(duration));
+ self.mbglMap.easeTo(mbgl::CameraOptions().withZoom(zoom).withAnchor(mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }), MGLDurationFromTimeInterval(duration));
}
}
@@ -1968,7 +1969,7 @@ public:
[self trackGestureEvent:MMEEventGestureDoubleTap forRecognizer:doubleTap];
mbgl::ScreenCoordinate center(gesturePoint.x, gesturePoint.y);
- self.mbglMap.setZoom(newZoom, center, MGLDurationFromTimeInterval(MGLAnimationDuration));
+ self.mbglMap.easeTo(mbgl::CameraOptions().withZoom(newZoom).withAnchor(center), MGLDurationFromTimeInterval(MGLAnimationDuration));
__weak MGLMapView *weakSelf = self;
@@ -1989,7 +1990,7 @@ public:
if ( ! self.isZoomEnabled) return;
- if (self.mbglMap.getZoom() == self.mbglMap.getMinZoom()) return;
+ if ([self zoomLevel] == self.mbglMap.getMinZoom()) return;
[self cancelTransitions];
@@ -2008,7 +2009,7 @@ public:
[self trackGestureEvent:MMEEventGestureTwoFingerSingleTap forRecognizer:twoFingerTap];
mbgl::ScreenCoordinate center(gesturePoint.x, gesturePoint.y);
- self.mbglMap.setZoom(newZoom, center, MGLDurationFromTimeInterval(MGLAnimationDuration));
+ self.mbglMap.easeTo(mbgl::CameraOptions().withZoom(newZoom).withAnchor(center), MGLDurationFromTimeInterval(MGLAnimationDuration));
__weak MGLMapView *weakSelf = self;
@@ -2031,7 +2032,7 @@ public:
{
[self trackGestureEvent:MMEEventGestureQuickZoom forRecognizer:quickZoom];
- self.scale = powf(2, self.mbglMap.getZoom());
+ self.scale = powf(2, [self zoomLevel]);
self.quickZoomStart = [quickZoom locationInView:quickZoom.view].y;
@@ -2043,7 +2044,7 @@ public:
CGFloat newZoom = MAX(log2f(self.scale) + (distance / 75), self.mbglMap.getMinZoom());
- if (self.mbglMap.getZoom() == newZoom) return;
+ if ([self zoomLevel] == newZoom) return;
CGPoint centerPoint = [self anchorPointForGesture:quickZoom];
@@ -2052,7 +2053,7 @@ public:
if ([self _shouldChangeFromCamera:oldCamera toCamera:toCamera])
{
- self.mbglMap.setZoom(newZoom, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
+ self.mbglMap.jumpTo(mbgl::CameraOptions().withZoom(newZoom).withAnchor(mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }));
}
[self cameraIsChanging];
@@ -3141,7 +3142,7 @@ public:
centerPoint = self.userLocationAnnotationViewCenter;
}
double newZoom = round(self.zoomLevel) + log2(scaleFactor);
- self.mbglMap.setZoom(newZoom, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
+ self.mbglMap.jumpTo(mbgl::CameraOptions().withZoom(newZoom).withAnchor(mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }));
[self unrotateIfNeededForGesture];
_accessibilityValueAnnouncementIsPending = YES;
@@ -3274,7 +3275,8 @@ public:
- (double)zoomLevel
{
- return self.mbglMap.getZoom();
+ mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInset);
+ return *self.mbglMap.getCameraOptions(padding).zoom;
}
- (void)setZoomLevel:(double)zoomLevel
@@ -3293,9 +3295,10 @@ public:
CGFloat duration = animated ? MGLAnimationDuration : 0;
- self.mbglMap.setZoom(zoomLevel,
- MGLEdgeInsetsFromNSEdgeInsets(self.contentInset),
- MGLDurationFromTimeInterval(duration));
+ self.mbglMap.easeTo(mbgl::CameraOptions()
+ .withZoom(zoomLevel)
+ .withPadding(MGLEdgeInsetsFromNSEdgeInsets(self.contentInset)),
+ MGLDurationFromTimeInterval(duration));
}
- (void)setMinimumZoomLevel:(double)minimumZoomLevel
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 5a24524b4a..03088ac5c6 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -1047,7 +1047,8 @@ public:
}
- (double)zoomLevel {
- return _mbglMap->getZoom();
+ mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets);
+ return *_mbglMap->getCameraOptions(padding).zoom;
}
- (void)setZoomLevel:(double)zoomLevel {
@@ -1058,9 +1059,10 @@ public:
- (void)setZoomLevel:(double)zoomLevel animated:(BOOL)animated {
MGLLogDebug(@"Setting zoomLevel: %f animated: %@", zoomLevel, MGLStringFromBOOL(animated));
[self willChangeValueForKey:@"zoomLevel"];
- _mbglMap->setZoom(zoomLevel,
- MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets),
- MGLDurationFromTimeInterval(animated ? MGLAnimationDuration : 0));
+ _mbglMap->easeTo(mbgl::CameraOptions()
+ .withZoom(zoomLevel)
+ .withPadding(MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets)),
+ MGLDurationFromTimeInterval(animated ? MGLAnimationDuration : 0));
[self didChangeValueForKey:@"zoomLevel"];
}
@@ -1069,7 +1071,10 @@ public:
[self willChangeValueForKey:@"zoomLevel"];
MGLMapCamera *oldCamera = self.camera;
mbgl::ScreenCoordinate center(point.x, self.bounds.size.height - point.y);
- _mbglMap->setZoom(zoomLevel, center, MGLDurationFromTimeInterval(animated ? MGLAnimationDuration : 0));
+ _mbglMap->easeTo(mbgl::CameraOptions()
+ .withZoom(zoomLevel)
+ .withAnchor(center),
+ MGLDurationFromTimeInterval(animated ? MGLAnimationDuration : 0));
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:self.camera]) {
self.camera = oldCamera;
@@ -1461,7 +1466,7 @@ public:
_mbglMap->cancelTransitions();
if (gestureRecognizer.state == NSGestureRecognizerStateBegan) {
- _zoomAtBeginningOfGesture = _mbglMap->getZoom();
+ _zoomAtBeginningOfGesture = [self zoomLevel];
} else if (gestureRecognizer.state == NSGestureRecognizerStateChanged) {
CGFloat newZoomLevel = _zoomAtBeginningOfGesture - delta.y / 75;
[self setZoomLevel:newZoomLevel atPoint:startPoint animated:NO];
@@ -1525,7 +1530,7 @@ public:
if (gestureRecognizer.state == NSGestureRecognizerStateBegan) {
_mbglMap->setGestureInProgress(true);
- _zoomAtBeginningOfGesture = _mbglMap->getZoom();
+ _zoomAtBeginningOfGesture = [self zoomLevel];
} else if (gestureRecognizer.state == NSGestureRecognizerStateChanged) {
NSPoint zoomInPoint = [gestureRecognizer locationInView:self];
mbgl::ScreenCoordinate center(zoomInPoint.x, self.bounds.size.height - zoomInPoint.y);
@@ -1533,7 +1538,9 @@ public:
[self willChangeValueForKey:@"zoomLevel"];
[self willChangeValueForKey:@"centerCoordinate"];
MGLMapCamera *oldCamera = self.camera;
- _mbglMap->setZoom(_zoomAtBeginningOfGesture + log2(1 + gestureRecognizer.magnification), center);
+ _mbglMap->jumpTo(mbgl::CameraOptions()
+ .withZoom(_zoomAtBeginningOfGesture + log2(1 + gestureRecognizer.magnification))
+ .withAnchor(center));
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:self.camera]) {
self.camera = oldCamera;
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index 6dccdf5292..d6a5941bcb 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -959,7 +959,7 @@ void NodeMap::SetZoom(const Nan::FunctionCallbackInfo<v8::Value>& info) {
}
try {
- nodeMap->map->setZoom(info[0]->NumberValue());
+ nodeMap->map->jumpTo(mbgl::CameraOptions().withZoom(info[0]->NumberValue()));
} catch (const std::exception &ex) {
return Nan::ThrowError(ex.what());
}
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index cc4028b64d..8059960601 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -726,12 +726,12 @@ void QMapboxGL::setLongitude(double longitude_)
*/
double QMapboxGL::scale() const
{
- return std::pow(2.0, d_ptr->mapObj->getZoom());
+ return std::pow(2.0, zoom());
}
void QMapboxGL::setScale(double scale_, const QPointF &center)
{
- d_ptr->mapObj->setZoom(::log2(scale_), mbgl::ScreenCoordinate { center.x(), center.y() });
+ d_ptr->mapObj->jumpTo(mbgl::CameraOptions().withZoom(::log2(scale_)).withAnchor(mbgl::ScreenCoordinate { center.x(), center.y() }));
}
/*!
@@ -746,12 +746,12 @@ void QMapboxGL::setScale(double scale_, const QPointF &center)
*/
double QMapboxGL::zoom() const
{
- return d_ptr->mapObj->getZoom();
+ return *d_ptr->mapObj->getCameraOptions().zoom;
}
void QMapboxGL::setZoom(double zoom_)
{
- d_ptr->mapObj->setZoom(zoom_, d_ptr->margins);
+ d_ptr->mapObj->jumpTo(mbgl::CameraOptions().withZoom(zoom_).withPadding(d_ptr->margins));
}
/*!
@@ -806,8 +806,10 @@ void QMapboxGL::setCoordinate(const QMapbox::Coordinate &coordinate_)
*/
void QMapboxGL::setCoordinateZoom(const QMapbox::Coordinate &coordinate_, double zoom_)
{
- d_ptr->mapObj->setLatLngZoom(
- mbgl::LatLng { coordinate_.first, coordinate_.second }, zoom_, d_ptr->margins);
+ d_ptr->mapObj->jumpTo(mbgl::CameraOptions()
+ .withCenter(mbgl::LatLng { coordinate_.first, coordinate_.second })
+ .withZoom(zoom_)
+ .withPadding(d_ptr->margins));
}
/*!
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index ab4ccb2007..b02d784e75 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -188,34 +188,10 @@ void Map::resetPosition(const EdgeInsets& padding) {
#pragma mark - Zoom
void Map::scaleBy(double scale, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
- double zoom = getZoom() + impl->transform.getState().scaleZoom(scale);
+ const double zoom = impl->transform.getZoom() + impl->transform.getState().scaleZoom(scale);
easeTo(CameraOptions().withZoom(zoom).withAnchor(anchor), animation);
}
-void Map::setZoom(double zoom, const AnimationOptions& animation) {
- easeTo(CameraOptions().withZoom(zoom), animation);
-}
-
-void Map::setZoom(double zoom, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
- easeTo(CameraOptions().withZoom(zoom).withAnchor(anchor), animation);
-}
-
-void Map::setZoom(double zoom, const EdgeInsets& padding, const AnimationOptions& animation) {
- easeTo(CameraOptions().withZoom(zoom).withPadding(padding), animation);
-}
-
-double Map::getZoom() const {
- return impl->transform.getZoom();
-}
-
-void Map::setLatLngZoom(const LatLng& latLng, double zoom, const AnimationOptions& animation) {
- easeTo(CameraOptions().withCenter(latLng).withZoom(zoom), animation);
-}
-
-void Map::setLatLngZoom(const LatLng& latLng, double zoom, const EdgeInsets& padding, const AnimationOptions& animation) {
- easeTo(CameraOptions().withCenter(latLng).withZoom(zoom).withPadding(padding), animation);
-}
-
CameraOptions Map::cameraForLatLngBounds(const LatLngBounds& bounds, const EdgeInsets& padding, optional<double> bearing, optional<double> pitch) const {
return cameraForLatLngs({
bounds.northwest(),
@@ -312,11 +288,6 @@ LatLngBounds Map::latLngBoundsForCamera(const CameraOptions& camera) const {
);
}
-void Map::resetZoom() {
- impl->cameraMutated = true;
- setZoom(0);
-}
-
#pragma mark - Pitch
void Map::pitchBy(double pitch, const AnimationOptions& animation) {
@@ -337,8 +308,8 @@ void Map::setLatLngBounds(optional<LatLngBounds> bounds) {
void Map::setMinZoom(const double minZoom) {
impl->transform.setMinZoom(minZoom);
- if (getZoom() < minZoom) {
- setZoom(minZoom);
+ if (impl->transform.getZoom() < minZoom) {
+ jumpTo(CameraOptions().withZoom(minZoom));
}
}
@@ -348,8 +319,8 @@ double Map::getMinZoom() const {
void Map::setMaxZoom(const double maxZoom) {
impl->transform.setMaxZoom(maxZoom);
- if (getZoom() > maxZoom) {
- setZoom(maxZoom);
+ if (impl->transform.getZoom() > maxZoom) {
+ jumpTo(CameraOptions().withZoom(maxZoom));
}
}
diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp
index d13bc15ea7..c0c4f38cf9 100644
--- a/test/api/annotations.test.cpp
+++ b/test/api/annotations.test.cpp
@@ -53,7 +53,7 @@ TEST(Annotations, SymbolAnnotation) {
// auto size = test.frontend.getSize();
// auto screenBox = ScreenBox { {}, { double(size.width), double(size.height) } };
// for (uint8_t zoom = test.map.getMinZoom(); zoom <= test.map.getMaxZoom(); ++zoom) {
-// test.map.setZoom(zoom);
+// test.map.jumpTo(CameraOptions().withZoom(zoom));
// test.checkRendering("point_annotation");
// EXPECT_EQ(test.map.queryPointAnnotations(screenBox).size(), 1u);
// }
@@ -67,7 +67,7 @@ TEST(Annotations, SymbolAnnotationTileBoundary) {
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double>(0.000000000000001, 0.00000000000001), "default_marker" });
- test.map.setZoom(10);
+ test.map.jumpTo(CameraOptions().withZoom(10));
test.checkRendering("point_annotation");
}
@@ -83,7 +83,7 @@ TEST(Annotations, LineAnnotation) {
test.map.addAnnotation(annotation);
test.checkRendering("line_annotation");
- test.map.setZoom(test.map.getMaxZoom());
+ test.map.jumpTo(CameraOptions().withZoom(test.map.getMaxZoom()));
test.checkRendering("line_annotation_max_zoom");
}
@@ -98,7 +98,7 @@ TEST(Annotations, FillAnnotation) {
test.map.addAnnotation(annotation);
test.checkRendering("fill_annotation");
- test.map.setZoom(test.map.getMaxZoom());
+ test.map.jumpTo(CameraOptions().withZoom(test.map.getMaxZoom()));
test.checkRendering("fill_annotation_max_zoom");
}
@@ -106,7 +106,7 @@ TEST(Annotations, AntimeridianAnnotationSmall) {
AnnotationTest test;
double antimeridian = 180;
- test.map.setLatLngZoom(mbgl::LatLng(0, antimeridian), 0);
+ test.map.jumpTo(CameraOptions().withCenter(LatLng { 0, antimeridian }).withZoom(0.0));
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
LineString<double> line = {{ { antimeridian, 20 }, { antimeridian, -20 } }};
@@ -127,7 +127,7 @@ TEST(Annotations, AntimeridianAnnotationLarge) {
AnnotationTest test;
double antimeridian = 180;
- test.map.setLatLngZoom(mbgl::LatLng(0, antimeridian), 0);
+ test.map.jumpTo(CameraOptions().withCenter(mbgl::LatLng(0.0, antimeridian)).withZoom(0.0));
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
LineString<double> line = {{ { antimeridian, 20 }, { antimeridian, -20 } }};
@@ -384,9 +384,9 @@ TEST(Annotations, QueryFractionalZoomLevels) {
}
}
- test.map.setLatLngZoom({ 5, 5 }, 0);
+ test.map.jumpTo(CameraOptions().withCenter(mbgl::LatLng(5.0, 5.0)).withZoom(0.0));
for (uint16_t zoomSteps = 10; zoomSteps <= 20; ++zoomSteps) {
- test.map.setZoom(zoomSteps / 10.0);
+ test.map.jumpTo(CameraOptions().withZoom(zoomSteps / 10.0));
test.frontend.render(test.map);
auto features = test.frontend.getRenderer()->queryRenderedFeatures(box);
@@ -408,7 +408,7 @@ TEST(Annotations, VisibleFeatures) {
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
- test.map.setLatLngZoom({ 5, 5 }, 3);
+ test.map.jumpTo(CameraOptions().withCenter(mbgl::LatLng(5.0, 5.0)).withZoom(3.0));
std::vector<mbgl::AnnotationID> ids;
for (int longitude = 0; longitude < 10; longitude += 2) {
@@ -428,8 +428,7 @@ TEST(Annotations, VisibleFeatures) {
features.erase(std::unique(features.begin(), features.end(), sameID), features.end());
EXPECT_EQ(features.size(), ids.size());
- test.map.setBearing(0);
- test.map.setZoom(4);
+ test.map.jumpTo(CameraOptions().withZoom(4.0).withAngle(0.0));
test.frontend.render(test.map);
features = test.frontend.getRenderer()->queryRenderedFeatures(box);
std::sort(features.begin(), features.end(), sortID);
@@ -452,7 +451,7 @@ TEST(Annotations, DebugEmpty) {
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.setDebug(MapDebugOptions::TileBorders);
- test.map.setZoom(1);
+ test.map.jumpTo(CameraOptions().withZoom(1.0));
test.checkRendering("debug_empty");
}
@@ -465,7 +464,7 @@ TEST(Annotations, DebugSparse) {
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.setDebug(MapDebugOptions::TileBorders);
- test.map.setZoom(1);
+ test.map.jumpTo(CameraOptions().withZoom(1.0));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double>(10, 10), "default_marker" });
@@ -484,7 +483,7 @@ TEST(Annotations, ChangeMaxZoom) {
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotation(annotation);
test.map.setMaxZoom(14);
- test.map.setZoom(test.map.getMaxZoom());
+ test.map.jumpTo(CameraOptions().withZoom(test.map.getMaxZoom()));
test.checkRendering("line_annotation_max_zoom");
}
diff --git a/test/api/custom_geometry_source.test.cpp b/test/api/custom_geometry_source.test.cpp
index 51d026e30d..3e18cca01a 100644
--- a/test/api/custom_geometry_source.test.cpp
+++ b/test/api/custom_geometry_source.test.cpp
@@ -26,7 +26,7 @@ TEST(CustomGeometrySource, Grid) {
Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
*threadPool, MapMode::Static);
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
- map.setLatLngZoom({ 37.8, -122.5 }, 10);
+ map.jumpTo(CameraOptions().withCenter(LatLng { 37.8, -122.5 }).withZoom(10.0));
CustomGeometrySource::Options options;
options.fetchTileFunction = [&map](const mbgl::CanonicalTileID& tileID) {
diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp
index c2a0797483..114b88398a 100644
--- a/test/api/custom_layer.test.cpp
+++ b/test/api/custom_layer.test.cpp
@@ -96,7 +96,7 @@ TEST(CustomLayer, Basic) {
Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
threadPool, MapMode::Static);
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
- map.setLatLngZoom({ 37.8, -122.5 }, 10);
+ map.jumpTo(CameraOptions().withCenter(LatLng { 37.8, -122.5 }).withZoom(10.0));
map.getStyle().addLayer(std::make_unique<CustomLayer>(
"custom",
std::make_unique<TestLayer>()));
diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp
index f5eb32788d..efda84baa9 100644
--- a/test/api/query.test.cpp
+++ b/test/api/query.test.cpp
@@ -59,7 +59,7 @@ std::vector<Feature> getTopClusterFeature(QueryTest& test) {
clusterLayer->setIconImage("test-icon"s);
clusterLayer->setIconSize(12.0f);
- test.map.setLatLngZoom(coordinate, 0);
+ test.map.jumpTo(CameraOptions().withCenter(coordinate).withZoom(0.0));
test.map.getStyle().addSource(std::move(source));
test.map.getStyle().addLayer(std::move(clusterLayer));
test.loop.runOnce();
diff --git a/test/gl/context.test.cpp b/test/gl/context.test.cpp
index 176257916f..a5f9807a8e 100644
--- a/test/gl/context.test.cpp
+++ b/test/gl/context.test.cpp
@@ -93,7 +93,7 @@ TEST(GLContextMode, Shared) {
Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource, threadPool, MapMode::Static);
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
- map.setLatLngZoom({ 37.8, -122.5 }, 10);
+ map.jumpTo(CameraOptions().withCenter(LatLng { 37.8, -122.5 }).withZoom(10.0));
// Set transparent background layer.
auto layer = map.getStyle().getLayer("background");
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index 690df6b3e9..da3abfcb24 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -64,9 +64,7 @@ TEST(Map, RendererState) {
double bearingInDegrees = 30.0;
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
- test.map.setLatLngZoom(coordinate, zoom);
- test.map.setPitch(pitchInDegrees);
- test.map.setBearing(bearingInDegrees);
+ test.map.jumpTo(CameraOptions().withCenter(coordinate).withZoom(zoom).withPitch(pitchInDegrees).withAngle(bearingInDegrees));
test.runLoop.runOnce();
test.frontend.render(test.map);
@@ -128,7 +126,7 @@ TEST(Map, RendererState) {
TEST(Map, LatLngBehavior) {
MapTest<> test;
- test.map.setLatLngZoom({ 1, 1 }, 0);
+ test.map.jumpTo(CameraOptions().withCenter(LatLng { 1.0, 1.0 }).withZoom(0.0));
auto latLng1 = test.map.getLatLng();
test.map.setLatLng({ 1, 1 });
@@ -141,7 +139,7 @@ TEST(Map, LatLngBehavior) {
TEST(Map, LatLngBoundsToCamera) {
MapTest<> test;
- test.map.setLatLngZoom({ 40.712730, -74.005953 }, 16.0);
+ test.map.jumpTo(CameraOptions().withCenter(LatLng { 40.712730, -74.005953 }).withZoom(16.0));
LatLngBounds bounds = LatLngBounds::hull({15.68169,73.499857}, {53.560711, 134.77281});
@@ -153,7 +151,7 @@ TEST(Map, LatLngBoundsToCamera) {
TEST(Map, LatLngBoundsToCameraWithAngle) {
MapTest<> test;
- test.map.setLatLngZoom({ 40.712730, -74.005953 }, 16.0);
+ test.map.jumpTo(CameraOptions().withCenter(LatLng { 40.712730, -74.005953 }).withZoom(16.0));
LatLngBounds bounds = LatLngBounds::hull({15.68169,73.499857}, {53.560711, 134.77281});
@@ -166,7 +164,7 @@ TEST(Map, LatLngBoundsToCameraWithAngle) {
TEST(Map, LatLngBoundsToCameraWithAngleAndPitch) {
MapTest<> test;
- test.map.setLatLngZoom({ 40.712730, -74.005953 }, 16.0);
+ test.map.jumpTo(CameraOptions().withCenter(LatLng { 40.712730, -74.005953 }).withZoom(16.0));
LatLngBounds bounds = LatLngBounds::hull({15.68169,73.499857}, {53.560711, 134.77281});
@@ -206,13 +204,13 @@ TEST(Map, LatLngsToCameraWithAngleAndPitch) {
TEST(Map, CameraToLatLngBounds) {
MapTest<> test;
- test.map.setLatLngZoom({ 45, 90 }, 16);
+ test.map.jumpTo(CameraOptions().withCenter(LatLng { 45, 90 }).withZoom(16.0));
LatLngBounds bounds = LatLngBounds::hull(
test.map.latLngForPixel({}),
test.map.latLngForPixel({ double(test.map.getSize().width), double(test.map.getSize().height) }));
- CameraOptions camera = test.map.getCameraOptions({});
+ CameraOptions camera = test.map.getCameraOptions();
ASSERT_EQ(bounds, test.map.latLngBoundsForCamera(camera));
@@ -255,16 +253,19 @@ TEST(Map, Offline) {
TEST(Map, SetStyleDefaultCamera) {
MapTest<> test;
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
- EXPECT_DOUBLE_EQ(test.map.getZoom(), 0.0);
- EXPECT_DOUBLE_EQ(test.map.getPitch(), 0.0);
- EXPECT_DOUBLE_EQ(test.map.getBearing(), 0.0);
- EXPECT_EQ(test.map.getLatLng(), LatLng {});
+ CameraOptions camera = test.map.getCameraOptions();
+ EXPECT_DOUBLE_EQ(*camera.zoom, 0.0);
+ EXPECT_DOUBLE_EQ(*camera.pitch, 0.0);
+ EXPECT_DOUBLE_EQ(*camera.angle, 0.0);
+ EXPECT_EQ(*camera.center, LatLng {});
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty-zoomed.json"));
- EXPECT_DOUBLE_EQ(test.map.getZoom(), 0.0);
+ camera = test.map.getCameraOptions();
+ EXPECT_DOUBLE_EQ(*camera.zoom, 0.0);
test.map.jumpTo(test.map.getStyle().getDefaultCamera());
- EXPECT_DOUBLE_EQ(test.map.getZoom(), 0.5);
+ camera = test.map.getCameraOptions();
+ EXPECT_DOUBLE_EQ(*camera.zoom, 0.5);
}
TEST(Map, SetStyleInvalidJSON) {
@@ -561,7 +562,7 @@ TEST(Map, DisabledSources) {
return {};
};
- test.map.setZoom(1);
+ test.map.jumpTo(CameraOptions().withZoom(1.0));
// This stylesheet has two raster layers, one that starts at zoom 1, the other at zoom 0.
// We first render a map at zoom level 1, which should show both layers (both are "visible" due
@@ -603,7 +604,7 @@ TEST(Map, DisabledSources) {
)STYLE");
test::checkImage("test/fixtures/map/disabled_layers/first", test.frontend.render(test.map));
- test.map.setZoom(0.5);
+ test.map.jumpTo(CameraOptions().withZoom(0.5));
test::checkImage("test/fixtures/map/disabled_layers/second", test.frontend.render(test.map));
}
@@ -648,7 +649,7 @@ TEST(Map, DontLoadUnneededTiles) {
// Note: using z += 0.1 in the loop doesn't produce accurate floating point numbers.
const double z = double(zoom) / 10;
tiles.clear();
- test.map.setZoom(z);
+ test.map.jumpTo(CameraOptions().withZoom(z));
test.frontend.render(test.map);
EXPECT_EQ(referenceTiles[z], tiles) << "zoom level " << z;
}
diff --git a/test/map/prefetch.test.cpp b/test/map/prefetch.test.cpp
index 9b61224027..9e513d61cd 100644
--- a/test/map/prefetch.test.cpp
+++ b/test/map/prefetch.test.cpp
@@ -58,7 +58,7 @@ TEST(Map, PrefetchTiles) {
// Force tile reloading.
map.getStyle().loadJSON(util::read_file("test/fixtures/map/prefetch/empty.json"));
map.getStyle().loadJSON(util::read_file("test/fixtures/map/prefetch/style.json"));
- map.setLatLngZoom({ 40.726989, -73.992857 }, zoom); // Manhattan
+ map.jumpTo(CameraOptions().withCenter(LatLng { 40.726989, -73.992857 }).withZoom(zoom)); // Manhattan
runLoop.run();
ASSERT_EQ(tiles.size(), expected.size());
diff --git a/test/util/memory.test.cpp b/test/util/memory.test.cpp
index 6befb521f0..e92311226b 100644
--- a/test/util/memory.test.cpp
+++ b/test/util/memory.test.cpp
@@ -73,7 +73,7 @@ TEST(Memory, Vector) {
HeadlessFrontend frontend { { 256, 256 }, ratio, test.fileSource, test.threadPool };
Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), ratio, test.fileSource,
test.threadPool, MapMode::Static);
- map.setZoom(16); // more map features
+ map.jumpTo(CameraOptions().withZoom(16));
map.getStyle().loadURL("mapbox://streets");
frontend.render(map);
@@ -123,7 +123,7 @@ TEST(Memory, Footprint) {
FrontendAndMap(MemoryTest& test_, const char* style)
: frontend(Size{ 256, 256 }, 2, test_.fileSource, test_.threadPool)
, map(frontend, MapObserver::nullObserver(), frontend.getSize(), 2, test_.fileSource, test_.threadPool, MapMode::Static) {
- map.setZoom(16);
+ map.jumpTo(CameraOptions().withZoom(16));
map.getStyle().loadURL(style);
frontend.render(map);
}