Skip to content

Commit 1c9ff8e

Browse files
authored
Added max_width and max_height to Directions API params (#1283)
1 parent 5903371 commit 1c9ff8e

7 files changed

Lines changed: 108 additions & 0 deletions

File tree

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,30 @@ public List<Boolean> snappingIncludeClosuresList() {
638638
@Nullable
639639
public abstract String departAt();
640640

641+
/**
642+
* The max vehicle height in meters. If this parameter is provided, the Directions API will
643+
* compute a route that includes only roads with a height limit greater than or equal to the max
644+
* vehicle height. max_height must be between 0 and 10 meters. The default value is 1.6 meters.
645+
* <p>
646+
* Available for {@link DirectionsCriteria#PROFILE_DRIVING_TRAFFIC} and
647+
* {@link DirectionsCriteria#PROFILE_DRIVING}.
648+
*/
649+
@SerializedName("max_height")
650+
@Nullable
651+
public abstract Double maxHeight();
652+
653+
/**
654+
* The max vehicle width in meters. If this parameter is provided, the Directions API will
655+
* compute a route that includes only roads with a width limit greater than or equal to the max
656+
* vehicle width. max_width must be between 0 and 10 meters. The default value is 1.9 meters.
657+
* <p>
658+
* Available for {@link DirectionsCriteria#PROFILE_DRIVING_TRAFFIC} and
659+
* {@link DirectionsCriteria#PROFILE_DRIVING}.
660+
*/
661+
@SerializedName("max_width")
662+
@Nullable
663+
public abstract Double maxWidth();
664+
641665
/**
642666
* Whether the routes should be refreshable via the directions refresh API.
643667
* <p>
@@ -1420,6 +1444,34 @@ public Builder snappingIncludeClosuresList(@Nullable List<Boolean> snappingClosu
14201444
@NonNull
14211445
public abstract Builder departAt(@Nullable String departAt);
14221446

1447+
/**
1448+
* The max vehicle height in meters. If this parameter is provided, the Directions API will
1449+
* compute a route that includes only roads with a height limit greater than or equal to the max
1450+
* vehicle height. The default value is 1.6 meters.
1451+
* <p>
1452+
* Available for {@link DirectionsCriteria#PROFILE_DRIVING_TRAFFIC} and
1453+
* {@link DirectionsCriteria#PROFILE_DRIVING}.
1454+
*
1455+
* @param maxHeight max vehicle height, in meters. Must be between 0 and 10.
1456+
* @return this builder
1457+
*/
1458+
@NonNull
1459+
public abstract Builder maxHeight(@Nullable @FloatRange(from = 0, to = 10) Double maxHeight);
1460+
1461+
/**
1462+
* The max vehicle width in meters. If this parameter is provided, the Directions API will
1463+
* compute a route that includes only roads with a width limit greater than or equal to the max
1464+
* vehicle width. The default value is 1.9 meters.
1465+
* <p>
1466+
* Available for {@link DirectionsCriteria#PROFILE_DRIVING_TRAFFIC} and
1467+
* {@link DirectionsCriteria#PROFILE_DRIVING}.
1468+
*
1469+
* @param maxWidth max vehicle width, in meters. Must be between 0 and 10.
1470+
* @return this builder
1471+
*/
1472+
@NonNull
1473+
public abstract Builder maxWidth(@Nullable @FloatRange(from = 0, to = 10) Double maxWidth);
1474+
14231475
/**
14241476
* Whether the routes should be refreshable via the directions refresh API.
14251477
* <p>

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,20 @@ public void departAtIsValid_fromJson() {
244244
assertEquals("2021-02-02'T'02:02", options.departAt());
245245
}
246246

247+
@Test
248+
public void maxHeightIsValid_fromJson() {
249+
RouteOptions options = RouteOptions.fromJson(optionsJson);
250+
251+
assertEquals(1.5, options.maxHeight(), 0.000001);
252+
}
253+
254+
@Test
255+
public void maxWidthIsValid_fromJson() {
256+
RouteOptions options = RouteOptions.fromJson(optionsJson);
257+
258+
assertEquals(1.4, options.maxWidth(), 0.000001);
259+
}
260+
247261
@Test
248262
public void enableRefreshIsValid_fromJson() {
249263
RouteOptions options = RouteOptions.fromJson(optionsJson);
@@ -308,6 +322,8 @@ private RouteOptions routeOptions() {
308322
.walkwayBias(-0.2)
309323
.arriveBy("2021-01-01'T'01:01")
310324
.departAt("2021-02-02'T'02:02")
325+
.maxHeight(1.5)
326+
.maxWidth(1.4)
311327
.snappingIncludeClosures(";false;true")
312328
.user(DirectionsCriteria.PROFILE_DEFAULT_USER)
313329
.enableRefresh(true)
@@ -379,6 +395,8 @@ private RouteOptions routeOptionsList() {
379395
.walkwayBias(-0.2)
380396
.arriveBy("2021-01-01'T'01:01")
381397
.departAt("2021-02-02'T'02:02")
398+
.maxHeight(1.5)
399+
.maxWidth(1.4)
382400
.snappingIncludeClosuresList(new ArrayList<Boolean>() {{
383401
add(null);
384402
add(false);

services-directions-models/src/test/resources/route_options_v5.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"walkway_bias": -0.2,
2828
"arrive_by": "2021-01-01'T'01:01",
2929
"depart_at": "2021-02-02'T'02:02",
30+
"max_height": 1.5,
31+
"max_width": 1.4,
3032
"enable_refresh": true,
3133
"metadata": true
3234
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ interface DirectionsService {
5050
* @param snappingIncludeClosures {@link RouteOptions#snappingIncludeClosures()}
5151
* @param arriveBy {@link RouteOptions#arriveBy()}
5252
* @param departAt {@link RouteOptions#departAt()}
53+
* @param maxHeight {@link RouteOptions#maxHeight()}
54+
* @param maxWidth {@link RouteOptions#maxWidth()}
5355
* @param metadata {@link RouteOptions#metadata()}
5456
* @return the {@link DirectionsResponse} in a Call wrapper
5557
*/
@@ -85,6 +87,8 @@ Call<DirectionsResponse> getCall(
8587
@Query("snapping_include_closures") String snappingIncludeClosures,
8688
@Query("arrive_by") String arriveBy,
8789
@Query("depart_at") String departAt,
90+
@Query("max_height") Double maxHeight,
91+
@Query("max_width") Double maxWidth,
8892
@Query("metadata") Boolean metadata
8993
);
9094

@@ -121,6 +125,8 @@ Call<DirectionsResponse> getCall(
121125
* @param snappingIncludeClosures {@link RouteOptions#snappingIncludeClosures()}
122126
* @param arriveBy {@link RouteOptions#arriveBy()}
123127
* @param departAt {@link RouteOptions#departAt()}
128+
* @param maxHeight {@link RouteOptions#maxHeight()}
129+
* @param maxWidth {@link RouteOptions#maxWidth()}
124130
* @param metadata {@link RouteOptions#metadata()}
125131
* @return the {@link DirectionsResponse} in a Call wrapper
126132
*/
@@ -157,6 +163,8 @@ Call<DirectionsResponse> postCall(
157163
@Field("snapping_include_closures") String snappingIncludeClosures,
158164
@Field("arrive_by") String arriveBy,
159165
@Field("depart_at") String departAt,
166+
@Field("max_height") Double maxHeight,
167+
@Field("max_width") Double maxWidth,
160168
@Field("metadata") Boolean metadata
161169
);
162170
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ private Call<DirectionsResponse> get() {
105105
routeOptions().snappingIncludeClosures(),
106106
routeOptions().arriveBy(),
107107
routeOptions().departAt(),
108+
routeOptions().maxHeight(),
109+
routeOptions().maxWidth(),
108110
routeOptions().metadata()
109111
);
110112
}
@@ -141,6 +143,8 @@ private Call<DirectionsResponse> post() {
141143
routeOptions().snappingIncludeClosures(),
142144
routeOptions().arriveBy(),
143145
routeOptions().departAt(),
146+
routeOptions().maxHeight(),
147+
routeOptions().maxWidth(),
144148
routeOptions().metadata()
145149
);
146150
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,28 @@ public void depart_at() throws Exception {
730730
mapboxDirections.cloneCall().request().url().queryParameter("depart_at"));
731731
}
732732

733+
@Test
734+
public void max_height() throws Exception {
735+
MapboxDirections mapboxDirections = MapboxDirections.builder()
736+
.accessToken("token")
737+
.routeOptions(routeOptions.toBuilder().baseUrl(mockUrl.toString()).build())
738+
.build();
739+
740+
assertEquals("1.5",
741+
mapboxDirections.cloneCall().request().url().queryParameter("max_height"));
742+
}
743+
744+
@Test
745+
public void max_width() throws Exception {
746+
MapboxDirections mapboxDirections = MapboxDirections.builder()
747+
.accessToken("token")
748+
.routeOptions(routeOptions.toBuilder().baseUrl(mockUrl.toString()).build())
749+
.build();
750+
751+
assertEquals("1.4",
752+
mapboxDirections.cloneCall().request().url().queryParameter("max_width"));
753+
}
754+
733755
@Test
734756
public void enable_refresh() throws Exception {
735757
MapboxDirections mapboxDirections = MapboxDirections.builder()

services-directions/src/test/resources/route_options_v5.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"walkway_bias": -0.2,
2828
"arrive_by": "2021-01-01'T'01:01",
2929
"depart_at": "2021-02-02'T'02:02",
30+
"max_height": 1.5,
31+
"max_width": 1.4,
3032
"enable_refresh": true,
3133
"metadata": true
3234
}

0 commit comments

Comments
 (0)