From e48207a4ef13ee7bc0594886cf53f5dbc6415c37 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Thu, 6 Feb 2014 16:08:44 -0500 Subject: [PATCH 1/4] allow for animated moves --- include/llmr/map/map.hpp | 2 +- include/llmr/map/transform.hpp | 2 +- src/map/map.cpp | 4 ++-- src/map/transform.cpp | 11 ++++++++--- 4 files changed, 12 insertions(+), 7 deletions(-) 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) { From a95f0a8621bf9f62b20947723d16fc5f0d3d0e95 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Thu, 6 Feb 2014 16:09:12 -0500 Subject: [PATCH 2/4] fixes #34: decelerated panning --- ios/MBXViewController.mm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ios/MBXViewController.mm b/ios/MBXViewController.mm index 4960c59fd..330855a39 100644 --- a/ios/MBXViewController.mm +++ b/ios/MBXViewController.mm @@ -148,6 +148,15 @@ class MBXMapView self.center = CGPointMake(self.center.x + delta.x, self.center.y + delta.y); } + else if (pan.state == UIGestureRecognizerStateEnded) + { + 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 From 29744cfa5afd1de981513f70bf1c31dec84f35be Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Thu, 6 Feb 2014 16:27:54 -0500 Subject: [PATCH 3/4] refs #34: don't decelerate pan for low velocity --- ios/MBXViewController.mm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ios/MBXViewController.mm b/ios/MBXViewController.mm index 330855a39..a35ae5f5a 100644 --- a/ios/MBXViewController.mm +++ b/ios/MBXViewController.mm @@ -150,6 +150,9 @@ class MBXMapView } 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)); From 6d75c0209d889af36948212dc1bc5f4efd78914f Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Thu, 6 Feb 2014 17:06:02 -0500 Subject: [PATCH 4/4] only output FPS on iOS when in debug mode --- ios/MBXViewController.mm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ios/MBXViewController.mm b/ios/MBXViewController.mm index a35ae5f5a..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; } @@ -227,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