Skip to content

Commit 31a2e90

Browse files
osanchikzugaldia
authored andcommitted
[WIP] Add roundaboutExits param to MapboxDirections (#562)
* Add roundaboutExits param to MapboxDirections Added roundaboutExits param to MapboxDirections. Still need to add fixtures, test and check param description * address PR review comments * add test fixture * add test * fix fixture generation * remove unused import * add constants to reflect two new types * fix line length
1 parent 61f592b commit 31a2e90

6 files changed

Lines changed: 54 additions & 2 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ directions-fixtures:
112112
curl "https://api.mapbox.com/directions/v5/mapbox/driving-traffic/-122.416667,37.783333;-121.900000,37.333333?geometries=polyline&steps=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
113113
-o mapbox/libjava-services/src/test/fixtures/directions_v5_traffic.json
114114

115+
# Directions: allow roundabout exits
116+
curl "https://api.mapbox.com/directions/v5/mapbox/driving-traffic/-77.04014240930304,38.91313201360546;-77.04573453985853,38.90725177816208.json?steps=true&overview=full&geometries=polyline&roundabout_exits=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
117+
-o mapbox/libjava-services/src/test/fixtures/directions_v5_roundabout_exits.json
118+
115119
mapmatching-fixtures:
116120
curl "https://api.mapbox.com/matching/v5/mapbox/driving/$(MAP_MATCHING_COORDINATES)?geometries=polyline&language=sv&steps=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
117121
-o mapbox/libjava-services/src/test/fixtures/mapmatching_v5_polyline.json

mapbox/libandroid-services/src/main/java/com/mapbox/services/android/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class Constants {
3030
@Experimental public static final String STEP_MANEUVER_TYPE_ROUNDABOUT = "roundabout";
3131
@Experimental public static final String STEP_MANEUVER_TYPE_ROTARY = "rotary";
3232
@Experimental public static final String STEP_MANEUVER_TYPE_ROUNDABOUT_TURN = "roundabout turn";
33+
@Experimental public static final String STEP_MANEUVER_TYPE_EXIT_ROUNDABOUT = "exit roundabout";
34+
@Experimental public static final String STEP_MANEUVER_TYPE_EXIT_ROTARY = "exit rotary";
3335
@Experimental public static final String STEP_MANEUVER_TYPE_NOTIFICATION = "notification";
3436
}
3537

mapbox/libjava-services/src/main/java/com/mapbox/services/api/directions/v5/DirectionsService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public interface DirectionsService {
3636
* route geometry. Each entry in an annotations field corresponds to a coordinate along the
3737
* route geometry.
3838
* @param language Language of returned turn-by-turn text instructions.
39+
* @param roundaboutExits Define if exit on roundabout is allowed.
3940
* @return The {@link DirectionsResponse} in a Call wrapper.
4041
* @since 1.0.0
4142
*/
@@ -55,6 +56,7 @@ Call<DirectionsResponse> getCall(
5556
@Query("bearings") String bearings,
5657
@Query("continue_straight") Boolean continueStraight,
5758
@Query("annotations") String annotations,
58-
@Query("language") String language
59+
@Query("language") String language,
60+
@Query("roundabout_exits") Boolean roundaboutExits
5961
);
6062
}

mapbox/libjava-services/src/main/java/com/mapbox/services/api/directions/v5/MapboxDirections.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ private Call<DirectionsResponse> getCall() {
7676
builder.getBearings(),
7777
builder.isContinueStraight(),
7878
builder.getAnnotation(),
79-
builder.getLanguage());
79+
builder.getLanguage(),
80+
builder.allowsRoundaboutExits());
8081

