Merge pull request #4226 from osmandapp/fix_ruler

Fix ruler
This commit is contained in:
Alexey 2017-07-28 11:41:20 +03:00 committed by GitHub
commit 39ae8c80b2

View file

@ -156,7 +156,7 @@ public class RulerControlLayer extends OsmandMapLayer {
if (d > acceptableTouchRadius) {
touchOutside = true;
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
} else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
touched = false;
touchEndTime = System.currentTimeMillis();
refreshMapDelayed();
@ -205,8 +205,8 @@ public class RulerControlLayer extends OsmandMapLayer {
drawCenterIcon(canvas, tb, center, settings.isNightMode(), mode);
Location currentLoc = app.getLocationProvider().getLastKnownLocation();
if (showDistBetweenFingerAndLocation && currentLoc != null) {
float x = tb.getPixXFromLonNoRot(touchPointLatLon.getLongitude());
float y = tb.getPixYFromLatNoRot(touchPointLatLon.getLatitude());
float x = tb.getPixXFromLatLon(touchPointLatLon.getLatitude(), touchPointLatLon.getLongitude());
float y = tb.getPixYFromLatLon(touchPointLatLon.getLatitude(), touchPointLatLon.getLongitude());
drawDistBetweenFingerAndLocation(canvas, tb, x, y, currentLoc, settings.isNightMode());
} else if (showTwoFingersDistance) {
LatLon firstTouchPoint = view.getFirstTouchPointLatLon();
@ -272,21 +272,31 @@ public class RulerControlLayer extends OsmandMapLayer {
private void drawDistBetweenFingerAndLocation(Canvas canvas, RotatedTileBox tb, float x, float y,
Location currentLoc, boolean nightMode) {
int currX = tb.getPixXFromLonNoRot(currentLoc.getLongitude());
int currY = tb.getPixYFromLatNoRot(currentLoc.getLatitude());
distancePath.reset();
tx.clear();
ty.clear();
int currX = (int) tb.getPixXFromLatLon(currentLoc.getLatitude(), currentLoc.getLongitude());
int currY = (int) tb.getPixYFromLatLon(currentLoc.getLatitude(), currentLoc.getLongitude());
int width = tb.getPixWidth();
int height = tb.getPixHeight();
tx.add(currX);
ty.add(currY);
tx.add((int) x);
ty.add((int) y);
if (currX < 0 || currY < 0 || currX > width || currY > height) {
float xNew = (currX + x) / 2;
float yNew = (currY + y) / 2;
calculatePath(tb, tx, ty, distancePath);
canvas.drawPath(distancePath, lineAttrs.paint);
// canvas.drawLine(currX, currY, x, y, lineAttrs.paint);
while (true) {
if (xNew < 0 || yNew < 0 || xNew > width || yNew > height) {
currX = (int) xNew;
currY = (int) yNew;
} else {
break;
}
xNew = (xNew + x) / 2;
yNew = (yNew + y) / 2;
}
}
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) {