From 49981b8358c74d54e2211efbf91e8bb45772f0ac Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 17 Jan 2018 12:57:36 +0200 Subject: [PATCH] Change click radius for waypoints, markers and favorites; extract common code to superclass --- .../osmand/plus/views/FavouritesLayer.java | 4 ++-- .../src/net/osmand/plus/views/GPXLayer.java | 4 ++-- .../osmand/plus/views/MapMarkersLayer.java | 19 ++----------------- .../net/osmand/plus/views/OsmandMapLayer.java | 15 +++++++++++++++ .../plus/views/PointNavigationLayer.java | 17 +---------------- 5 files changed, 22 insertions(+), 37 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java b/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java index 07f72d42db..626d27161f 100644 --- a/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java @@ -75,7 +75,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer. } private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) { - return (Math.abs(objx - ex) <= radius * 2 && Math.abs(objy - ey) <= radius * 2) ; + return (Math.abs(objx - ex) <= radius * 1.5 && Math.abs(objy - ey) <= radius * 1.5) ; // return Math.abs(objx - ex) <= radius && (ey - objy) <= radius / 2 && (objy - ey) <= 3 * radius ; //return Math.abs(objx - ex) <= radius && (ey - objy) <= radius / 2 && (objy - ey) <= 3 * radius ; } @@ -179,7 +179,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer. } public void getFavoriteFromPoint(RotatedTileBox tb, PointF point, List res) { - int r = (int) (15 * tb.getDensity()); + int r = getDefaultRadiusPoi(tb); int ex = (int) point.x; int ey = (int) point.y; for (FavouritePoint n : getPoints()) { diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 1b89f257a9..0aa24e8701 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -533,12 +533,12 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex } private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) { - return (Math.abs(objx - ex) <= radius * 2 && Math.abs(objy - ey) <= radius * 2); + return (Math.abs(objx - ex) <= radius * 1.5 && Math.abs(objy - ey) <= radius * 1.5); // return Math.abs(objx - ex) <= radius && (ey - objy) <= radius / 2 && (objy - ey) <= 3 * radius ; } public void getWptFromPoint(RotatedTileBox tb, PointF point, List res) { - int r = (int) (15 * tb.getDensity()); + int r = getDefaultRadiusPoi(tb); int ex = (int) point.x; int ey = (int) point.y; for (SelectedGpxFile g : selectedGpxHelper.getSelectedGPXFiles()) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index dc928b52ed..8a3471be2d 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -519,7 +519,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi } OsmandApplication app = map.getMyApplication(); - int r = getRadiusPoi(tileBox); + int r = getDefaultRadiusPoi(tileBox); boolean selectMarkerOnSingleTap = app.getSettings().SELECT_MARKER_ON_SINGLE_TAP.get(); for (MapMarker marker : app.getMapMarkersHelper().getMapMarkers()) { @@ -563,22 +563,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi } private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) { - return Math.abs(objx - ex) <= radius && (ey - objy) <= radius && (objy - ey) <= 2.5 * radius; - } - - public int getRadiusPoi(RotatedTileBox tb) { - int r; - final double zoom = tb.getZoom(); - if (zoom <= 15) { - r = 10; - } else if (zoom <= 16) { - r = 14; - } else if (zoom <= 17) { - r = 16; - } else { - r = 18; - } - return (int) (r * tb.getDensity()); + return Math.abs(objx - ex) <= radius * 1.5 && (ey - objy) <= radius * 1.5 && (objy - ey) <= 2.5 * radius; } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index 818a172173..5969853e95 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -261,6 +261,21 @@ public abstract class OsmandMapLayer { return res; } + public int getDefaultRadiusPoi(RotatedTileBox tb) { + int r; + final double zoom = tb.getZoom(); + if (zoom <= 15) { + r = 10; + } else if (zoom <= 16) { + r = 14; + } else if (zoom <= 17) { + r = 16; + } else { + r = 18; + } + return (int) (r * tb.getDensity()); + } + public abstract class MapLayerData { public int ZOOM_THRESHOLD = 1; public RotatedTileBox queriedBox; diff --git a/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java b/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java index 256f3bd23c..ad56fff866 100644 --- a/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java @@ -188,7 +188,7 @@ public class PointNavigationLayer extends OsmandMapLayer implements if (tileBox.getZoom() >= 3) { TargetPointsHelper tg = map.getMyApplication().getTargetPointsHelper(); List intermediatePoints = tg.getAllPoints(); - int r = getRadiusPoi(tileBox); + int r = getDefaultRadiusPoi(tileBox); for (int i = 0; i < intermediatePoints.size(); i++) { TargetPoint tp = intermediatePoints.get(i); LatLon latLon = tp.point; @@ -209,21 +209,6 @@ public class PointNavigationLayer extends OsmandMapLayer implements return Math.abs(objx - ex) <= radius && (ey - objy) <= radius && (objy - ey) <= 2.5 * radius; } - public int getRadiusPoi(RotatedTileBox tb) { - int r; - final double zoom = tb.getZoom(); - if (zoom <= 15) { - r = 10; - } else if (zoom <= 16) { - r = 14; - } else if (zoom <= 17) { - r = 16; - } else { - r = 18; - } - return (int) (r * tb.getDensity()); - } - @Override public LatLon getObjectLocation(Object o) { if (o instanceof TargetPoint) {