1717import com .mapbox .geojson .Point ;
1818import com .mapbox .geojson .gson .GeoJsonAdapterFactory ;
1919
20+ import java .util .HashSet ;
2021import java .util .Locale ;
22+ import java .util .Set ;
2123
2224import retrofit2 .Call ;
2325
@@ -50,6 +52,8 @@ protected MapboxIsochrone() {
5052
5153 @ Override
5254 protected GsonBuilder getGsonBuilder () {
55+ MapboxIsochrone .Builder b = MapboxIsochrone .builder ();
56+
5357 return new GsonBuilder ()
5458 .registerTypeAdapterFactory (GeoJsonAdapterFactory .create ())
5559 .registerTypeAdapterFactory (GeometryAdapterFactory .create ());
@@ -66,7 +70,10 @@ protected Call<FeatureCollection> initializeCall() {
6670 contoursColors (),
6771 polygons (),
6872 denoise (),
69- generalize ()
73+ generalize (),
74+ contoursMeters (),
75+ exclusions (),
76+ departAt ()
7077 );
7178 }
7279
@@ -80,6 +87,8 @@ protected Call<FeatureCollection> initializeCall() {
8087 public static Builder builder () {
8188 return new AutoValue_MapboxIsochrone .Builder ()
8289 .baseUrl (Constants .BASE_API_URL )
90+ .contoursMinutes ("" )
91+ .contoursMeters ("" )
8392 .user (IsochroneCriteria .PROFILE_DEFAULT_USER );
8493 }
8594
@@ -114,6 +123,15 @@ public static Builder builder() {
114123 @ Nullable
115124 abstract Float generalize ();
116125
126+ @ Nullable
127+ abstract String contoursMeters ();
128+
129+ @ Nullable
130+ abstract String exclusions ();
131+
132+ @ Nullable
133+ abstract String departAt ();
134+
117135 /**
118136 * This builder is used to create a new request to the Mapbox Isochrone API. At a bare minimum,
119137 * your request must include an access token, a directions routing profile (driving, walking,
@@ -131,9 +149,11 @@ public abstract static class Builder {
131149
132150 private Integer [] contoursMinutes ;
133151 private String [] contoursColors ;
152+ private Integer [] contoursMeters ;
153+ private Set <String > exclusions = new HashSet <>();
134154
135155 /**
136- * Optionally change the APIs base URL to something other then the default Mapbox one.
156+ * Optionally change the APIs base URL to something other than the default Mapbox one.
137157 *
138158 * @param baseUrl base url used as end point
139159 * @return this builder for chaining options together
@@ -164,6 +184,8 @@ public abstract static class Builder {
164184 /**
165185 * A Mapbox Directions routing profile ID. Options are
166186 * {@link IsochroneCriteria#PROFILE_DRIVING} for travel times by car,
187+ * {@link IsochroneCriteria#PROFILE_DRIVING_TRAFFIC} for fastest travel by car using
188+ * current and historic traffic,
167189 * {@link IsochroneCriteria#PROFILE_WALKING} for pedestrian and hiking travel times,
168190 * and {@link IsochroneCriteria#PROFILE_CYCLING} for travel times by bicycle.
169191 *
@@ -217,6 +239,22 @@ public Builder addContoursMinutes(@NonNull @IntRange(from = 0, to = 60)
217239 return this ;
218240 }
219241
242+ /**
243+ * An integer list of meter values to use for each isochrone contour.
244+ * The distances, in meters, to use for each isochrone contour. You
245+ * must be in increasing order. The default maximum distance that can be specified
246+ * is 100000 meters (100km), if you need a bigger range contact support.
247+ *
248+ * @param listOfMeterValues an integer list with at least one number
249+ * for the meters which represent each contour
250+ * @return this builder for chaining options together
251+ * @since 7.3.0
252+ */
253+ public Builder addContoursMeters (Integer ... listOfMeterValues ) {
254+ this .contoursMeters = listOfMeterValues ;
255+ return this ;
256+ }
257+
220258 /**
221259 * A single String which is a comma-separated list of time(s) in minutes
222260 * to use for each isochrone contour. You must pass in at least one minute
@@ -226,12 +264,25 @@ public Builder addContoursMinutes(@NonNull @IntRange(from = 0, to = 60)
226264 *
227265 * @param stringListOfMinuteValues a String of at least one number for the
228266 * minutes which represent each contour
229- * @return this builder for chaining optio.ns together
267+ * @return this builder for chaining options together
230268 */
231269 // Required for matching with MapboxIsochrone addContoursMinutes() method.
232270 @ SuppressWarnings ("WeakerAccess" )
233271 abstract Builder contoursMinutes (@ NonNull String stringListOfMinuteValues );
234272
273+ /**
274+ * A single String which is a comma-separated list of values(s) in meters
275+ * to use for each isochrone contour. The distances, in meters, to use for each
276+ * isochrone contour. You can specify up to four contours. Distances must be in
277+ * increasing order. The default maximum distance that can be specified
278+ * is 100000 meters (100km), if you need a bigger range contact support.
279+ *
280+ * @param stringListOfMeterValues a String of at least one number for the
281+ * meters which represent each contour
282+ * @return this builder for chaining options together
283+ */
284+ abstract Builder contoursMeters (@ NonNull String stringListOfMeterValues );
285+
235286 /**
236287 * A list of separate String which has a list of comma-separated
237288 * HEX color values to use for each isochrone contour.
@@ -300,6 +351,107 @@ public Builder addContoursColors(@Nullable String... contoursColors) {
300351 */
301352 public abstract Builder generalize (@ Nullable @ FloatRange (from = 0.0 ) Float generalize );
302353
354+ abstract Builder exclusions (@ Nullable String exclusions );
355+
356+ /**
357+ * Exclude highways or motorways. Available in mapbox/driving and
358+ * mapbox/driving-traffic profiles.
359+ * @param exclude indicates whether motorways should be excluded
360+ * @return this builder for chaining options together
361+ *
362+ * @since 7.3.0
363+ */
364+ public Builder excludeMotorways (Boolean exclude ) {
365+ if (exclude != null && exclude ) {
366+ exclusions .add ("motorway" );
367+ } else {
368+ exclusions .remove ("motorway" );
369+ }
370+ return this ;
371+ }
372+
373+ /**
374+ * Exclude tolls. Available in mapbox/driving and
375+ * mapbox/driving-traffic profiles.
376+ * @param exclude indicates whether tolls should be excluded
377+ * @return this builder for chaining options together
378+ *
379+ * @since 7.3.0
380+ */
381+ public Builder excludeTolls (Boolean exclude ) {
382+ if (exclude != null && exclude ) {
383+ exclusions .add ("toll" );
384+ } else {
385+ exclusions .remove ("toll" );
386+ }
387+ return this ;
388+ }
389+
390+ /**
391+ * Exclude ferries. Available in mapbox/driving and
392+ * mapbox/driving-traffic profiles.
393+ * @param exclude indicates whether ferries should be excluded
394+ * @return this builder for chaining options together
395+ *
396+ * @since 7.3.0
397+ */
398+ public Builder excludeFerries (Boolean exclude ) {
399+ if (exclude != null && exclude ) {
400+ exclusions .add ("ferry" );
401+ } else {
402+ exclusions .remove ("ferry" );
403+ }
404+ return this ;
405+ }
406+
407+ /**
408+ * Exclude unpaved roads. Available in mapbox/driving and
409+ * mapbox/driving-traffic profiles.
410+ * @param exclude indicates whether unpaved roads should be excluded
411+ * @return this builder for chaining options together
412+ *
413+ * @since 7.3.0
414+ */
415+ public Builder excludeUnpavedRoads (Boolean exclude ) {
416+ if (exclude != null && exclude ) {
417+ exclusions .add ("unpaved" );
418+ } else {
419+ exclusions .remove ("unpaved" );
420+ }
421+ return this ;
422+ }
423+
424+ /**
425+ * Exclude cash only toll roads. Available in mapbox/driving and
426+ * mapbox/driving-traffic profiles.
427+ * @param exclude indicates whether cash only toll roads should be excluded
428+ * @return this builder for chaining options together
429+ *
430+ * @since 7.3.0
431+ */
432+ public Builder excludeCashOnlyTollRoads (Boolean exclude ) {
433+ if (exclude != null && exclude ) {
434+ exclusions .add ("cash_only_tolls" );
435+ } else {
436+ exclusions .remove ("cash_only_tolls" );
437+ }
438+ return this ;
439+ }
440+
441+ /**
442+ * The departure time from the given coordinates.
443+ * <a href="https://docs.mapbox.com/api/navigation/isochrone/">One of three formats.</a>.
444+ * If not provided then 'depart at' is considered to be the present time in the local
445+ * timezone of the coordinates. The isochrone contours will reflect traffic
446+ * conditions at the time provided.
447+ *
448+ * @param depart the departure date/time
449+ * @return this builder for chaining options together
450+ *
451+ * @since 7.3.0
452+ */
453+ public abstract Builder departAt (@ NonNull String depart );
454+
303455 /**
304456 * @return this builder for chaining options together
305457 * @since 4.6.0
@@ -314,6 +466,8 @@ public Builder addContoursColors(@Nullable String... contoursColors) {
314466 */
315467 public MapboxIsochrone build () {
316468
469+ exclusions (TextUtils .join ("," , exclusions .toArray ()));
470+
317471 if (contoursMinutes != null ) {
318472 if (contoursMinutes .length < 1 ) {
319473 throw new ServicesException ("A query with at least one specified "
@@ -331,6 +485,23 @@ public MapboxIsochrone build() {
331485 contoursMinutes (TextUtils .join ("," , contoursMinutes ));
332486 }
333487
488+ if (contoursMeters != null ) {
489+ if (contoursMeters .length < 1 ) {
490+ throw new ServicesException ("A query with at least one specified "
491+ + "meter value is required." );
492+ }
493+
494+ if (contoursMeters .length >= 2 ) {
495+ for (int x = 0 ; x < contoursMeters .length - 1 ; x ++) {
496+ if (contoursMeters [x ] > contoursMeters [x + 1 ]) {
497+ throw new ServicesException ("The meters must be listed"
498+ + " in order from the lowest number to the highest number." );
499+ }
500+ }
501+ contoursMeters (TextUtils .join ("," , contoursMeters ));
502+ }
503+ }
504+
334505 if (contoursColors != null ) {
335506 contoursColors (TextUtils .join ("," , contoursColors ));
336507 }
@@ -342,6 +513,17 @@ public MapboxIsochrone build() {
342513 + "must match number of minute elements provided." );
343514 }
344515
516+ if (contoursColors != null
517+ && contoursMeters != null
518+ && contoursColors .length != contoursMeters .length ) {
519+ throw new ServicesException ("Number of color elements "
520+ + "must match number of meter elements provided." );
521+ }
522+
523+ if (contoursMinutes != null && contoursMeters != null ) {
524+ throw new ServicesException ("Cannot specify both contoursMinutes and contoursMeters." );
525+ }
526+
345527 MapboxIsochrone isochrone = autoBuild ();
346528
347529 if (!MapboxUtils .isAccessTokenValid (isochrone .accessToken ())) {
@@ -359,9 +541,10 @@ public MapboxIsochrone build() {
359541 + " walking, or driving) is required." );
360542 }
361543
362- if (TextUtils .isEmpty (isochrone .contoursMinutes ())) {
544+ if (TextUtils .isEmpty (isochrone .contoursMinutes ())
545+ && TextUtils .isEmpty (isochrone .contoursMeters ())) {
363546 throw new ServicesException ("A query with at least one specified minute amount"
364- + " is required." );
547+ + " or meter value is required." );
365548 }
366549
367550 if (isochrone .contoursColors () != null ) {
0 commit comments