[core] Added Map::scaleBy()
This commit is contained in:
@@ -81,6 +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& = {});
|
||||
|
||||
@@ -487,7 +487,7 @@ void GLFWView::onScroll(GLFWwindow *window, double /*xOffset*/, double yOffset)
|
||||
scale = 1.0 / scale;
|
||||
}
|
||||
|
||||
view->map->setZoom(view->map->getZoom() + ::log2(scale), mbgl::ScreenCoordinate { view->lastX, view->lastY });
|
||||
view->map->scaleBy(scale, mbgl::ScreenCoordinate { view->lastX, view->lastY });
|
||||
}
|
||||
|
||||
void GLFWView::onWindowResize(GLFWwindow *window, int width, int height) {
|
||||
@@ -530,9 +530,9 @@ void GLFWView::onMouseClick(GLFWwindow *window, int button, int action, int modi
|
||||
double now = glfwGetTime();
|
||||
if (now - view->lastClick < 0.4 /* ms */) {
|
||||
if (modifiers & GLFW_MOD_SHIFT) {
|
||||
view->map->setZoom(view->map->getZoom() - 1, mbgl::ScreenCoordinate { view->lastX, view->lastY }, mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
|
||||
view->map->scaleBy(0.5, mbgl::ScreenCoordinate { view->lastX, view->lastY }, mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
|
||||
} else {
|
||||
view->map->setZoom(view->map->getZoom() + 1, mbgl::ScreenCoordinate { view->lastX, view->lastY }, mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
|
||||
view->map->scaleBy(2.0, mbgl::ScreenCoordinate { view->lastX, view->lastY }, mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
|
||||
}
|
||||
}
|
||||
view->lastClick = now;
|
||||
|
||||
@@ -1126,7 +1126,7 @@ void QMapboxGL::moveBy(const QPointF &offset)
|
||||
can be used for implementing a pinch gesture.
|
||||
*/
|
||||
void QMapboxGL::scaleBy(double scale_, const QPointF ¢er) {
|
||||
d_ptr->mapObj->setZoom(d_ptr->mapObj->getZoom() + ::log2(scale_), mbgl::ScreenCoordinate { center.x(), center.y() });
|
||||
d_ptr->mapObj->scaleBy(scale_, mbgl::ScreenCoordinate { center.x(), center.y() });
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -187,6 +187,11 @@ 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);
|
||||
easeTo(CameraOptions().withZoom(zoom).withAnchor(anchor), animation);
|
||||
}
|
||||
|
||||
void Map::setZoom(double zoom, const AnimationOptions& animation) {
|
||||
easeTo(CameraOptions().withZoom(zoom), animation);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user