Skip to content

Commit da64ba5

Browse files
authored
added type and modifier to BannerText
* added type and modifier to BannerText
1 parent 47e4d96 commit da64ba5

5 files changed

Lines changed: 143 additions & 2 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ directions-fixtures:
104104
curl "https://api.mapbox.com/directions/v5/mapbox/driving/-95.69263,29.78771;-95.54899,29.78284.json?steps=true&overview=full&geometries=polyline6&roundabout_exits=true&voice_instructions=true&banner_instructions=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
105105
-o services-directions/src/test/resources/directions_v5_banner_with_shield.json
106106

107+
# Directions: route with bannerText
108+
curl "https://api.mapbox.com/directions/v5/mapbox/driving/-122.03067988107114,37.331808179989494;-122.03178702099605,37.3302383113533?voice_units=imperial&roundabout_exits=true&geometries=polyline&overview=full&steps=true&voice_instructions=true&banner_instructions=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
109+
-o services-directions/src/test/resources/directions_v5_banner_text.json
110+
107111
mapmatching-fixtures:
108112
curl "https://api.mapbox.com/matching/v5/mapbox/driving/$(MAP_MATCHING_COORDINATES)?geometries=polyline&language=sv&steps=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
109113
-o services-matching/src/test/resources/mapmatching_v5_polyline.json

