Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removing the code that is merging turn instructions - Issue #177 #179

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public RouteResult createRouteResult(List<GHResponse> routes, RoutingRequest req
// nInstructions -= 1;

Instruction instr, prevInstr = null;
InstructionType instrType, prevInstrType = InstructionType.UNKNOWN;
InstructionType instrType = InstructionType.UNKNOWN;
RouteSegment seg = new RouteSegment(path, units);

if (includeDetourFactor)
Expand All @@ -145,7 +145,6 @@ public RouteResult createRouteResult(List<GHResponse> routes, RoutingRequest req
seg.setDetourFactor((dist == 0) ? 0 : FormatUtility.roundToDecimals(path.getDistance()/dist, 2));
}

RouteStep prevStep = null;
String instrText = "";
double stepDistance, stepDuration;

Expand Down Expand Up @@ -217,49 +216,19 @@ else if (instrType == InstructionType.FINISH)
}


// merge route steps with similar names
// example: http://localhost:8082/openrouteservice-4.0.0/routes?profile=driving-car&coordinates=8.690614,49.38365|8.7007,49.411699|8.7107,49.4516&prettify_instructions=true
if (prevStep != null && instrType == prevInstrType && canMergeInstructions(instr.getName(), prevInstr.getName()))
{
String mergedRoadName = mergeInstructions(instr.getName(), prevInstr.getName());

int[] wayPoints = prevStep.getWayPoints();
wayPoints[1] = wayPoints[1] + instr.getPoints().size();

stepDuration = FormatUtility.roundToDecimals(instr.getTime()/1000.0, 1);
_nameAppendix = null;

prevStep.setDistance(FormatUtility.roundToDecimals(DistanceUnitUtil.convert(prevStep.getDistance() + stepDistance, DistanceUnit.Meters, units), unitDecimals));
prevStep.setDuration(FormatUtility.roundToDecimals(prevStep.getDuration() + stepDuration, 1));
prevStep.setName(mergedRoadName);

if (_nameAppendix != null)
mergedRoadName += " ("+ _nameAppendix + ")";
if (formatInstructions)
mergedRoadName = "<b>" + mergedRoadName + "</b>";
step.setDistance(stepDistance);
step.setDuration(stepDuration);
step.setInstruction(instrText);
step.setName(instr.getName());
step.setType(instrType.ordinal());
step.setWayPoints(new int[] { startWayPointIndex, getWayPointEndIndex(startWayPointIndex, instrType, instr)});

prevStep.setInstruction(instrTranslator.getContinue(instrType, mergedRoadName));
if (request.getIncludeManeuvers())
step.setManeuver(calcManeuver(instrType, prevSegPoints, segPoints, nextSegPoints));

//if (request.getIncludeManeuvers())
// prevStep.setManeuver(computeManeuver(prevSegPoints, segPoints));
}
else
{
_nameAppendix = null;

step.setDistance(stepDistance);
step.setDuration(stepDuration);
step.setInstruction(instrText);
step.setName(instr.getName());
step.setType(instrType.ordinal());
step.setWayPoints(new int[] { startWayPointIndex, getWayPointEndIndex(startWayPointIndex, instrType, instr)});

if (request.getIncludeManeuvers())
step.setManeuver(calcManeuver(instrType, prevSegPoints, segPoints, nextSegPoints));

seg.addStep(step);

prevStep = step;
}
seg.addStep(step);

// step.setMessage(message);
// add message and message type
Expand All @@ -271,7 +240,6 @@ else if (instrType == InstructionType.FINISH)
distanceActual += stepDistance;

prevInstr = instr;
prevInstrType = instrType;
prevSegPoints = segPoints;
}

Expand Down Expand Up @@ -449,67 +417,6 @@ private RouteStepManeuver calcManeuver(InstructionType instrType, PointList prev
return maneuver;
}

private boolean canMergeInstructions(String name, String prevName)
{
if (prevName == null)
return false;

if (name.length() > prevName.length())
{
int pos = name.indexOf(prevName);
if (pos >= 0 && !Helper.isEmpty(prevName))
return true;
}
else
{
int pos = prevName.indexOf(name);
if (pos >= 0 && !Helper.isEmpty(name))
return true;
}

return false;
}

private String mergeInstructionsOrdered(String name, String prevName)
{
int pos = name.indexOf(prevName);
if (pos >= 0)
{
pos = pos + prevName.length() + 1;
if (pos < name.length())
{
String appendix = name.substring(pos, name.length());

if (appendix.length() > 1 && appendix.startsWith(","))
appendix = appendix.substring(1);

appendix = appendix.trim();

if (isValidAppendix(appendix))
{
if (_nameAppendix != null)
_nameAppendix += ", ";
else
_nameAppendix = "";

_nameAppendix += appendix;
}

return prevName;
}
}

return name;
}

private String mergeInstructions(String name, String prevName)
{
if (name.length() > prevName.length())
return mergeInstructionsOrdered(name, prevName);
else
return mergeInstructionsOrdered(prevName, name);
}

private boolean isValidAppendix(String name)
{
if (name == null)
Expand Down