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 981501fab..27a234419 100644 --- a/include/llmr/map/transform.hpp +++ b/include/llmr/map/transform.hpp @@ -22,7 +22,7 @@ public: void cancelAnimations(); // 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/ios/MBXViewController.mm b/ios/MBXViewController.mm index 4960c59fd..580f36853 100644 --- a/ios/MBXViewController.mm +++ b/ios/MBXViewController.mm @@ -22,6 +22,7 @@ @property (nonatomic) CGPoint center; @property (nonatomic) CGFloat scale; @property (nonatomic) CGFloat angle; +@property (nonatomic) BOOL debug; @end @@ -127,7 +128,9 @@ class MBXMapView if (current - elapsed >= 1) { - NSLog(@"FPS: %f", frames / (current - elapsed)); + if (self.debug) + NSLog(@"FPS: %f", frames / (current - elapsed)); + elapsed = current; frames = 0; } @@ -148,6 +151,18 @@ class MBXMapView self.center = CGPointMake(self.center.x + delta.x, self.center.y + delta.y); } + else if (pan.state == UIGestureRecognizerStateEnded) + { + if ([pan velocityInView:pan.view].x < 50 && [pan velocityInView:pan.view].y < 50) + return; + + CGPoint finalCenter = CGPointMake(self.center.x + (0.1 * [pan velocityInView:pan.view].x), + self.center.y + (0.1 * [pan velocityInView:pan.view].y)); + + CGFloat duration = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad ? 0.3 : 0.5); + + mapView->map.moveBy(finalCenter.x - self.center.x, finalCenter.y - self.center.y, duration); + } } - (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch @@ -215,7 +230,11 @@ class MBXMapView - (void)handleThreeFingerLongPressGesture:(UILongPressGestureRecognizer *)threeFingerLongPress { if (threeFingerLongPress.state == UIGestureRecognizerStateBegan) + { mapView->map.toggleDebug(); + + self.debug = ! self.debug; + } } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 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 a94c1dad3..748ae2b84 100644 --- a/src/map/transform.cpp +++ b/src/map/transform.cpp @@ -32,9 +32,14 @@ void Transform::cancelAnimations() { animations.clear(); } -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) {