services-directions/src/main/java/com/mapbox/api/directions/v5/models/BannerText.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,48 @@ public static Builder builder() {
4848
@Nullable
4949
public abstract List<BannerComponents> components();
5050

51+
/**
52+
* This indicates the type of maneuver. It can be any of these listed:
53+
* <br>
54+
* <ul>
55+
* <li>turn - a basic turn into direction of the modifier</li>
56+
* <li>new name - the road name changes (after a mandatory turn)</li>
57+
* <li>depart - indicates departure from a leg</li>
58+
* <li>arrive - indicates arrival to a destination of a leg</li>
59+
* <li>merge - merge onto a street</li>
60+
* <li>on ramp - take a ramp to enter a highway</li>
61+
* <li>off ramp - take a ramp to exit a highway</li>
62+
* <li>fork - take the left/right side of a fork</li>
63+
* <li>end of road - road ends in a T intersection</li>
64+
* <li>continue - continue on a street after a turn</li>
65+
* <li>roundabout - traverse roundabout, has additional property exit in RouteStep
66+
* containing the exit number. The modifier specifies the direction of entering the roundabout.
67+
* </li>
68+
* <li>rotary - a traffic circle. While very similar to a larger version of a roundabout, it does
69+
* not necessarily follow roundabout rules for right of way. It can offer
70+
* {@link LegStep#rotaryName()} and/or {@link LegStep#rotaryPronunciation()} parameters in
71+
* addition to the exit property.</li>
72+
* <li>roundabout turn - small roundabout that is treated as an intersection</li>
73+
* <li>notification - change of driving conditions, e.g. change of mode from driving to ferry</li>
74+
* </ul>
75+
*
76+
* @return String with type of maneuver
77+
* @since 3.0.0
78+
*/
79+
@Nullable
80+
public abstract String type();
81+
82+
/**
83+
* This indicates the mode of the maneuver. If type is of turn, the modifier indicates the
84+
* change in direction accomplished through the turn. If the type is of depart/arrive, the
85+
* modifier indicates the position of waypoint from the current direction of travel.
86+
*
87+
* @return String with modifier
88+
* @since 3.0.0
89+
*/
90+
@Nullable
91+
public abstract String modifier();
92+
5193
/**
5294
* Gson type adapter for parsing Gson to this class.
5395
*
@@ -87,6 +129,26 @@ public abstract static class Builder {
87129
@Nullable
88130
public abstract Builder components(List<BannerComponents> components);
89131

132+
/**
133+
* This indicates the type of maneuver. See {@link BannerText#type()} for a full list of
134+
* options.
135+
*
136+
* @param type String with type of maneuver
137+
* @return this builder for chaining options together
138+
* @since 3.0.0
139+
*/
140+
public abstract Builder type(@Nullable String type);
141+
142+
/**
143+
* This indicates the mode of the maneuver. If type is of turn, the modifier indicates the
144+
* change in direction accomplished through the turn. If the type is of depart/arrive, the
145+
* modifier indicates the position of waypoint from the current direction of travel.
146+
*
147+
* @param modifier String with modifier
148+
* @return this builder for chaining options together
149+
* @since 3.0.0
150+
*/
151+
public abstract Builder modifier(@Nullable String modifier);
90152
/**
91153
* Build a new {@link BannerText} object.
92154
*

services-directions/src/test/java/com/mapbox/api/directions/v5/models/BannerTextTest.java

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,58 @@
11
package com.mapbox.api.directions.v5.models;
22

3-
import static org.junit.Assert.assertEquals;
4-
import static org.junit.Assert.assertNotNull;
53

4+
import com.mapbox.api.directions.v5.DirectionsCriteria;
5+
import com.mapbox.api.directions.v5.MapboxDirections;
66
import com.mapbox.core.TestUtils;
7+
import com.mapbox.geojson.Point;
8+
9+
import java.io.IOException;
10+
11+
import okhttp3.HttpUrl;
12+
import okhttp3.mockwebserver.MockResponse;
13+
import okhttp3.mockwebserver.MockWebServer;
14+
import okhttp3.mockwebserver.RecordedRequest;
15+
import org.hamcrest.junit.ExpectedException;
16+
import org.junit.After;
17+
import org.junit.Before;
18+
import org.junit.Rule;
719
import org.junit.Test;
20+
import retrofit2.Response;
21+
22+
import static org.junit.Assert.assertNotNull;
23+
import static org.junit.Assert.assertEquals;
824

925
public class BannerTextTest extends TestUtils {
1026

27+
private static final String DIRECTIONS_V5_FIXTURE = "directions_v5_banner_text.json";
28+
29+
private MockWebServer server;
30+
private HttpUrl mockUrl;
31+
32+
@Before
33+
public void setUp() throws IOException {
34+
server = new MockWebServer();
35+
36+
server.setDispatcher(new okhttp3.mockwebserver.Dispatcher() {
37+
@Override
38+
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
39+
try {
40+
String body = loadJsonFixture(DIRECTIONS_V5_FIXTURE);
41+
return new MockResponse().setBody(body);
42+
} catch (IOException ioException) {
43+
throw new RuntimeException(ioException);
44+
}
45+
}
46+
});
47+
server.start();
48+
mockUrl = server.url("");
49+
}
50+
51+
@After
52+
public void tearDown() throws IOException {
53+
server.shutdown();
54+
}
55+
1156
@Test
1257
public void sanity() throws Exception {
1358
BannerText bannerText = BannerText.builder().text("test").build();
@@ -20,4 +65,32 @@ public void testSerializable() throws Exception {
2065
byte[] serialized = TestUtils.serialize(bannerText);
2166
assertEquals(bannerText, deserialize(serialized, BannerText.class));
2267
}
68+
69+
@Test
70+
public void requestBannerInstructions() throws Exception {
71+
Response<DirectionsResponse> response = MapboxDirections.builder()
72+
.baseUrl(mockUrl.toString())
73+
.accessToken(ACCESS_TOKEN)
74+
.origin(Point.fromLngLat(-122.03067988107114, 37.331808179989494))
75+
.destination(Point.fromLngLat(-122.03178702099605, 37.3302383113533))
76+
.profile(DirectionsCriteria.PROFILE_DRIVING)
77+
.voiceUnits("imperial")
78+
.roundaboutExits(true)
79+
.geometries("polyline")
80+
.overview("full")
81+
.steps(true)
82+
.voiceInstructions(true)
83+
.bannerInstructions(true)
84+
.build().executeCall();
85+
86+
BannerText bannerText = response.body()
87+
.routes().get(0)
88+
.legs().get(0)
89+
.steps().get(0)
90+
.bannerInstructions().get(0)
91+
.primary();
92+
93+
assertNotNull(bannerText.modifier());
94+
assertNotNull(bannerText.type());
95+
}
2396
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"routes":[{"geometry":"yjzbFfcygVV?vA?P@NAzAa@VGX`BRbAF\\@`@?P","legs":[{"summary":"Infinite Loop, Mariani Avenue","weight":74.9,"duration":64.1,"steps":[{"intersections":[{"out":0,"entry":[true],"bearings":[180],"location":[-122.03076,37.331808]},{"out":1,"in":0,"entry":[false,true,true],"bearings":[0,180,270],"location":[-122.03076,37.331686]},{"out":1,"in":0,"entry":[false,true,true],"bearings":[0,165,270],"location":[-122.030765,37.331157]}],"driving_side":"right","geometry":"yjzbFfcygVV?vA?P@NAzAa@VG","mode":"driving","maneuver":{"bearing_after":180,"bearing_before":0,"location":[-122.03076,37.331808],"modifier":"left","type":"depart","instruction":"Head south on Infinite Loop"},"weight":50,"duration":39.3,"name":"Infinite Loop","distance":148,"voiceInstructions":[{"distanceAlongGeometry":148,"announcement":"Head south on Infinite Loop, then turn right onto Mariani Avenue","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">Head south on Infinite Loop, then turn right onto Mariani Avenue</prosody></amazon:effect></speak>"},{"distanceAlongGeometry":56.5,"announcement":"Turn right onto Mariani Avenue, then you will arrive at your destination","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">Turn right onto Mariani Avenue, then you will arrive at your destination</prosody></amazon:effect></speak>"}],"bannerInstructions":[{"distanceAlongGeometry":148,"primary":{"type":"turn","modifier":"right","components":[{"text":"Mariani Avenue","type":"text","abbr":"Mariani Ave","abbr_priority":0}],"text":"Mariani Avenue"},"secondary":null}]},{"intersections":[{"out":1,"in":2,"entry":[true,true,false],"bearings":[90,255,345],"location":[-122.03055,37.3305]}],"driving_side":"right","geometry":"sbzbF|aygVX`BRbAF\\@`@?P","mode":"driving","maneuver":{"bearing_after":250,"bearing_before":163,"location":[-122.03055,37.3305],"modifier":"right","type":"end of road","instruction":"Turn right onto Mariani Avenue"},"weight":24.9,"duration":24.8,"name":"Mariani Avenue","distance":114.5,"voiceInstructions":[{"distanceAlongGeometry":13.9,"announcement":"You have arrived at your destination","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">You have arrived at your destination</prosody></amazon:effect></speak>"}],"bannerInstructions":[{"distanceAlongGeometry":114.5,"primary":{"type":"arrive","modifier":"straight","components":[{"text":"You will arrive","type":"text"}],"text":"You will arrive"},"secondary":{"type":"arrive","modifier":"straight","components":[{"text":"Mariani Avenue","type":"text","abbr":"Mariani Ave","abbr_priority":0}],"text":"Mariani Avenue"}},{"distanceAlongGeometry":15,"primary":{"type":"arrive","modifier":"straight","components":[{"text":"You have arrived","type":"text"}],"text":"You have arrived"},"secondary":{"type":"arrive","modifier":"straight","components":[{"text":"Mariani Avenue","type":"text","abbr":"Mariani Ave","abbr_priority":0}],"text":"Mariani Avenue"}}]},{"intersections":[{"in":0,"entry":[true],"bearings":[90],"location":[-122.031787,37.330217]}],"driving_side":"right","geometry":"{`zbFtiygV","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":270,"location":[-122.031787,37.330217],"type":"arrive","instruction":"You have arrived at your destination"},"weight":0,"duration":0,"name":"Mariani Avenue","distance":0,"voiceInstructions":[],"bannerInstructions":[]}],"distance":262.5}],"weight_name":"routability","weight":74.9,"duration":64.1,"distance":262.5,"voiceLocale":"en-US"}],"waypoints":[{"name":"Infinite Loop","location":[-122.03076,37.331808]},{"name":"Mariani Avenue","location":[-122.031787,37.330217]}],"code":"Ok","uuid":"cjeahg7sj3of747lgc2f0p3pp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"matchings":[{"confidence":0.8849067703299458,"geometry":"}_m_Iu{{pAEZwA{@cC}AqBsAaCyA","legs":[{"summary":"Adalbertstraße","weight":60.6,"duration":47.4,"steps":[{"intersections":[{"classes":["restricted"],"out":0,"entry":[true],"bearings":[291],"location":[13.418992,52.500626]}],"driving_side":"right","geometry":"}_m_Iu{{pA?DET","mode":"driving","maneuver":{"bearing_after":291,"bearing_before":0,"location":[13.418992,52.500626],"modifier":"left","type":"depart","instruction":"Kör åt nordväst"},"weight":33.6,"duration":20.4,"name":"","distance":10.2},{"intersections":[{"out":0,"in":1,"entry":[true,false,true],"bearings":[15,105,210],"location":[13.418852,52.500659]}],"driving_side":"right","geometry":"c`m_Iyz{pAoAu@GE","mode":"driving","maneuver":{"bearing_after":21,"bearing_before":291,"location":[13.418852,52.500659],"modifier":"right","type":"turn","instruction":"Sväng höger in på Adalbertstraße"},"weight":27,"duration":27,"name":"Adalbertstraße","distance":52.6},{"intersections":[{"in":0,"entry":[true],"bearings":[202],"location":[13.419148,52.501096]}],"driving_side":"right","geometry":"{bm_Iu|{pA","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":22,"location":[13.419148,52.501096],"modifier":"left","type":"arrive","instruction":"Du är framme vid din 1:a destination, till vänster"},"weight":0,"duration":0,"name":"Adalbertstraße","distance":0}],"distance":62.7},{"summary":"Adalbertstraße","weight":32.6,"duration":20.6,"steps":[{"intersections":[{"out":0,"entry":[true],"bearings":[22],"location":[13.419148,52.501096]},{"out":0,"in":2,"entry":[true,true,false,true],"bearings":[30,120,195,300],"location":[13.419277,52.501287]}],"driving_side":"right","geometry":"{bm_Iu|{pAe@Ym@a@o@a@","mode":"driving","maneuver":{"bearing_after":22,"bearing_before":0,"location":[13.419148,52.501096],"modifier":"left","type":"depart","instruction":"Kör åt nordost på Adalbertstraße"},"weight":32.6,"duration":20.6,"name":"Adalbertstraße","distance":80},{"intersections":[{"in":0,"entry":[true],"bearings":[204],"location":[13.41962,52.501755]}],"driving_side":"right","geometry":"_gm_Is_|pA","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":24,"location":[13.41962,52.501755],"modifier":"right","type":"arrive","instruction":"Du är framme vid din 2:a destination, till höger"},"weight":0,"duration":0,"name":"Adalbertstraße","distance":0}],"distance":80},{"summary":"Adalbertstraße","weight":9.9,"duration":9.8,"steps":[{"intersections":[{"out":0,"entry":[true],"bearings":[24],"location":[13.41962,52.501755]},{"out":0,"in":2,"entry":[true,true,false,true],"bearings":[30,120,210,300],"location":[13.419982,52.502249]}],"driving_side":"right","geometry":"_gm_Is_|pAaBgAOK","mode":"driving","maneuver":{"bearing_after":24,"bearing_before":0,"location":[13.41962,52.501755],"modifier":"right","type":"depart","instruction":"Kör åt nordost på Adalbertstraße"},"weight":9.9,"duration":9.8,"name":"Adalbertstraße","distance":70.4},{"intersections":[{"in":0,"entry":[true],"bearings":[203],"location":[13.420041,52.502334]}],"driving_side":"right","geometry":"qjm_Igb|pA","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":23,"location":[13.420041,52.502334],"modifier":"left","type":"arrive","instruction":"Du är framme vid din 3:e destination, till vänster"},"weight":0,"duration":0,"name":"Adalbertstraße","distance":0}],"distance":70.4},{"summary":"Adalbertstraße","weight":18.8,"duration":18.8,"steps":[{"intersections":[{"out":0,"entry":[true],"bearings":[23],"location":[13.420041,52.502334]}],"driving_side":"right","geometry":"qjm_Igb|pAaCyA","mode":"driving","maneuver":{"bearing_after":23,"bearing_before":0,"location":[13.420041,52.502334],"modifier":"left","type":"depart","instruction":"Kör åt nordost på Adalbertstraße"},"weight":18.8,"duration":18.8,"name":"Adalbertstraße","distance":78.5},{"intersections":[{"in":0,"entry":[true],"bearings":[203],"location":[13.420494,52.502984]}],"driving_side":"right","geometry":"snm_Iae|pA","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":23,"location":[13.420494,52.502984],"modifier":"right","type":"arrive","instruction":"Du är framme vid din destination, till höger"},"weight":0,"duration":0,"name":"Adalbertstraße","distance":0}],"distance":78.5}],"weight_name":"routability","weight":121.9,"duration":96.6,"distance":291.6}],"tracepoints":[{"alternatives_count":0,"waypoint_index":0,"matchings_index":0,"name":"","location":[13.418992,52.500626]},{"alternatives_count":0,"waypoint_index":1,"matchings_index":0,"name":"Adalbertstraße","location":[13.419148,52.501096]},{"alternatives_count":0,"waypoint_index":2,"matchings_index":0,"name":"Adalbertstraße","location":[13.41962,52.501755]},{"alternatives_count":0,"waypoint_index":3,"matchings_index":0,"name":"Adalbertstraße","location":[13.420041,52.502334]},{"alternatives_count":1,"waypoint_index":4,"matchings_index":0,"name":"Adalbertstraße","location":[13.420494,52.502984]}],"code":"Ok"}

0 commit comments

Comments
 (0)