diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/map.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/map/source.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/map/transform.cpp | 47 | ||||
-rw-r--r-- | src/mbgl/map/transform.hpp | 8 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.cpp | 24 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.hpp | 9 |
6 files changed, 50 insertions, 52 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 5360e294c0..01e199f460 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -186,11 +186,11 @@ void Map::resetZoom() { } double Map::getMinZoom() const { - return data->transform.getMinZoom(); + return data->transform.currentState().getMinZoom(); } double Map::getMaxZoom() const { - return data->transform.getMaxZoom(); + return data->transform.currentState().getMaxZoom(); } @@ -279,7 +279,7 @@ uint32_t Map::addPointAnnotation(const LatLng& point, const std::string& symbol) AnnotationIDs Map::addPointAnnotations(const AnnotationSegment& points, const std::vector<std::string>& symbols) { AnnotationsProperties properties = { { "symbols", symbols } }; - auto result = data->annotationManager.addPointAnnotations(points, properties, data->transform.getMaxZoom()); + auto result = data->annotationManager.addPointAnnotations(points, properties, getMaxZoom()); context->invoke(&MapContext::updateAnnotationTiles, result.first); return result.second; } @@ -291,7 +291,7 @@ uint32_t Map::addShapeAnnotation(const AnnotationSegments& shape, AnnotationIDs Map::addShapeAnnotations(const std::vector<AnnotationSegments>& shapes, const std::vector<StyleProperties>& styleProperties) { - auto result = data->annotationManager.addShapeAnnotations(shapes, styleProperties, {{}}, data->transform.getMaxZoom()); + auto result = data->annotationManager.addShapeAnnotations(shapes, styleProperties, {{}}, getMaxZoom()); context->invoke(&MapContext::updateAnnotationTiles, result.first); return result.second; } @@ -301,12 +301,12 @@ void Map::removeAnnotation(uint32_t annotation) { } void Map::removeAnnotations(const std::vector<uint32_t>& annotations) { - auto result = data->annotationManager.removeAnnotations(annotations, data->transform.getMaxZoom()); + auto result = data->annotationManager.removeAnnotations(annotations, getMaxZoom()); context->invoke(&MapContext::updateAnnotationTiles, result); } std::vector<uint32_t> Map::getAnnotationsInBounds(const LatLngBounds& bounds, const AnnotationType& type) { - return data->annotationManager.getAnnotationsInBounds(bounds, data->transform.getMaxZoom(), type); + return data->annotationManager.getAnnotationsInBounds(bounds, getMaxZoom(), type); } LatLngBounds Map::getBoundsForAnnotations(const std::vector<uint32_t>& annotations) { diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index c9f3e84210..b073321a77 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -468,7 +468,7 @@ bool Source::update(MapData& data, if (info.type != SourceType::Raster && cache.getSize() == 0) { size_t conservativeCacheSize = ((float)transformState.getWidth() / util::tileSize) * ((float)transformState.getHeight() / util::tileSize) * - (data.transform.getMaxZoom() - data.transform.getMinZoom() + 1) * + (transformState.getMaxZoom() - transformState.getMinZoom() + 1) * 0.5; cache.setSize(conservativeCacheSize); } diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index cca0c2a580..b7296f6f7e 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -47,7 +47,7 @@ bool Transform::resize(const uint16_t w, const uint16_t h, const float ratio, state.pixelRatio = ratio; state.framebuffer[0] = fb_w; state.framebuffer[1] = fb_h; - constrain(state.scale, state.y); + state.constrain(state.scale, state.y); view.notifyMapChange(MapChangeRegionDidChange); @@ -79,7 +79,7 @@ void Transform::_moveBy(const double dx, const double dy, const Duration duratio double x = state.x + std::cos(state.angle) * dx + std::sin( state.angle) * dy; double y = state.y + std::cos(state.angle) * dy + std::sin(-state.angle) * dx; - constrain(state.scale, y); + state.constrain(state.scale, y); if (duration == Duration::zero()) { state.x = x; @@ -156,10 +156,10 @@ void Transform::scaleBy(const double ds, const double cx, const double cy, const // clamp scale to min/max values double new_scale = state.scale * ds; - if (new_scale < min_scale) { - new_scale = min_scale; - } else if (new_scale > max_scale) { - new_scale = max_scale; + if (new_scale < state.min_scale) { + new_scale = state.min_scale; + } else if (new_scale > state.max_scale) { + new_scale = state.max_scale; } _setScale(new_scale, cx, cy, duration); @@ -198,26 +198,14 @@ double Transform::getScale() const { return state.scale; } -double Transform::getMinZoom() const { - double test_scale = state.scale; - double test_y = state.y; - constrain(test_scale, test_y); - - return std::log2(std::fmin(min_scale, test_scale)); -} - -double Transform::getMaxZoom() const { - return std::log2(max_scale); -} - void Transform::_setScale(double new_scale, double cx, double cy, const Duration duration) { // This is only called internally, so we don't need a lock here. // Ensure that we don't zoom in further than the maximum allowed. - if (new_scale < min_scale) { - new_scale = min_scale; - } else if (new_scale > max_scale) { - new_scale = max_scale; + if (new_scale < state.min_scale) { + new_scale = state.min_scale; + } else if (new_scale > state.max_scale) { + new_scale = state.max_scale; } // Zoom in on the center if we don't have click or gesture anchor coordinates. @@ -255,7 +243,7 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl double x = xn; double y = yn; - constrain(scale, y); + state.constrain(scale, y); if (duration == Duration::zero()) { state.scale = scale; @@ -293,19 +281,6 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl duration); } -#pragma mark - Constraints - -void Transform::constrain(double& scale, double& y) const { - // Constrain minimum zoom to avoid zooming out far enough to show off-world areas. - if (scale < (state.height / util::tileSize)) scale = (state.height / util::tileSize); - - // Constrain min/max vertical pan to avoid showing off-world areas. - double max_y = ((scale * util::tileSize) - state.height) / 2; - - if (y > max_y) y = max_y; - if (y < -max_y) y = -max_y; -} - #pragma mark - Angle void Transform::rotateBy(const double start_x, const double start_y, const double end_x, diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp index 1c29802d72..a92b4abaf8 100644 --- a/src/mbgl/map/transform.hpp +++ b/src/mbgl/map/transform.hpp @@ -36,8 +36,6 @@ public: void setZoom(double zoom, Duration = Duration::zero()); double getZoom() const; double getScale() const; - double getMinZoom() const; - double getMaxZoom() const; // Angle void rotateBy(double sx, double sy, double ex, double ey, Duration = Duration::zero()); @@ -64,18 +62,12 @@ private: void _setScaleXY(double new_scale, double xn, double yn, Duration = Duration::zero()); void _setAngle(double angle, Duration = Duration::zero()); - void constrain(double& scale, double& y) const; - View &view; mutable std::recursive_mutex mtx; TransformState state; - // Limit the amount of zooming possible on the map. - const double min_scale = std::pow(2, 0); - const double max_scale = std::pow(2, 18); - void startTransition(std::function<Update(double)> frame, std::function<void()> finish, Duration); diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index 8002a07f2b..3c4acc7e06 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -152,6 +152,18 @@ double TransformState::getScale() const { return scale; } +double TransformState::getMinZoom() const { + double test_scale = scale; + double test_y = y; + constrain(test_scale, test_y); + + return std::log2(std::fmin(min_scale, test_scale)); +} + +double TransformState::getMaxZoom() const { + return std::log2(max_scale); +} + #pragma mark - Rotation @@ -256,6 +268,18 @@ bool TransformState::isChanging() const { #pragma mark - (private helper functions) +void TransformState::constrain(double& scale_, double& y_) const { + // Constrain minimum zoom to avoid zooming out far enough to show off-world areas. + if (scale_ < height / util::tileSize) { + scale_ = height / util::tileSize; + } + + // Constrain min/max vertical pan to avoid showing off-world areas. + double max_y = ((scale_ * util::tileSize) - height) / 2; + + if (y_ > max_y) y_ = max_y; + if (y_ < -max_y) y_ = -max_y; +} double TransformState::pixel_x() const { const double center = (width - scale * util::tileSize) / 2; diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp index 3e76c7f817..63aa6444fb 100644 --- a/src/mbgl/map/transform_state.hpp +++ b/src/mbgl/map/transform_state.hpp @@ -47,6 +47,8 @@ public: int32_t getIntegerZoom() const; double getZoomFraction() const; double getScale() const; + double getMinZoom() const; + double getMaxZoom() const; // Rotation float getAngle() const; @@ -59,10 +61,15 @@ public: bool isChanging() const; private: + void constrain(double& scale, double& y) const; + + // Limit the amount of zooming possible on the map. + double min_scale = std::pow(2, 0); + double max_scale = std::pow(2, 18); + double pixel_x() const; double pixel_y() const; -private: // logical dimensions uint16_t width = 0, height = 0; |