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

[WIP] Add roundaboutExits param to MapboxDirections #562

Merged
merged 9 commits into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from 7 commits
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ directions-fixtures:
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)" \
-o mapbox/libjava-services/src/test/fixtures/directions_v5_traffic.json

# Directions: allow roundabout exits
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)" \
-o mapbox/libjava-services/src/test/fixtures/directions_v5_roundabout_exits.json

mapmatching-fixtures:
curl "https://api.mapbox.com/matching/v5/mapbox/driving/$(MAP_MATCHING_COORDINATES)?geometries=polyline&language=sv&steps=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
-o mapbox/libjava-services/src/test/fixtures/mapmatching_v5_polyline.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class Constants {
@Experimental public static final String STEP_MANEUVER_TYPE_ROUNDABOUT = "roundabout";
@Experimental public static final String STEP_MANEUVER_TYPE_ROTARY = "rotary";
@Experimental public static final String STEP_MANEUVER_TYPE_ROUNDABOUT_TURN = "roundabout turn";
@Experimental public static final String STEP_MANEUVER_TYPE_EXIT_ROUNDABOUT = "exit roundabout";
@Experimental public static final String STEP_MANEUVER_TYPE_EXIT_ROTARY = "exit rotary";
@Experimental public static final String STEP_MANEUVER_TYPE_NOTIFICATION = "notification";
}

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public interface DirectionsService {
* route geometry. Each entry in an annotations field corresponds to a coordinate along the
* route geometry.
* @param language Language of returned turn-by-turn text instructions.
* @param roundaboutExits Define if exit on roundabout is allowed.
* @return The {@link DirectionsResponse} in a Call wrapper.
* @since 1.0.0
*/
Expand All @@ -55,6 +56,7 @@ Call<DirectionsResponse> getCall(
@Query("bearings") String bearings,
@Query("continue_straight") Boolean continueStraight,
@Query("annotations") String annotations,
@Query("language") String language
@Query("language") String language,
@Query("roundabout_exits") Boolean roundaboutExits
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ private Call<DirectionsResponse> getCall() {
builder.getBearings(),
builder.isContinueStraight(),
builder.getAnnotation(),
builder.getLanguage());
builder.getLanguage(),
builder.allowsRoundaboutExits());

// Done
return call;
Expand Down Expand Up @@ -149,6 +150,7 @@ public static class Builder<T extends Builder> extends MapboxBuilder {
private Position destination = null;
private String[] annotation = null;
private String language = null;
private Boolean roundaboutExits = null;

/**
* Constructor
Expand Down Expand Up @@ -373,6 +375,18 @@ public T setLanguage(String language) {
return (T) this;
}

/**
* Optionally, set this to true if you want to enable instructions while exiting roundabouts
* and rotaries.
*
* @param roundaboutExits true if exit on a roundabout is allowed.
* @return Builder
* @since 2.2.4
*/
public T setRoundaboutExits(Boolean roundaboutExits) {
this.roundaboutExits = roundaboutExits;
return (T) this;
}
/*
* Getters, they return the value in a format ready for the API to consume
*/
Expand Down Expand Up @@ -590,6 +604,15 @@ public T setBaseUrl(String baseUrl) {
return (T) this;
}

/**
* @return return true if you enabled additional instructions while exiting rotaries and
* roundabouts. See {@link #setRoundaboutExits(Boolean)}.
* @since 2.2.4
*/
public Boolean allowsRoundaboutExits() {
return roundaboutExits;
}

/**
* Build method
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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"}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class MapboxDirectionsTest {
private static final String DIRECTIONS_TRAFFIC_FIXTURE = "src/test/fixtures/directions_v5_traffic.json";
private static final String DIRECTIONS_ROTARY_FIXTURE = "src/test/fixtures/directions_v5_fixtures_rotary.json";
private static final String DIRECTIONS_V5_ANNOTATIONS_FIXTURE = "src/test/fixtures/directions_annotations_v5.json";
private static final String DIRECTIONS_V5_ROUNDABOUTS_FIXTURE = "src/test/fixtures/directions_v5_roundabout_exits.json";

private static final double DELTA = 1E-10;

Expand Down Expand Up @@ -76,6 +77,9 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio
if (request.getPath().contains("annotations")) {
resource = DIRECTIONS_V5_ANNOTATIONS_FIXTURE;
}
if (request.getPath().contains("roundabout_exits")) {
resource = DIRECTIONS_V5_ROUNDABOUTS_FIXTURE;
}

try {
String body = new String(Files.readAllBytes(Paths.get(resource)), Charset.forName("utf-8"));
Expand Down Expand Up @@ -662,4 +666,19 @@ public void setLanguage_doesReturnCorrectTurnInstructionLanguage() throws IOExce
assertTrue(response.body().getRoutes().get(0).getLegs().get(0)
.getSteps().get(0).getManeuver().getInstruction().contains("Kör åt öster på Eddy Street"));
}

@Test
public void testRoundaboutExitsResponse() throws IOException {
MapboxDirections client = new MapboxDirections.Builder()
.setAccessToken("pk.XXX")
.setCoordinates(positions)
.setProfile(DirectionsCriteria.PROFILE_DRIVING)
.setBaseUrl(mockUrl.toString())
.setRoundaboutExits(true)
.build();

Response<DirectionsResponse> response = client.executeCall();
assertEquals(response.body().getRoutes().get(0).getLegs().get(0)
.getSteps().get(2).getManeuver().getType(), "exit roundabout");
}
}