From bda0b850fde0b72a8a5aad7700c7c7892ee06928 Mon Sep 17 00:00:00 2001 From: Alexey Gavrilov Date: Sun, 12 Apr 2020 15:21:12 +0300 Subject: [PATCH] Fix #6838 Announce the change of street names One road may be result of several streets changing one into another. In that case OsmAnd didn't indicate that street name would change, because thare was no turn left/right in the route. Commit adds the new feature. When two segments of stright part route have different street names, a new 'stright' direction with the new name will be inserted into the list of directions. This is not applied to roads that have international/national refs, like 'E 101' --- .../plus/routing/RouteCalculationResult.java | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index d103ff5776..14548c321a 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -362,8 +362,40 @@ public class RouteCalculationResult { i--; } } + + String streetName = null; TurnType turn = s.getTurnType(); + // Try to detect the case when a street changes is name to another (typically after road crossing) + // Then add RouteDirectionInfo of TurnType.straight() + if (turn == null && routeInd + 1 < list.size()) { + String curStreetName = s.getObject().getName(ctx.getSettings().MAP_PREFERRED_LOCALE.get(), + ctx.getSettings().MAP_TRANSLITERATE_NAMES.get()); + String curIntRef = s.getObject().getValue("int_ref"); + String curRoadRef2 = s.getObject().getValue("road_ref_2"); + // Ignore the segments when has no street name or road is a highway (has ref like 'E 101') + if (!Algorithms.isEmpty(curStreetName) && Algorithms.isEmpty(curIntRef) && Algorithms.isEmpty(curRoadRef2)) { + int routeIndNext = routeInd + 1; + do { + RouteSegmentResult nextSegment = list.get(routeIndNext); + if (nextSegment.getTurnType() != null) + break; // in case instant turn is encountered then stop detection + String nextStreetName = nextSegment.getObject().getName(ctx.getSettings().MAP_PREFERRED_LOCALE.get(), + ctx.getSettings().MAP_TRANSLITERATE_NAMES.get()); + if (!Algorithms.isEmpty(nextStreetName)) { + if (!Algorithms.stringsEqual(curStreetName, nextStreetName)) { + // If road changes street name, save valid data for RouteDirectionInfo + turn = TurnType.straight(); + streetName = nextStreetName; + } + // If next segment has the same street name then stop detection + break; + } + routeIndNext++; + } while (routeIndNext < routeInd + 5 && routeIndNext < list.size()); + } + } + if(turn != null) { RouteDirectionInfo info = new RouteDirectionInfo(s.getSegmentSpeed(), turn); if (routeInd < list.size()) { @@ -383,8 +415,10 @@ public class RouteCalculationResult { String ref = next.getObject().getRef(ctx.getSettings().MAP_PREFERRED_LOCALE.get(), ctx.getSettings().MAP_TRANSLITERATE_NAMES.get(), next.isForwardDirection()); info.setRef(ref); - String streetName = next.getObject().getName(ctx.getSettings().MAP_PREFERRED_LOCALE.get(), - ctx.getSettings().MAP_TRANSLITERATE_NAMES.get()); + if(streetName==null) { + streetName = next.getObject().getName(ctx.getSettings().MAP_PREFERRED_LOCALE.get(), + ctx.getSettings().MAP_TRANSLITERATE_NAMES.get()); + } if (Algorithms.isEmpty(streetName)) { // try to get street names from following segments float distanceFromTurn = next.getDistance();