From cc6baf0d1de8dd755c34688096b0b35f6fb79d50 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 8 Jun 2017 19:04:57 +0300 Subject: [PATCH] Fix circles in off-center modes --- .../osmand/plus/views/RulerControlLayer.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java index c3ccda1f92..99de184d11 100644 --- a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java @@ -32,9 +32,11 @@ public class RulerControlLayer extends OsmandMapLayer { private int maxRadius; private int radius; private int cacheZoom; + private int height; private int halfMaxSide; private double cacheTileX; private double cacheTileY; + private int cacheCenterY; private ArrayList cacheDistances; private Bitmap centerIcon; private Paint bitmapPaint; @@ -58,7 +60,7 @@ public class RulerControlLayer extends OsmandMapLayer { DisplayMetrics displayMetrics = new DisplayMetrics(); mapActivity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); - int height = displayMetrics.heightPixels; + height = displayMetrics.heightPixels; int width = displayMetrics.widthPixels; halfMaxSide = (int) ((width > height ? width : height) / 2.2); @@ -151,13 +153,15 @@ public class RulerControlLayer extends OsmandMapLayer { } private void updateData(RotatedTileBox tb) { + boolean centerChange = cacheCenterY != tb.getCenterPixelY(); boolean move = tb.getZoom() != cacheZoom || Math.abs(tb.getCenterTileX() - cacheTileX) > 1 || - Math.abs(tb.getCenterTileY() - cacheTileY) > 1; + Math.abs(tb.getCenterTileY() - cacheTileY) > 1 || centerChange; if (!mapActivity.getMapView().isZooming() && move && tb.getPixWidth() > 0 && maxRadius > 0) { cacheZoom = tb.getZoom(); cacheTileX = tb.getCenterTileX(); cacheTileY = tb.getCenterTileY(); + cacheCenterY = tb.getCenterPixelY(); cacheDistances.clear(); final double dist = tb.getDistance(0, tb.getPixHeight() / 2, tb.getPixWidth(), tb.getPixHeight() / 2); @@ -166,10 +170,16 @@ public class RulerControlLayer extends OsmandMapLayer { OsmAndFormatter.calculateRoundedDist(maxRadius / pixDensity, app); radius = (int) (pixDensity * roundedDist); - int halfSide = halfMaxSide; + int maxHeightOfCircles; int i = 1; - while ((halfSide -= radius) > 0) { + if (portrait && cacheCenterY > height / 2) { + maxHeightOfCircles = cacheCenterY; + } else { + maxHeightOfCircles = halfMaxSide; + } + + while ((maxHeightOfCircles -= radius) > 0) { cacheDistances.add(OsmAndFormatter.getFormattedDistance((float) roundedDist * i++, app, false).replaceAll(" ", "")); }