Fix turn lanes

This commit is contained in:
Victor Shcherb 2016-03-28 15:10:47 +02:00
parent d8a2b60436
commit 0f86f53b5e
3 changed files with 54 additions and 41 deletions

View file

@ -252,11 +252,11 @@ public class TurnType {
}
public static boolean isLeftTurn(int type) {
return type == TL || type == TSHL || type == TSLL || type == TRU;
return type == TL || type == TSHL || type == TSLL || type == TU || type == KL;
}
public static boolean isRightTurn(int type) {
return type == TR || type == TSHR || type == TSLR || type == TU;
return type == TR || type == TSHR || type == TSLR || type == TRU || type == KR;
}
public static boolean isSlightTurn(int type) {

View file

@ -405,58 +405,64 @@ public class TurnPathHelper {
}
public static Bitmap getBitmapFromTurnType(Resources res, Map<TurnResource, Bitmap> cache, int firstTurn, int secondTurn, int thirdTurn, int turnIndex, Bitmap defaultType, float coef, boolean leftSide) {
public static Bitmap getBitmapFromTurnType(Resources res, Map<TurnResource, Bitmap> cache, int firstTurn,
int secondTurn, int thirdTurn, int turnIndex, float coef, boolean leftSide) {
int firstTurnType = TurnType.valueOf(firstTurn, leftSide).getValue();
int secondTurnType = TurnType.valueOf(secondTurn, leftSide).getValue();
int thirdTurnType = TurnType.valueOf(thirdTurn, leftSide).getValue();
TurnResource turnResource = new TurnResource(R.drawable.map_turn_forward_small, false);
TurnResource turnResource = null;
if(turnIndex == FIRST_TURN){
if(firstTurn == 0) return defaultType;
if(secondTurnType == 0) {
if (turnIndex == FIRST_TURN) {
if (secondTurnType == 0) {
turnResource = getTallArrow(firstTurnType);
}else if(secondTurnType != TurnType.C){
if(firstTurnType == TurnType.TU || firstTurnType == TurnType.TRU){
} else if (secondTurnType != TurnType.C) {
if (firstTurnType == TurnType.TU || firstTurnType == TurnType.TRU) {
turnResource = getShortArrow(firstTurnType);
}else {
} else {
turnResource = getTallArrow(firstTurnType);
}
}else{
} else {
// get the small one
turnResource = getShortArrow(firstTurnType);
}
}else if(turnIndex == SECOND_TURN){
if(firstTurnType == TurnType.C || firstTurnType == TurnType.TR){
} else if (turnIndex == SECOND_TURN) {
if (TurnType.isLeftTurn(firstTurnType) && TurnType.isLeftTurn(secondTurnType)) {
turnResource = null;
} else if (TurnType.isRightTurn(firstTurnType) && TurnType.isRightTurn(secondTurnType)) {
turnResource = null;
} else if (firstTurnType == TurnType.C || thirdTurnType == TurnType.C) {
// get the small one
turnResource = getShortArrow(secondTurnType);
}else{
} else {
turnResource = getTallArrow(secondTurnType);
}
}else if(turnIndex == THIRD_TURN){
if(secondTurnType == TurnType.C){
// get the small one
turnResource = getShortArrow(thirdTurnType);
}else{
// ? slightly turn?
} else if (turnIndex == THIRD_TURN) {
if ((TurnType.isLeftTurn(firstTurnType) || TurnType.isLeftTurn(secondTurnType)) && TurnType.isLeftTurn(thirdTurnType)) {
turnResource = null;
} else if ((TurnType.isRightTurn(firstTurnType) || TurnType.isRightTurn(secondTurnType)) && TurnType.isRightTurn(thirdTurnType)) {
turnResource = null;
} else {
turnResource = getShortArrow(secondTurnType);
}
}
if (turnResource == null) {
return null;
}
Bitmap b = cache.get(turnResource);
if(b == null) {
b = turnResource.flip ? getFlippedBitmap(res, turnResource.resourceId) : BitmapFactory.decodeResource(res, turnResource.resourceId);
if (b == null) {
b = turnResource.flip ? getFlippedBitmap(res, turnResource.resourceId) : BitmapFactory.decodeResource(res,
turnResource.resourceId);
cache.put(turnResource, b);
}
//Maybe redundant scaling
// Maybe redundant scaling
/*
float bRatio = (float)b.getWidth() / (float)b.getHeight();
float s = 72f * coef;
int wq = Math.round(s / bRatio);
int hq = Math.round(s);
b = Bitmap.createScaledBitmap(b, wq, hq, false);
*/
* float bRatio = (float)b.getWidth() / (float)b.getHeight(); float s = 72f * coef; int wq = Math.round(s /
* bRatio); int hq = Math.round(s); b = Bitmap.createScaledBitmap(b, wq, hq, false);
*/
return b;
}

View file

@ -692,32 +692,39 @@ public class RouteInfoWidgetsFactory {
canvas.save();
// canvas.translate((int) (16 * scaleCoefficient), 0);
for (int i = 0; i < lanes.length; i++) {
int turnType;
int secondTurnType;
if ((lanes[i] & 1) == 1) {
paintRouteDirection.setColor(imminent ? ctx.getResources().getColor(R.color.nav_arrow_imminent) :
ctx.getResources().getColor(R.color.nav_arrow));
} else {
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow_distant));
}
turnType = TurnType.getPrimaryTurn(lanes[i]);
secondTurnType = TurnType.getSecondaryTurn(lanes[i]);
int turnType = TurnType.getPrimaryTurn(lanes[i]);
int secondTurnType = TurnType.getSecondaryTurn(lanes[i]);
int thirdTurnType = TurnType.getTertiaryTurn(lanes[i]);
float coef = scaleCoefficient / miniCoeff;
Bitmap b = TurnPathHelper.getBitmapFromTurnType(ctx.getResources(), bitmapCache, turnType, secondTurnType, 0, TurnPathHelper.FIRST_TURN, laneStraightBitmap, coef, leftSide);
if(secondTurnType > 0){
if(thirdTurnType > 0){
Bitmap bSecond = null;
bSecond = TurnPathHelper.getBitmapFromTurnType(ctx.getResources(), bitmapCache, turnType, secondTurnType, 0, TurnPathHelper.SECOND_TURN, laneStraightBitmap, coef, leftSide);
bSecond = TurnPathHelper.getBitmapFromTurnType(ctx.getResources(), bitmapCache, turnType, secondTurnType, thirdTurnType, TurnPathHelper.THIRD_TURN, coef, leftSide);
if (bSecond != null){
paintSecondTurn.setColorFilter(new PorterDuffColorFilter(paintSecondTurn.getColor(), PorterDuff.Mode.SRC_ATOP));
canvas.drawBitmap(bSecond, 0f, 0f, paintSecondTurn);
}
}
paintRouteDirection.setColorFilter(new PorterDuffColorFilter(paintRouteDirection.getColor(), PorterDuff.Mode.SRC_ATOP));
canvas.drawBitmap(b, 0f, 0f, paintRouteDirection);
canvas.translate(w, 0);
if(secondTurnType > 0){
Bitmap bSecond = null;
bSecond = TurnPathHelper.getBitmapFromTurnType(ctx.getResources(), bitmapCache, turnType, secondTurnType, thirdTurnType, TurnPathHelper.SECOND_TURN, coef, leftSide);
if (bSecond != null){
paintSecondTurn.setColorFilter(new PorterDuffColorFilter(paintSecondTurn.getColor(), PorterDuff.Mode.SRC_ATOP));
canvas.drawBitmap(bSecond, 0f, 0f, paintSecondTurn);
}
}
Bitmap b = TurnPathHelper.getBitmapFromTurnType(ctx.getResources(), bitmapCache, turnType, secondTurnType, thirdTurnType, TurnPathHelper.FIRST_TURN, coef, leftSide);
if(b != null) {
paintRouteDirection.setColorFilter(new PorterDuffColorFilter(paintRouteDirection.getColor(), PorterDuff.Mode.SRC_ATOP));
canvas.drawBitmap(b, 0f, 0f, paintRouteDirection);
canvas.translate(w, 0);
}
}
canvas.restore();
}