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 /platform | |
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 'platform')
-rwxr-xr-x | platform/android/src/native_map_view.cpp | 14 | ||||
-rw-r--r-- | platform/glfw/glfw_view.cpp | 2 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 16 | ||||
-rw-r--r-- | platform/macos/src/MGLMapView.mm | 10 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl.cpp | 4 |
5 files changed, 24 insertions, 22 deletions
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 83a158efa9..3a4e2014ba 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -287,11 +287,13 @@ void NativeMapView::setStyleJson(jni::JNIEnv& env, const jni::String& json) { } void NativeMapView::setLatLngBounds(jni::JNIEnv& env, const jni::Object<mbgl::android::LatLngBounds>& jBounds) { + mbgl::BoundOptions bounds; if (jBounds) { - map->setLatLngBounds(mbgl::android::LatLngBounds::getLatLngBounds(env, jBounds)); + bounds.withLatLngBounds(mbgl::android::LatLngBounds::getLatLngBounds(env, jBounds)); } else { - map->setLatLngBounds(mbgl::LatLngBounds::world()); + bounds.withLatLngBounds(mbgl::LatLngBounds::world()); } + map->setBounds(bounds); } void NativeMapView::cancelTransitions(jni::JNIEnv&) { @@ -424,19 +426,19 @@ void NativeMapView::resetZoom(jni::JNIEnv&) { } void NativeMapView::setMinZoom(jni::JNIEnv&, jni::jdouble zoom) { - map->setMinZoom(zoom); + map->setBounds(BoundOptions().withMinZoom(zoom)); } jni::jdouble NativeMapView::getMinZoom(jni::JNIEnv&) { - return map->getMinZoom(); + return *map->getBounds().minZoom; } void NativeMapView::setMaxZoom(jni::JNIEnv&, jni::jdouble zoom) { - map->setMaxZoom(zoom); + map->setBounds(BoundOptions().withMaxZoom(zoom)); } jni::jdouble NativeMapView::getMaxZoom(jni::JNIEnv&) { - return map->getMaxZoom(); + return *map->getBounds().maxZoom; } void NativeMapView::rotateBy(jni::JNIEnv&, jni::jdouble sx, jni::jdouble sy, jni::jdouble ex, jni::jdouble ey, jni::jlong duration) { diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index 86833da6ee..e768851a53 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -296,7 +296,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, mbgl::LatLngBounds bound = bounds[nextBound++]; nextBound = nextBound % bounds.size(); - view->map->setLatLngBounds(bound); + view->map->setBounds(mbgl::BoundOptions().withLatLngBounds(bound)); if (bound == mbgl::LatLngBounds::unbounded()) { view->map->removeAnnotation(boundAnnotationID); diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index f393dec0c1..692da30f04 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1661,7 +1661,7 @@ public: newScale += scale / (velocity * duration) * 0.1; } - if (newScale <= 0 || log2(newScale) < self.mbglMap.getMinZoom()) + if (newScale <= 0 || log2(newScale) < *self.mbglMap.getBounds().minZoom) { velocity = 0; } @@ -1927,7 +1927,7 @@ public: if ( ! self.isZoomEnabled) return; - if ([self zoomLevel] == self.mbglMap.getMinZoom()) return; + if ([self zoomLevel] == *self.mbglMap.getBounds().minZoom) return; [self cancelTransitions]; @@ -1979,7 +1979,7 @@ public: { CGFloat distance = [quickZoom locationInView:quickZoom.view].y - self.quickZoomStart; - CGFloat newZoom = MAX(log2f(self.scale) + (distance / 75), self.mbglMap.getMinZoom()); + CGFloat newZoom = MAX(log2f(self.scale) + (distance / 75), *self.mbglMap.getBounds().minZoom); if ([self zoomLevel] == newZoom) return; @@ -3251,23 +3251,23 @@ public: - (void)setMinimumZoomLevel:(double)minimumZoomLevel { MGLLogDebug(@"Setting minimumZoomLevel: %f", minimumZoomLevel); - self.mbglMap.setMinZoom(minimumZoomLevel); + self.mbglMap.setBounds(mbgl::BoundOptions().withMinZoom(minimumZoomLevel)); } - (double)minimumZoomLevel { - return self.mbglMap.getMinZoom(); + return *self.mbglMap.getBounds().minZoom; } - (void)setMaximumZoomLevel:(double)maximumZoomLevel { MGLLogDebug(@"Setting maximumZoomLevel: %f", maximumZoomLevel); - self.mbglMap.setMaxZoom(maximumZoomLevel); + self.mbglMap.setBounds(mbgl::BoundOptions().withMaxZoom(maximumZoomLevel)); } - (double)maximumZoomLevel { - return self.mbglMap.getMaxZoom(); + return *self.mbglMap.getBounds().maxZoom; } - (MGLCoordinateBounds)visibleCoordinateBounds @@ -5847,7 +5847,7 @@ public: - (CGFloat)currentMinimumZoom { - return fmaxf(self.mbglMap.getMinZoom(), MGLMinimumZoom); + return fmaxf(*self.mbglMap.getBounds().minZoom, MGLMinimumZoom); } - (BOOL)isRotationAllowed diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 054b91d44c..320abf740c 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -328,7 +328,7 @@ public: mbgl::CameraOptions options; options.center = mbgl::LatLng(0, 0); options.padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets); - options.zoom = _mbglMap->getMinZoom(); + options.zoom = *_mbglMap->getBounds().minZoom; _mbglMap->jumpTo(options); _pendingLatitude = NAN; _pendingLongitude = NAN; @@ -1094,21 +1094,21 @@ public: - (void)setMinimumZoomLevel:(double)minimumZoomLevel { MGLLogDebug(@"Setting minimumZoomLevel: %f", minimumZoomLevel); - _mbglMap->setMinZoom(minimumZoomLevel); + _mbglMap->setBounds(mbgl::BoundOptions().withMinZoom(minimumZoomLevel)); } - (void)setMaximumZoomLevel:(double)maximumZoomLevel { MGLLogDebug(@"Setting maximumZoomLevel: %f", maximumZoomLevel); - _mbglMap->setMaxZoom(maximumZoomLevel); + _mbglMap->setBounds(mbgl::BoundOptions().withMaxZoom(maximumZoomLevel)); } - (double)maximumZoomLevel { - return _mbglMap->getMaxZoom(); + return *_mbglMap->getBounds().maxZoom; } - (double)minimumZoomLevel { - return _mbglMap->getMinZoom(); + return *_mbglMap->getBounds().minZoom; } /// Respond to a click on the zoom control. diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index 990e70c97f..b05c82a783 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -765,7 +765,7 @@ void QMapboxGL::setZoom(double zoom_) */ double QMapboxGL::minimumZoom() const { - return d_ptr->mapObj->getMinZoom(); + return *d_ptr->mapObj->getBounds().minZoom; } /*! @@ -775,7 +775,7 @@ double QMapboxGL::minimumZoom() const */ double QMapboxGL::maximumZoom() const { - return d_ptr->mapObj->getMaxZoom(); + return *d_ptr->mapObj->getBounds().maxZoom; } /*! |