diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp index a751da5be..117bf3402 100644 --- a/include/llmr/map/map.hpp +++ b/include/llmr/map/map.hpp @@ -32,7 +32,7 @@ public: void tileFailed(std::shared_ptr tile); /* position */ - void moveBy(double dx, double dy); + void moveBy(double dx, double dy, double duration = 0); // void setLonLat(double lon, double lat); void resetPosition(); diff --git a/include/llmr/map/transform.hpp b/include/llmr/map/transform.hpp index c1633ea70..6836ce906 100644 --- a/include/llmr/map/transform.hpp +++ b/include/llmr/map/transform.hpp @@ -21,7 +21,7 @@ public: void updateAnimations(); // Relative changes - void moveBy(double dx, double dy); + void moveBy(double dx, double dy, double duration = 0); void scaleBy(double ds, double cx = -1, double cy = -1, double duration = 0); void rotateBy(double cx, double cy, double sx, double sy, double ex, double ey); diff --git a/src/map/map.cpp b/src/map/map.cpp index afc3c72f6..e53af16e8 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -57,8 +57,8 @@ void Map::resize(uint32_t width, uint32_t height, uint32_t fb_width, uint32_t fb update(); } -void Map::moveBy(double dx, double dy) { - transform.moveBy(dx, dy); +void Map::moveBy(double dx, double dy, double duration) { + transform.moveBy(dx, dy, duration); update(); transform.getLonLat(settings.longitude, settings.latitude); diff --git a/src/map/transform.cpp b/src/map/transform.cpp index f28571952..6d11c1025 100644 --- a/src/map/transform.cpp +++ b/src/map/transform.cpp @@ -28,9 +28,14 @@ void Transform::updateAnimations() { }); } -void Transform::moveBy(double dx, double dy) { - x += cos(angle) * dx + sin(angle) * dy; - y += cos(angle) * dy + sin(-angle) * dx; +void Transform::moveBy(double dx, double dy, double duration) { + if (duration == 0) { + x += cos(angle) * dx + sin(angle) * dy; + y += cos(angle) * dy + sin(-angle) * dx; + } else { + animations.emplace_front(x, x + cos(angle) * dx + sin(angle) * dy, x, duration); + animations.emplace_front(y, y + cos(angle) * dy + sin(-angle) * dx, y, duration); + } } void Transform::scaleBy(double ds, double cx, double cy, double duration) {