diff --git a/web-bundle/src/main/java/com/graphhopper/resources/BufferResource.java b/web-bundle/src/main/java/com/graphhopper/resources/BufferResource.java index 61daba17f47..262cceeb716 100644 --- a/web-bundle/src/main/java/com/graphhopper/resources/BufferResource.java +++ b/web-bundle/src/main/java/com/graphhopper/resources/BufferResource.java @@ -588,14 +588,9 @@ else if (roadName == null && !tempState.get(this.roundaboutAccessEnc)) { boolean matchesPreviousEdgeName = (currentIsBlank && previousIsBlank) || (currentEdgeRoadName != null && currentEdgeRoadName.equals(previousRoadName)); - if (matchesPreviousEdgeName && !currentIsBlank) { - currentEdge = tempEdge; - usedEdges.add(tempEdge); - break; - } - - // Collect both named and unnamed edges for angle-based selection when continuing from an unnamed road. - if (previousIsBlank) { + // Collect all qualifying unnamed edges that either match the previous edge name or are the first unnamed edge after a named edge. + // After the loop we will select the straightest edge from this list to continue the path. + if ((matchesPreviousEdgeName && !currentIsBlank) || previousIsBlank) { candidateEdgesFromUnnamedRoad.add(tempEdge); } } diff --git a/web/src/test/java/com/graphhopper/application/resources/BufferResourceTest.java b/web/src/test/java/com/graphhopper/application/resources/BufferResourceTest.java index 68d6c715687..81b910be86d 100644 --- a/web/src/test/java/com/graphhopper/application/resources/BufferResourceTest.java +++ b/web/src/test/java/com/graphhopper/application/resources/BufferResourceTest.java @@ -397,6 +397,24 @@ public void testBidirectionalUpstreamPathWhenRequireRoadMatchIsFalse() { assertNotEquals(lineString0.getCoordinates()[0], lineString1.getCoordinates()[0]); } + @Test + public void testUnidirectionalUpstreamPathWithUnnamedEdgeStart() { + JsonFeatureCollection featureCollection; + try (Response response = clientTarget(app, "/buffer?queryMultiplier=.000075&" + + "point=42.531666,1.520129&roadName=CG-3&thresholdDistance=200&buildUpstream=true") + .request().buildGet().invoke()) { + assertEquals(200, response.getStatus()); + + featureCollection = response.readEntity(JsonFeatureCollection.class); + } + + // Expect a single feature collection for unidirectional + assertEquals(1, featureCollection.getFeatures().size()); + // Expect a line string with coordinates to have been built + Geometry lineString0 = featureCollection.getFeatures().get(0).getGeometry(); + assertNotEquals(0, lineString0.getCoordinates().length); + } + @Test public void testBidirectionalUpstreamPathWhenRequireRoadMatchIsFalse_InvalidName() { JsonFeatureCollection featureCollection;