Skip to content

Commit

Permalink
expose snapping_include_static_closures
Browse files Browse the repository at this point in the history
  • Loading branch information
dzinad committed Jul 28, 2022
1 parent 0e9ea0e commit 29f3cbe
Show file tree
Hide file tree
Showing 9 changed files with 304 additions and 73 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Mapbox welcomes participation and contributions from everyone.

### main
- Added `RouteOptions.snappingIncludeStaticClosures` and `RouteOptions.snappingIncludeStaticClosuresList`. [#1469](https://github.com/mapbox/mapbox-java/pull/1469)

### v6.7.0-beta.1 - Jul 22, 2022
- Added `Incident.affectedRoadNames`. [#1457](https://github.com/mapbox/mapbox-java/pull/1457)
Expand Down
122 changes: 122 additions & 0 deletions samples/src/main/java/com/mapbox/samples/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"code": "Ok",
"waypoints": [
{
"name": "Jorden",
"location": [
-95.633041,
29.789099
],
"distance": 18.873
},
{
"name": "Austin Street",
"location": [
-95.359243,
29.757685
],
"distance": 16.747
}
],
"routes": [
{
"country_crossed": false,
"weight_typical": 1912.277,
"routeIndex": "0",
"distance": 29967.924,
"duration": 1523.01,
"duration_typical": 1531.425,
"geometry": "uydyw@`h~kuDti@cg@V`r@r~@gc]r|DxEz@{yIx`@y{fHlnHilRxjB{mn@ha@q}mAwhCe_TtiCgkIxgDo`CbtHahChqFvoB|kB`rDdbCvnA`nIixOi|AiiA``AqjBuqAy_A",
"weight": 1901.654,
"weight_name": "auto",
"legs": [
{
"weight_typical": 1912.277,
"weight": 1901.654,
"via_waypoints": [],
"distance": 29967.924,
"duration": 1523.01,
"duration_typical": 1531.425,
"summary": "Park Row, I 10 East",
"admins": [
{
"iso_3166_1": "US",
"iso_3166_1_alpha3": "USA"
}
],
"steps": []
}
],
"routeOptions": {
"baseUrl": "https://api.mapbox.com",
"user": "mapbox",
"profile": "driving-traffic",
"coordinates": "-95.6332,29.789;-95.3591,29.7576",
"alternatives": true,
"geometries": "polyline6",
"compute_toll_cost": true
},
"requestUuid": "GlP3NG2g3mUgjgISzOf8cftN63D--E8IcZ7l6NxEZrlU9lWKuM2k0A\u003d\u003d",
"toll_costs": [
{
"currency": "yen",
"payment_methods": {
"etc": {
"standard": -1.0
}
}
}
]
},
{
"country_crossed": false,
"weight_typical": 2124.817,
"routeIndex": "1",
"distance": 35648.906,
"duration": 1718.277,
"duration_typical": 1711.331,
"geometry": "uydyw@`h~kuDti@cg@V`r@r~@gc]r|DxEz@{yIx`@y{fH~s@mbDpsDwcDlst@rB~la@hoFtzEhu@xbBqmAn_Aii^evDueeBubCyff@qhYueSsbLmgJs`E`aIib@yZ",
"weight": 2132.387,
"weight_name": "auto",
"legs": [
{
"weight_typical": 2124.817,
"weight": 2132.387,
"via_waypoints": [],
"distance": 35648.906,
"duration": 1718.277,
"duration_typical": 1711.331,
"summary": "I 10 East, I 69 North",
"admins": [
{
"iso_3166_1": "US",
"iso_3166_1_alpha3": "USA"
}
],
"steps": []
}
],
"routeOptions": {
"baseUrl": "https://api.mapbox.com",
"user": "mapbox",
"profile": "driving-traffic",
"coordinates": "-95.6332,29.789;-95.3591,29.7576",
"alternatives": true,
"geometries": "polyline6",
"compute_toll_cost": true
},
"requestUuid": "GlP3NG2g3mUgjgISzOf8cftN63D--E8IcZ7l6NxEZrlU9lWKuM2k0A\u003d\u003d",
"toll_costs": [
{
"currency": "yen",
"payment_methods": {
"etc": {
"standard": -1.0
}
}
}
]
}
],
"uuid": "GlP3NG2g3mUgjgISzOf8cftN63D--E8IcZ7l6NxEZrlU9lWKuM2k0A\u003d\u003d"
}
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,23 @@ public List<Point> waypointTargetsList() {
@Nullable
public abstract String snappingIncludeClosures();

/**
* A semicolon-separated list of booleans affecting snapping of waypoint locations to road segments.
* If true, road segments statically closed, that is long-term, will be considered for snapping
* (for example, road under construction).
* If false, they will not be considered for snapping.
* If provided, the number of snappingIncludeStaticClosures must be the same as the number of waypoints.
* However, you can skip a coordinate and show its position in the list with the ; separator.
* If null, this parameter defaults to false.
* <p>
* Only available with the {@link DirectionsCriteria#PROFILE_DRIVING_TRAFFIC}.
*
* @return a String representing a list of booleans
*/
@SerializedName("snapping_include_static_closures")
@Nullable
public abstract String snappingIncludeStaticClosures();

/**
* A list of booleans affecting snapping of waypoint locations to road segments.
* If true, road segments closed due to live-traffic closures will be considered for snapping.
Expand All @@ -761,6 +778,24 @@ public List<Boolean> snappingIncludeClosuresList() {
return ParseUtils.parseToBooleans(snappingIncludeClosures());
}

/**
* A list of booleans affecting snapping of waypoint locations to road segments.
* If true, road segments statically closed, that is long-term, will be considered for snapping
* (for example, road under construction).
* If false, they will not be considered for snapping.
* If provided, the number of snappingIncludeStaticClosures must be the same as the number of waypoints.
* However, you can skip a coordinate and show its position in the list with the null.
* If null, this parameter defaults to false.
* <p>
* Only available with the {@link DirectionsCriteria#PROFILE_DRIVING_TRAFFIC}.
*
* @return a list of booleans
*/
@Nullable
public List<Boolean> snappingIncludeStaticClosuresList() {
return ParseUtils.parseToBooleans(snappingIncludeStaticClosures());
}

/**
* The desired arrival time, formatted as a timestamp in ISO-8601 format
* in the local time at the route destination.
Expand Down Expand Up @@ -975,6 +1010,7 @@ public URL toUrl(@NonNull String accessToken) {
appendQueryParameter(sb, "walkway_bias", walkwayBias());
appendQueryParameter(sb, "alley_bias", alleyBias());
appendQueryParameter(sb, "snapping_include_closures", snappingIncludeClosures());
appendQueryParameter(sb, "snapping_include_static_closures", snappingIncludeStaticClosures());
appendQueryParameter(sb, "arrive_by", arriveBy());
appendQueryParameter(sb, "depart_at", departAt());
appendQueryParameter(sb, "max_height", maxHeight());
Expand Down Expand Up @@ -1858,6 +1894,46 @@ public Builder snappingIncludeClosuresList(@Nullable List<Boolean> snappingClosu
return this;
}

/**
* A semicolon-separated list of booleans affecting snapping of waypoint locations to road segments.
* If true, road segments statically closed, that is long-term, will be considered for snapping
* (for example, road under construction).
* If false, they will not be considered for snapping.
* If provided, the number of snappingIncludeStaticClosures must be the same as the number of waypoints.
* However, you can skip a coordinate and show its position in the list with the ; separator.
* If null, this parameter defaults to false.
* <p>
* Only available with the {@link DirectionsCriteria#PROFILE_DRIVING_TRAFFIC}.
*
* @param snappingStaticClosures a String representing a list of booleans
* @return this builder for chaining options together
*/
@NonNull
public abstract Builder snappingIncludeStaticClosures(@Nullable String snappingStaticClosures);

/**
* A list of booleans affecting snapping of waypoint locations to road segments.
* If true, road segments statically closed, that is long-term, will be considered for snapping
* (for example, road under construction).
* If false, they will not be considered for snapping.
* If provided, the number of snappingIncludeStaticClosures must be the same as the number of waypoints.
* However, you can skip a coordinate and show its position in the list with the null.
* If null, this parameter defaults to false.
* <p>
* Only available with the {@link DirectionsCriteria#PROFILE_DRIVING_TRAFFIC}.
*
* @param snappingStaticClosures a list of booleans
* @return this builder for chaining options together
*/
@NonNull
public Builder snappingIncludeStaticClosuresList(@Nullable List<Boolean> snappingStaticClosures) {
String result = FormatUtils.join(";", snappingStaticClosures);
if (result != null) {
snappingIncludeStaticClosures(result);
}
return this;
}

/**
* The desired arrival time, formatted as a timestamp in ISO-8601 format
* in the local time at the route destination.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class RouteOptionsTest extends TestUtils {
*/
private static final String ROUTE_OPTIONS_JSON = "route_options_v5.json";
private static final String ROUTE_OPTIONS_URL =
"https://api.mapbox.com/directions/v5/mapbox/driving/-122.4003312,37.7736941;-122.4187529,37.7689715;-122.4255172,37.7775835?access_token=pk.token&geometries=polyline6&alternatives=false&overview=full&radiuses=%3Bunlimited%3B5.1&steps=true&avoid_maneuver_radius=200.0&bearings=0%2C90%3B90%2C0%3B&layers=-42%3B%3B0&continue_straight=false&annotations=congestion%2Cdistance%2Cduration&language=ru&roundabout_exits=false&voice_instructions=true&banner_instructions=true&voice_units=metric&exclude=toll%2Cferry%2Cpoint%2811.0+-22.0%29&include=hot%2Chov2&approaches=%3Bcurb%3B&waypoints=0%3B1%3B2&waypoint_names=%3BSerangoon+Garden+Market+%26+Food+Centre%3BFunky+%26nAmE*&waypoint_targets=%3B12.2%2C21.2%3B&enable_refresh=true&walking_speed=5.11&walkway_bias=-0.2&alley_bias=0.75&snapping_include_closures=%3Bfalse%3Btrue&arrive_by=2021-01-01%27T%2701%3A01&depart_at=2021-02-02%27T%2702%3A02&max_height=1.5&max_width=1.4&max_weight=2.9&metadata=true";
"https://api.mapbox.com/directions/v5/mapbox/driving/-122.4003312,37.7736941;-122.4187529,37.7689715;-122.4255172,37.7775835?access_token=pk.token&geometries=polyline6&alternatives=false&overview=full&radiuses=%3Bunlimited%3B5.1&steps=true&avoid_maneuver_radius=200.0&bearings=0%2C90%3B90%2C0%3B&layers=-42%3B%3B0&continue_straight=false&annotations=congestion%2Cdistance%2Cduration&language=ru&roundabout_exits=false&voice_instructions=true&banner_instructions=true&voice_units=metric&exclude=toll%2Cferry%2Cpoint%2811.0+-22.0%29&include=hot%2Chov2&approaches=%3Bcurb%3B&waypoints=0%3B1%3B2&waypoint_names=%3BSerangoon+Garden+Market+%26+Food+Centre%3BFunky+%26nAmE*&waypoint_targets=%3B12.2%2C21.2%3B&enable_refresh=true&walking_speed=5.11&walkway_bias=-0.2&alley_bias=0.75&snapping_include_closures=%3Bfalse%3Btrue&snapping_include_static_closures=true%3B%3Bfalse&arrive_by=2021-01-01%27T%2701%3A01&depart_at=2021-02-02%27T%2702%3A02&max_height=1.5&max_width=1.4&max_weight=2.9&metadata=true";
private static final String ACCESS_TOKEN = "pk.token";

private final String optionsJson = loadJsonFixture(ROUTE_OPTIONS_JSON);
Expand Down Expand Up @@ -265,6 +265,13 @@ public void snappingIncludeClosuresStringIsValid_fromJson() {
assertEquals(";false;true", options.snappingIncludeClosures());
}

@Test
public void snappingIncludeStaticClosuresStringIsValid_fromJson() {
RouteOptions options = RouteOptions.fromJson(optionsJson);

assertEquals("true;;false", options.snappingIncludeStaticClosures());
}

@Test
public void alleyBiasIsValid_fromJson() {
RouteOptions options = RouteOptions.fromJson(optionsJson);
Expand Down Expand Up @@ -812,6 +819,7 @@ private RouteOptions routeOptions() {
.maxWidth(1.4)
.maxWeight(2.9)
.snappingIncludeClosures(";false;true")
.snappingIncludeStaticClosures("true;;false")
.user(DirectionsCriteria.PROFILE_DEFAULT_USER)
.enableRefresh(true)
.metadata(true)
Expand Down Expand Up @@ -904,6 +912,11 @@ private RouteOptions routeOptionsList() {
add(false);
add(true);
}})
.snappingIncludeStaticClosuresList(new ArrayList<Boolean>() {{
add(true);
add(null);
add(false);
}})
.user(DirectionsCriteria.PROFILE_DEFAULT_USER)
.enableRefresh(true)
.metadata(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"waypoint_names": ";Serangoon Garden Market & Food Centre;Funky &nAmE*",
"waypoint_targets": ";12.2,21.2;",
"snapping_include_closures": ";false;true",
"snapping_include_static_closures": "true;;false",
"alley_bias": 0.75,
"walking_speed": 5.11,
"walkway_bias": -0.2,
Expand Down
Loading

0 comments on commit 29f3cbe

Please sign in to comment.