8182
// Done
8283
return call;
@@ -149,6 +150,7 @@ public static class Builder<T extends Builder> extends MapboxBuilder {
149150
private Position destination = null;
150151
private String[] annotation = null;
151152
private String language = null;
153+
private Boolean roundaboutExits = null;
152154

153155
/**
154156
* Constructor
@@ -373,6 +375,18 @@ public T setLanguage(String language) {
373375
return (T) this;
374376
}
375377

378+
/**
379+
* Optionally, set this to true if you want to enable instructions while exiting roundabouts
380+
* and rotaries.
381+
*
382+
* @param roundaboutExits true if exit on a roundabout is allowed.
383+
* @return Builder
384+
* @since 2.2.4
385+
*/
386+
public T setRoundaboutExits(Boolean roundaboutExits) {
387+
this.roundaboutExits = roundaboutExits;
388+
return (T) this;
389+
}
376390
/*
377391
* Getters, they return the value in a format ready for the API to consume
378392
*/
@@ -590,6 +604,15 @@ public T setBaseUrl(String baseUrl) {
590604
return (T) this;
591605
}
592606

607+
/**
608+
* @return return true if you enabled additional instructions while exiting rotaries and
609+
* roundabouts. See {@link #setRoundaboutExits(Boolean)}.
610+
* @since 2.2.4
611+
*/
612+
public Boolean allowsRoundaboutExits() {
613+
return roundaboutExits;
614+
}
615+
593616
/**
594617
* Build method
595618
*
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"waypoints":[{"name":"New Hampshire Avenue Northwest","location":[-77.040159,38.913142]},{"name":"N Street Northwest","location":[-77.045735,38.907244]}],"routes":[{"legs":[{"steps":[{"intersections":[{"out":0,"entry":[true],"location":[-77.040159,38.913142],"bearings":[216]},{"out":2,"in":0,"entry":[false,false,true,true],"location":[-77.04066,38.912608],"bearings":[30,90,210,270]},{"out":2,"in":0,"entry":[false,true,true,false],"location":[-77.041354,38.91187],"bearings":[30,90,210,270]},{"out":3,"in":1,"entry":[true,false,true,true],"location":[-77.041666,38.911537],"bearings":[0,30,180,210]},{"out":2,"in":0,"entry":[false,true,true,false],"location":[-77.042051,38.911129],"bearings":[30,90,210,270]},{"out":2,"in":0,"entry":[false,false,true],"location":[-77.042809,38.910322],"bearings":[30,195,225]}],"geometry":"cfolF~{euMzAtAHHBBLLdCzBj@h@DDNNPNp@l@LLNLpChCFHFLBJ@LAN","duration":124.39999999999999,"distance":421.2,"name":"New Hampshire Avenue Northwest","weight":136.39999999999998,"mode":"driving","maneuver":{"bearing_after":216,"bearing_before":0,"type":"depart","location":[-77.040159,38.913142],"instruction":"Head southwest on New Hampshire Avenue Northwest"}},{"intersections":[{"out":2,"in":0,"entry":[false,false,true],"location":[-77.043141,38.910215],"bearings":[90,120,285]},{"out":1,"in":0,"entry":[false,true,true],"location":[-77.043232,38.910239],"bearings":[105,285,300]},{"out":1,"in":0,"entry":[false,true,true],"location":[-77.043398,38.91026],"bearings":[90,270,285]},{"out":2,"in":1,"entry":[false,false,true],"location":[-77.043676,38.910234],"bearings":[45,75,240]},{"out":2,"in":1,"entry":[false,false,true],"location":[-77.043975,38.9101],"bearings":[15,45,225]},{"out":2,"in":0,"entry":[false,false,true,true],"location":[-77.044115,38.90997],"bearings":[30,75,210,300]},{"out":2,"in":0,"entry":[false,true,true,true,false],"location":[-77.04421,38.909799],"bearings":[15,150,195,210,315]},{"out":0,"in":2,"entry":[true,false,false],"location":[-77.044212,38.909496],"bearings":[165,315,345]}],"geometry":"{snlFrnfuMAHAFAJAH?J?F?F?F@F?F@F@F@F@HDJBHDHDHBDDDBDDBDDB@DBB@DBB@D@B@F@F@D?F@FAF?FADAFAFCFCDCFEDEDE","duration":104.69999999999999,"distance":182.3,"name":"New Hampshire Avenue Northwest","weight":120.8,"mode":"driving","maneuver":{"exit":5,"bearing_after":289,"location":[-77.043141,38.910215],"type":"roundabout","bearing_before":271,"modifier":"straight","instruction":"Enter the roundabout and take the 5th exit onto New Hampshire Avenue Northwest"}},{"intersections":[{"out":1,"in":2,"entry":[true,true,false],"location":[-77.044051,38.909248],"bearings":[135,165,315]},{"out":2,"in":0,"entry":[false,false,true],"location":[-77.044059,38.908982],"bearings":[15,60,210]},{"out":1,"in":0,"entry":[false,true,true],"location":[-77.044444,38.90857],"bearings":[30,210,270]},{"out":3,"in":1,"entry":[true,false,false,true],"location":[-77.0449,38.908073],"bearings":[0,30,180,210]},{"out":2,"in":0,"entry":[false,true,true],"location":[-77.045062,38.907902],"bearings":[30,90,210]}],"geometry":"ymnlFhtfuMNEH?H@D@JBpAjAbBzA`@^bCzB","duration":113.5,"distance":269.4,"name":"New Hampshire Avenue Northwest","weight":130,"mode":"driving","maneuver":{"exit":5,"bearing_after":163,"location":[-77.044051,38.909248],"type":"exit roundabout","bearing_before":142,"modifier":"slight right","instruction":"Make a slight right onto New Hampshire Avenue Northwest"}},{"intersections":[{"out":3,"in":0,"entry":[false,false,true,true],"location":[-77.045681,38.907244],"bearings":[30,90,210,270]}],"geometry":"ganlFn~fuM?J","duration":1.2,"distance":4.7,"name":"N Street Northwest","weight":1.2,"mode":"driving","maneuver":{"bearing_after":268,"location":[-77.045681,38.907244],"type":"turn","bearing_before":215,"modifier":"right","instruction":"Turn right onto N Street Northwest"}},{"intersections":[{"in":0,"entry":[true],"location":[-77.045735,38.907244],"bearings":[90]}],"geometry":"ganlFz~fuM","duration":0,"distance":0,"name":"N Street Northwest","weight":0,"mode":"driving","maneuver":{"bearing_after":0,"bearing_before":270,"type":"arrive","location":[-77.045735,38.907244],"instruction":"You have arrived at your destination"}}],"weight":388.4,"distance":877.5,"summary":"New Hampshire Avenue Northwest, Dupont Circle Northwest","duration":343.8}],"weight_name":"routability","geometry":"cfolF~{euMzAtAHHBBLLdCzBj@h@DDNNPNp@l@LLNLpChCFHFLBJ@LANAHAFAJAH?J?F?F?F@F?F@F@F@F@HDJBHDHDHBDDDBDDBDDB@DBB@DBB@D@B@F@F@D?F@FAF?FADAFAFCFCDCFEDEDENEH?H@D@JBpAjAbBzA`@^bCzB?J","weight":388.4,"distance":877.5,"duration":343.8}],"code":"Ok","uuid":"cj7kzo9zg5tjayani9nxmit7r"}

mapbox/libjava-services/src/test/java/com/mapbox/services/api/directions/v5/MapboxDirectionsTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class MapboxDirectionsTest {
4545
private static final String DIRECTIONS_TRAFFIC_FIXTURE = "src/test/fixtures/directions_v5_traffic.json";
4646
private static final String DIRECTIONS_ROTARY_FIXTURE = "src/test/fixtures/directions_v5_fixtures_rotary.json";
4747
private static final String DIRECTIONS_V5_ANNOTATIONS_FIXTURE = "src/test/fixtures/directions_annotations_v5.json";
48+
private static final String DIRECTIONS_V5_ROUNDABOUTS_FIXTURE =
49+
"src/test/fixtures/directions_v5_roundabout_exits.json";
4850

4951
private static final double DELTA = 1E-10;
5052

@@ -76,6 +78,9 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio
7678
if (request.getPath().contains("annotations")) {
7779
resource = DIRECTIONS_V5_ANNOTATIONS_FIXTURE;
7880
}
81+
if (request.getPath().contains("roundabout_exits")) {
82+
resource = DIRECTIONS_V5_ROUNDABOUTS_FIXTURE;
83+
}
7984

8085
try {
8186
String body = new String(Files.readAllBytes(Paths.get(resource)), Charset.forName("utf-8"));
@@ -662,4 +667,19 @@ public void setLanguage_doesReturnCorrectTurnInstructionLanguage() throws IOExce
662667
assertTrue(response.body().getRoutes().get(0).getLegs().get(0)
663668
.getSteps().get(0).getManeuver().getInstruction().contains("Kör åt öster på Eddy Street"));
664669
}
670+
671+
@Test
672+
public void testRoundaboutExitsResponse() throws IOException {
673+
MapboxDirections client = new MapboxDirections.Builder()
674+
.setAccessToken("pk.XXX")
675+
.setCoordinates(positions)
676+
.setProfile(DirectionsCriteria.PROFILE_DRIVING)
677+
.setBaseUrl(mockUrl.toString())
678+
.setRoundaboutExits(true)
679+
.build();
680+
681+
Response<DirectionsResponse> response = client.executeCall();
682+
assertEquals(response.body().getRoutes().get(0).getLegs().get(0)
683+
.getSteps().get(2).getManeuver().getType(), "exit roundabout");
684+
}
665685
}

0 commit comments

Comments
 (0)