From a2aa63e3b6cc7ef020d2e81da3879af1ceb215e1 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 13 May 2015 23:19:19 +0200 Subject: [PATCH 1/2] Add action layer --- .../src/net/osmand/plus/views/RouteLayer.java | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java index 1d0d3562b6..8c11314a2a 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java @@ -24,6 +24,7 @@ import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Matrix; import android.graphics.Paint; +import android.graphics.PorterDuff; import android.graphics.Paint.Cap; import android.graphics.Paint.Join; import android.graphics.Paint.Style; @@ -57,6 +58,7 @@ public class RouteLayer extends OsmandMapLayer { private Bitmap actionArrow; private Paint paintIcon; + private Paint paintIconAction; private OsmandRenderer osmandRenderer; @@ -79,7 +81,7 @@ public class RouteLayer extends OsmandMapLayer { actionPaint.setAntiAlias(true); actionPaint.setStrokeCap(Cap.BUTT); actionPaint.setStrokeJoin(Join.ROUND); - actionPaint.setStrokeWidth(7 * view.getDensity()); + actionPaint.setStrokeWidth(7 * view.getScaleCoefficient()); actionPaint.setColor(Color.WHITE); path = new Path(); @@ -89,6 +91,11 @@ public class RouteLayer extends OsmandMapLayer { paintIcon.setColor(Color.BLACK); paintIcon.setStrokeWidth(3); + + paintIconAction = new Paint(); + paintIconAction.setFilterBitmap(true); + paintIconAction.setAntiAlias(true); + } @Override @@ -118,9 +125,11 @@ public class RouteLayer extends OsmandMapLayer { paint.setStrokeWidth(12 * view.getDensity()); } osmandRenderer.updatePaint(req, actionPaint, 2, false, rc); + actionPaint.setColor(Color.BLUE); + paintIconAction.setColorFilter(new PorterDuffColorFilter(actionPaint.getColor(), Mode.MULTIPLY)); // TODO remove - actionPaint.setStrokeWidth(7 * view.getDensity()); - actionPaint.setColor(Color.WHITE); + // actionPaint.setColor(Color.WHITE); + isPaint2 = osmandRenderer.updatePaint(req, paint2, 1, false, rc); isPaint_1 = osmandRenderer.updatePaint(req, paint_1, -1, false, rc); isShadowPaint = req.isSpecified(rrs.PROPS.R_SHADOW_RADIUS); @@ -132,8 +141,8 @@ public class RouteLayer extends OsmandMapLayer { } else { System.err.println("Rendering attribute route is not found !"); paint.setStrokeWidth(12 * view.getDensity()); - actionPaint.setStrokeWidth(7 * view.getDensity()); } + actionPaint.setStrokeWidth(7 * view.getScaleCoefficient()); } } } @@ -192,9 +201,9 @@ public class RouteLayer extends OsmandMapLayer { Location o = actionPoints.get(i); if (o == null) { canvas.drawPath(pth, actionPaint); - float angleRad = (float) Math.atan2(y - py, x - px); - float angle = (float) (angleRad * 180 / Math.PI) + 90f; - float distSegment = FloatMath.sqrt((y - py) * (y - py) + (x - px) * (x - px)); + double angleRad = Math.atan2(y - py, x - px); + double angle = (angleRad * 180 / Math.PI) + 90f; + double distSegment = FloatMath.sqrt((y - py) * (y - py) + (x - px) * (x - px)); if (distSegment == 0) { continue; } @@ -203,9 +212,9 @@ public class RouteLayer extends OsmandMapLayer { float pdy = y - py; matrix.reset(); matrix.postTranslate(0, -actionArrow.getHeight() / 2); - matrix.postRotate(angle, actionArrow.getWidth() / 2, 0); + matrix.postRotate((float) angle, actionArrow.getWidth() / 2, 0); matrix.postTranslate(px + pdx - actionArrow.getWidth() / 2, py + pdy); - canvas.drawBitmap(actionArrow, matrix, paintIcon); + canvas.drawBitmap(actionArrow, matrix, paintIconAction); first = true; } else { px = x; @@ -343,7 +352,7 @@ public class RouteLayer extends OsmandMapLayer { drawSegment(tb, canvas); if (tb.getZoom() >= 14) { calculateActionPoints(topLatitude, leftLongitude, bottomLatitude, rightLongitude, lastProjection, - routeNodes, cd, it); + routeNodes, cd, it, tb.getZoom()); drawAction(tb, canvas); } } @@ -351,12 +360,13 @@ public class RouteLayer extends OsmandMapLayer { private void calculateActionPoints(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, Location lastProjection, List routeNodes, int cd, - Iterator it) { + Iterator it, int zoom) { RouteDirectionInfo nf = null; - double DISTANCE_ACTION = 35; + double DISTANCE_ACTION = zoom >= 17 ? 15 : 35; double actionDist = 0; Location previousAction = null; actionPoints.clear(); + int prevPoint = -1; for (int i = 0; i < routeNodes.size(); i++) { Location ls = routeNodes.get(i); if(nf != null && nf.routePointOffset < i + cd) { @@ -379,8 +389,8 @@ public class RouteLayer extends OsmandMapLayer { float loc = ls.distanceTo(previousAction); actionDist += loc; if(actionDist >= DISTANCE_ACTION) { - // calculate distance proj? actionPoints.add(calculateProjection(1 - (actionDist - DISTANCE_ACTION) / loc, previousAction, ls)); + prevPoint = i; actionPoints.add(null); previousAction = null; actionDist = 0; @@ -407,6 +417,11 @@ public class RouteLayer extends OsmandMapLayer { } break; } else { + if(prevPoint == k) { + actionPoints.remove(ind - 1); + actionPoints.remove(ind - 1); + prevPoint = -1; + } actionPoints.add(ind, l); lp = l; } From 7bad767b52e1296bbf4270df8e6c791b333f17df Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 14 May 2015 00:44:55 +0200 Subject: [PATCH 2/2] Add action roads --- .../plus/routing/RouteCalculationResult.java | 11 ++++---- .../osmand/plus/routing/RouteProvider.java | 3 ++ .../src/net/osmand/plus/views/RouteLayer.java | 28 +++++++++++-------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index 6631d2cd13..9371f8b120 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -243,12 +243,12 @@ public class RouteCalculationResult { if (routeInd < list.size()) { int lind = routeInd; if(turn.isRoundAbout()) { - int roundAboutEnd = prevLocationSize - 1; + int roundAboutEnd = prevLocationSize ; // take next name for roundabout (not roundabout name) - while(lind < list.size() -1 && list.get(lind).getObject().roundabout()) { - roundAboutEnd += Math.abs(list.get(lind).getEndPointIndex()-list.get(lind).getStartPointIndex()); - lind++; - } + while (lind < list.size() - 1 && list.get(lind).getObject().roundabout()) { + roundAboutEnd++; + lind++; + } // Consider roundabout end. info.routeEndPointOffset = roundAboutEnd; } @@ -811,6 +811,7 @@ public class RouteCalculationResult { !Algorithms.objectEquals(p.getStreetName(), i.getStreetName()))) { p = new RouteDirectionInfo(i.getAverageSpeed(), i.getTurnType()); p.routePointOffset = i.routePointOffset; + p.routeEndPointOffset = i.routeEndPointOffset; p.setDestinationName(i.getDestinationName()); p.setRef(i.getRef()); p.setStreetName(i.getStreetName()); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 7ebda89056..c64e6ba048 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -428,6 +428,9 @@ public class RouteProvider { if (info.routePointOffset >= startI[0] && info.routePointOffset < endI[0]) { RouteDirectionInfo ch = new RouteDirectionInfo(info.getAverageSpeed(), info.getTurnType()); ch.routePointOffset = info.routePointOffset - startI[0]; + if(info.routeEndPointOffset != 0) { + ch.routeEndPointOffset = info.routeEndPointOffset - startI[0]; + } ch.setDescriptionRoute(info.getDescriptionRoutePart()); directions.add(ch); } diff --git a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java index 8c11314a2a..b89b74b281 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java @@ -125,10 +125,9 @@ public class RouteLayer extends OsmandMapLayer { paint.setStrokeWidth(12 * view.getDensity()); } osmandRenderer.updatePaint(req, actionPaint, 2, false, rc); - actionPaint.setColor(Color.BLUE); - paintIconAction.setColorFilter(new PorterDuffColorFilter(actionPaint.getColor(), Mode.MULTIPLY)); // TODO remove - // actionPaint.setColor(Color.WHITE); + // actionPaint.setColor(Color.BLUE); + paintIconAction.setColorFilter(new PorterDuffColorFilter(actionPaint.getColor(), Mode.MULTIPLY)); isPaint2 = osmandRenderer.updatePaint(req, paint2, 1, false, rc); isPaint_1 = osmandRenderer.updatePaint(req, paint_1, -1, false, rc); @@ -366,19 +365,24 @@ public class RouteLayer extends OsmandMapLayer { double actionDist = 0; Location previousAction = null; actionPoints.clear(); - int prevPoint = -1; + int prevPoint = -2; for (int i = 0; i < routeNodes.size(); i++) { Location ls = routeNodes.get(i); - if(nf != null && nf.routePointOffset < i + cd) { - nf = null; - } - while (nf == null && it.hasNext()) { - nf = it.next(); - if (nf.routePointOffset < i + cd) { + if(nf != null) { + int pnt = nf.routeEndPointOffset == 0 ? nf.routePointOffset : nf.routeEndPointOffset; + if(pnt < i + cd ) { nf = null; } } - boolean action = nf != null && nf.routePointOffset == i + cd; + while (nf == null && it.hasNext()) { + nf = it.next(); + int pnt = nf.routeEndPointOffset == 0 ? nf.routePointOffset : nf.routeEndPointOffset; + if (pnt < i + cd) { + nf = null; + } + } + boolean action = nf != null && (nf.routePointOffset == i + cd || + (nf.routePointOffset <= i + cd && i + cd <= nf.routeEndPointOffset)); if(!action && previousAction == null) { continue; } @@ -420,7 +424,7 @@ public class RouteLayer extends OsmandMapLayer { if(prevPoint == k) { actionPoints.remove(ind - 1); actionPoints.remove(ind - 1); - prevPoint = -1; + prevPoint = -2; } actionPoints.add(ind, l); lp = l;