From c4d7b30f0d6e9530bbbb5776300d5a2cfe547a24 Mon Sep 17 00:00:00 2001 From: Emux Date: Fri, 19 Aug 2016 19:39:06 +0300 Subject: [PATCH] Viewport: enhance toScreenPoint with relative to center option, fixes #81 --- vtm/src/org/oscim/map/Viewport.java | 30 ++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/vtm/src/org/oscim/map/Viewport.java b/vtm/src/org/oscim/map/Viewport.java index e820a1a5..126c0481 100644 --- a/vtm/src/org/oscim/map/Viewport.java +++ b/vtm/src/org/oscim/map/Viewport.java @@ -331,14 +331,33 @@ public class Viewport { } /** - * Get the screen pixel for a GeoPoint + * Get the screen pixel for a GeoPoint (relative to center) * * @param geoPoint the GeoPoint * @param out Point projected to screen pixel relative to center */ public void toScreenPoint(GeoPoint geoPoint, Point out) { + toScreenPoint(geoPoint, true, out); + } + + /** + * Get the screen pixel for a GeoPoint + * + * @param geoPoint the GeoPoint + * @param out Point projected to screen pixel + */ + public void toScreenPoint(GeoPoint geoPoint, boolean relativeToCenter, Point out) { MercatorProjection.project(geoPoint, out); - toScreenPoint(out.x, out.y, out); + toScreenPoint(out.x, out.y, relativeToCenter, out); + } + + /** + * Get the screen pixel for map coordinates (relative to center) + * + * @param out Point projected to screen coordinate relative to center + */ + public void toScreenPoint(double x, double y, Point out) { + toScreenPoint(x, y, true, out); } /** @@ -346,7 +365,7 @@ public class Viewport { * * @param out Point projected to screen coordinate */ - public void toScreenPoint(double x, double y, Point out) { + public void toScreenPoint(double x, double y, boolean relativeToCenter, Point out) { double cs = mPos.scale * Tile.SIZE; double cx = mPos.x * cs; @@ -362,6 +381,11 @@ public class Viewport { out.x = (mv[0] * (mWidth / 2)); out.y = -(mv[1] * (mHeight / 2)); + + if (!relativeToCenter) { + out.x += mWidth / 2; + out.y += mHeight / 2; + } } protected boolean copy(Viewport viewport) {