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,23 @@ 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 maximum distance that can be specified
246+ * is 100000 meters (100km).
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 (@ NonNull @ IntRange (from = 0 , to = 100000 )
254+ Integer ... listOfMeterValues ) {
255+ this .contoursMeters = listOfMeterValues ;
256+ return this ;
257+ }
258+
220259 /**
221260 * A single String which is a comma-separated list of time(s) in minutes
222261 * to use for each isochrone contour. You must pass in at least one minute
@@ -226,12 +265,25 @@ public Builder addContoursMinutes(@NonNull @IntRange(from = 0, to = 60)
226265 *
227266 * @param stringListOfMinuteValues a String of at least one number for the
228267 * minutes which represent each contour
229- * @return this builder for chaining optio.ns together
268+ * @return this builder for chaining options together
230269 */
231270 // Required for matching with MapboxIsochrone addContoursMinutes() method.
232271 @ SuppressWarnings ("WeakerAccess" )
233272 abstract Builder contoursMinutes (@ NonNull String stringListOfMinuteValues );
234273
274+ /**
275+ * A single String which is a comma-separated list of values(s) in meters
276+ * to use for each isochrone contour. The distances, in meters, to use for each
277+ * isochrone contour. You can specify up to four contours. Distances must be in
278+ * increasing order. The maximum distance that can be specified
279+ * is 100000 meters (100km).
280+ *
281+ * @param stringListOfMeterValues a String of at least one number for the
282+ * meters which represent each contour
283+ * @return this builder for chaining options together
284+ */
285+ abstract Builder contoursMeters (@ NonNull String stringListOfMeterValues );
286+
235287 /**
236288 * A list of separate String which has a list of comma-separated
237289 * HEX color values to use for each isochrone contour.
@@ -300,6 +352,107 @@ public Builder addContoursColors(@Nullable String... contoursColors) {
300352 */
301353 public abstract Builder generalize (@ Nullable @ FloatRange (from = 0.0 ) Float generalize );
302354
355+ abstract Builder exclusions (@ Nullable String exclusions );
356+
357+ /**
358+ * Exclude highways or motorways. Available in mapbox/driving and
359+ * mapbox/driving-traffic profiles.
360+ * @param exclude indicates whether motorways should be excluded
361+ * @return this builder for chaining options together
362+ *
363+ * @since 7.3.0
364+ */
365+ public Builder excludeMotorways (Boolean exclude ) {
366+ if (exclude != null && exclude ) {
367+ exclusions .add ("motorway" );
368+ } else {
369+ exclusions .remove ("motorway" );
370+ }
371+ return this ;
372+ }
373+
374+ /**
375+ * Exclude tolls. Available in mapbox/driving and
376+ * mapbox/driving-traffic profiles.
377+ * @param exclude indicates whether tolls should be excluded
378+ * @return this builder for chaining options together
379+ *
380+ * @since 7.3.0
381+ */
382+ public Builder excludeTolls (Boolean exclude ) {
383+ if (exclude != null && exclude ) {
384+ exclusions .add ("toll" );
385+ } else {
386+ exclusions .remove ("toll" );
387+ }
388+ return this ;
389+ }
390+
391+ /**
392+ * Exclude ferries. Available in mapbox/driving and
393+ * mapbox/driving-traffic profiles.
394+ * @param exclude indicates whether ferries should be excluded
395+ * @return this builder for chaining options together
396+ *
397+ * @since 7.3.0
398+ */
399+ public Builder excludeFerries (Boolean exclude ) {
400+ if (exclude != null && exclude ) {
401+ exclusions .add ("ferry" );
402+ } else {
403+ exclusions .remove ("ferry" );
404+ }
405+ return this ;
406+ }
407+
408+ /**
409+ * Exclude unpaved roads. Available in mapbox/driving and
410+ * mapbox/driving-traffic profiles.
411+ * @param exclude indicates whether unpaved roads should be excluded
412+ * @return this builder for chaining options together
413+ *
414+ * @since 7.3.0
415+ */
416+ public Builder excludeUnpavedRoads (Boolean exclude ) {
417+ if (exclude != null && exclude ) {
418+ exclusions .add ("unpaved" );
419+ } else {
420+ exclusions .remove ("unpaved" );
421+ }
422+ return this ;
423+ }
424+
425+ /**
426+ * Exclude cash only toll roads. Available in mapbox/driving and
427+ * mapbox/driving-traffic profiles.
428+ * @param exclude indicates whether cash only toll roads should be excluded
429+ * @return this builder for chaining options together
430+ *
431+ * @since 7.3.0
432+ */
433+ public Builder excludeCashOnlyTollRoads (Boolean exclude ) {
434+ if (exclude != null && exclude ) {
435+ exclusions .add ("cash_only_tolls" );
436+ } else {
437+ exclusions .remove ("cash_only_tolls" );
438+ }
439+ return this ;
440+ }
441+
442+ /**
443+ * The departure time from the given coordinates.
444+ * <a href="https://docs.mapbox.com/api/navigation/isochrone/">One of three formats.</a>.
445+ * If not provided then 'depart at' is considered to be the present time in the local
446+ * timezone of the coordinates. The isochrone contours will reflect traffic
447+ * conditions at the time provided.
448+ *
449+ * @param depart the departure date/time
450+ * @return this builder for chaining options together
451+ *
452+ * @since 7.3.0
453+ */
454+ public abstract Builder departAt (@ NonNull String depart );
455+
303456 /**
304457 * @return this builder for chaining options together
305458 * @since 4.6.0
@@ -314,6 +467,8 @@ public Builder addContoursColors(@Nullable String... contoursColors) {
314467 */
315468 public MapboxIsochrone build () {
316469
470+ exclusions (TextUtils .join ("," , exclusions .toArray ()));
471+
317472 if (contoursMinutes != null ) {
318473 if (contoursMinutes .length < 1 ) {
319474 throw new ServicesException ("A query with at least one specified "
@@ -331,6 +486,23 @@ public MapboxIsochrone build() {
331486 contoursMinutes (TextUtils .join ("," , contoursMinutes ));
332487 }
333488
489+ if (contoursMeters != null ) {
490+ if (contoursMeters .length < 1 ) {
491+ throw new ServicesException ("A query with at least one specified "
492+ + "meter value is required." );
493+ }
494+
495+ if (contoursMeters .length >= 2 ) {
496+ for (int x = 0 ; x < contoursMeters .length - 1 ; x ++) {
497+ if (contoursMeters [x ] > contoursMeters [x + 1 ]) {
498+ throw new ServicesException ("The meters must be listed"
499+ + " in order from the lowest number to the highest number." );
500+ }
501+ }
502+ contoursMeters (TextUtils .join ("," , contoursMeters ));
503+ }
504+ }
505+
334506 if (contoursColors != null ) {
335507 contoursColors (TextUtils .join ("," , contoursColors ));
336508 }
@@ -342,6 +514,17 @@ public MapboxIsochrone build() {
342514 + "must match number of minute elements provided." );
343515 }
344516
517+ if (contoursColors != null
518+ && contoursMeters != null
519+ && contoursColors .length != contoursMeters .length ) {
520+ throw new ServicesException ("Number of color elements "
521+ + "must match number of meter elements provided." );
522+ }
523+
524+ if (contoursMinutes != null && contoursMeters != null ) {
525+ throw new ServicesException ("Cannot specify both contoursMinutes and contoursMeters." );
526+ }
527+
345528 MapboxIsochrone isochrone = autoBuild ();
346529
347530 if (!MapboxUtils .isAccessTokenValid (isochrone .accessToken ())) {
@@ -359,9 +542,10 @@ public MapboxIsochrone build() {
359542 + " walking, or driving) is required." );
360543 }
361544
362- if (TextUtils .isEmpty (isochrone .contoursMinutes ())) {
545+ if (TextUtils .isEmpty (isochrone .contoursMinutes ())
546+ && TextUtils .isEmpty (isochrone .contoursMeters ())) {
363547 throw new ServicesException ("A query with at least one specified minute amount"
364- + " is required." );
548+ + " or meter value is required." );
365549 }
366550
367551 if (isochrone .contoursColors () != null ) {
0 commit comments