fixes #33: rotate around arbitrary point

This commit is contained in:
Justin R. Miller
2014-02-04 16:01:09 -05:00
parent e00efd5c2c
commit dbea7937b3
3 changed files with 17 additions and 3 deletions

View File

@@ -54,7 +54,7 @@ public:
/* rotation */
void rotateBy(double cx, double cy, double sx, double sy, double ex, double ey);
void setAngle(double angle);
void setAngle(double angle, double cx = -1, double cy = -1);
double getAngle() const;
void resetNorth();

View File

@@ -210,7 +210,7 @@ class MBXMapView
}
else if (rotate.state == UIGestureRecognizerStateChanged)
{
mapView->map.setAngle(self.angle + rotate.rotation);
mapView->map.setAngle(self.angle + rotate.rotation, [rotate locationInView:rotate.view].x, [rotate locationInView:rotate.view].y);
}
}

View File

@@ -93,10 +93,24 @@ void Map::setScale(double scale) {
settings.save();
}
void Map::setAngle(double angle) {
void Map::setAngle(double angle, double x, double y) {
double dx, dy;
if (x >= 0 && y >= 0) {
dx = (transform.width / 2) - x;
dy = (transform.height / 2) - y;
transform.moveBy(dx, dy);
}
transform.setAngle(angle);
if (x >= 0 && y >= 0) {
transform.moveBy(-dx, -dy);
}
update();
transform.getLonLat(settings.longitude, settings.latitude);
settings.angle = transform.getAngle();
settings.save();
}