Merge pull request #4399 from osmandapp/fix_ruler_algorithm
Fix algorithm for calculating the line between location and touch point
This commit is contained in:
commit
e082111712
1 changed files with 15 additions and 6 deletions
|
@ -30,6 +30,7 @@ public class RulerControlLayer extends OsmandMapLayer {
|
|||
private static final long DRAW_TIME = 2000;
|
||||
private static final long DELAY_BEFORE_DRAW = 500;
|
||||
private static final int TEXT_SIZE = 14;
|
||||
private static final int MAX_ITERATIONS = 50;
|
||||
|
||||
private final MapActivity mapActivity;
|
||||
private OsmandApplication app;
|
||||
|
@ -272,12 +273,18 @@ public class RulerControlLayer extends OsmandMapLayer {
|
|||
int currY = (int) tb.getPixYFromLatLon(currentLoc.getLatitude(), currentLoc.getLongitude());
|
||||
int width = tb.getPixWidth();
|
||||
int height = tb.getPixHeight();
|
||||
boolean needDraw = true;
|
||||
|
||||
if (currX < 0 || currY < 0 || currX > width || currY > height) {
|
||||
if ((currX < 0 && x == 0) || (currY < 0 && y == 0)
|
||||
|| (currX > width && x == width) || (currY > height && y == height)) {
|
||||
needDraw = false;
|
||||
} else if (currX < 0 || currY < 0 || currX > width || currY > height) {
|
||||
float xNew = (currX + x) / 2;
|
||||
float yNew = (currY + y) / 2;
|
||||
int count = 0;
|
||||
|
||||
while (true) {
|
||||
while (count < MAX_ITERATIONS) {
|
||||
count++;
|
||||
if (xNew < 0 || yNew < 0 || xNew > width || yNew > height) {
|
||||
currX = (int) xNew;
|
||||
currY = (int) yNew;
|
||||
|
@ -289,11 +296,13 @@ public class RulerControlLayer extends OsmandMapLayer {
|
|||
}
|
||||
}
|
||||
|
||||
if (needDraw) {
|
||||
canvas.rotate(-tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
|
||||
canvas.drawLine(currX, currY, x, y, lineAttrs.paint);
|
||||
drawFingerTouchIcon(canvas, x, y, nightMode);
|
||||
canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateData(RotatedTileBox tb, QuadPoint center) {
|
||||
if (tb.getPixHeight() > 0 && tb.getPixWidth() > 0 && maxRadiusInDp > 0) {
|
||||
|
|
Loading…
Reference in a new issue