diff options
author | Ander Conselvan de Oliveira <ander.deoliveira@mapbox.com> | 2019-03-08 12:43:05 +0200 |
---|---|---|
committer | Ander Conselvan de Oliveira <ander.deoliveira@mapbox.com> | 2019-03-14 18:33:11 +0200 |
commit | 57334407473a31ff43baa645dafd2f5e1bd910fb (patch) | |
tree | e981f87c0040799a1ebc45f86d05b3ece6916aba /src | |
parent | 11de777628e9e2c4b219bae3f1a6eabd86f2a3c5 (diff) | |
download | qtlocation-mapboxgl-57334407473a31ff43baa645dafd2f5e1bd910fb.tar.gz |
[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.
Diffstat (limited to 'src')
-rw-r--r-- | src/core-files.json | 1 | ||||
-rw-r--r-- | src/mbgl/map/map.cpp | 49 |
2 files changed, 28 insertions, 22 deletions
diff --git a/src/core-files.json b/src/core-files.json index 8915ebc49d..6415f03182 100644 --- a/src/core-files.json +++ b/src/core-files.json @@ -328,6 +328,7 @@ "mbgl/layermanager/line_layer_factory.hpp": "include/mbgl/layermanager/line_layer_factory.hpp", "mbgl/layermanager/raster_layer_factory.hpp": "include/mbgl/layermanager/raster_layer_factory.hpp", "mbgl/layermanager/symbol_layer_factory.hpp": "include/mbgl/layermanager/symbol_layer_factory.hpp", + "mbgl/map/bound_options.hpp": "include/mbgl/map/bound_options.hpp", "mbgl/map/camera.hpp": "include/mbgl/map/camera.hpp", "mbgl/map/change.hpp": "include/mbgl/map/change.hpp", "mbgl/map/map.hpp": "include/mbgl/map/map.hpp", 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 |