From 57334407473a31ff43baa645dafd2f5e1bd910fb Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Fri, 8 Mar 2019 12:43:05 +0200 Subject: [core] Group Map LatLngBounds, min and max zoom methods Group bounds, minimum and maximum zoom related methods together using the new BoundOptions. v2: Document that getBounds() initializes all optional fields. - Add test for getBounds() on a map with default values. --- src/mbgl/map/map.cpp | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'src/mbgl/map') diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index e45d4b85f2..f545fc8095 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -275,36 +275,41 @@ LatLngBounds Map::latLngBoundsForCamera(const CameraOptions& camera) const { #pragma mark - Bounds -LatLngBounds Map::getLatLngBounds() const { - return impl->transform.getState().getLatLngBounds(); -} +void Map::setBounds(const BoundOptions& options) { + bool changeCamera = false; + CameraOptions cameraOptions; -void Map::setLatLngBounds(LatLngBounds bounds) { - impl->cameraMutated = true; - impl->transform.setLatLngBounds(std::move(bounds)); - impl->onUpdate(); -} + if (options.bounds) { + changeCamera = true; + impl->transform.setLatLngBounds(*options.bounds); + } -void Map::setMinZoom(const double minZoom) { - impl->transform.setMinZoom(minZoom); - if (impl->transform.getZoom() < minZoom) { - jumpTo(CameraOptions().withZoom(minZoom)); + if (options.minZoom) { + impl->transform.setMinZoom(*options.minZoom); + if (impl->transform.getZoom() < *options.minZoom) { + changeCamera = true; + cameraOptions.withZoom(*options.minZoom); + } } -} -double Map::getMinZoom() const { - return impl->transform.getState().getMinZoom(); -} + if (options.maxZoom) { + impl->transform.setMaxZoom(*options.maxZoom); + if (impl->transform.getZoom() > *options.maxZoom) { + changeCamera = true; + cameraOptions.withZoom(*options.maxZoom); + } + } -void Map::setMaxZoom(const double maxZoom) { - impl->transform.setMaxZoom(maxZoom); - if (impl->transform.getZoom() > maxZoom) { - jumpTo(CameraOptions().withZoom(maxZoom)); + if (changeCamera) { + jumpTo(cameraOptions); } } -double Map::getMaxZoom() const { - return impl->transform.getState().getMaxZoom(); +BoundOptions Map::getBounds() const { + return BoundOptions() + .withLatLngBounds(impl->transform.getState().getLatLngBounds()) + .withMinZoom(impl->transform.getState().getMinZoom()) + .withMaxZoom(impl->transform.getState().getMaxZoom()); } #pragma mark - Size -- cgit v1.2.1