Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,15 @@ tilequery-fixtures:
curl "https://api.mapbox.com/v4/mapbox.mapbox-streets-v7/tilequery/-122.42901,37.806332.json?access_token=$(MAPBOX_ACCESS_TOKEN)&" \
-o services-tilequery/src/test/resources/tilequery-all-params.json

isochrone-fixtures:

# Fetch isochrone driving information with polygon information. The query Point is in downtown Los Angeles.
curl "https://api.mapbox.com/isochrone/v1/mapbox/driving/-118.22258,33.99038?contours_minutes=5,30,55&contours_colors=6706ce,04e813,4286f4&polygons=true&access_token=$(MAPBOX_ACCESS_TOKEN)&" \
-o services-isochrone/src/test/resources/isochroneWithPolygons.json

# Fetch isochrone driving information without polygon information. The query Point is in downtown Los Angeles.
curl "https://api.mapbox.com/isochrone/v1/mapbox/driving/-118.22258,33.99038?contours_minutes=5,30,55&contours_colors=6706ce,04e813,4286f4&polygons=false&access_token=$(MAPBOX_ACCESS_TOKEN)&" \
-o services-isochrone/src/test/resources/isochroneNoPolygons.json

clean:
./gradlew clean
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def TESTABLE_MODULES = ["services",
"services-staticmap",
"services-tilequery",
"services-turf",
"services-directions-refresh"]
"services-directions-refresh",
"services-isochrone"]

def RELEASE_MODULES = ["services",
"services-core",
Expand Down
1 change: 1 addition & 0 deletions samples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
implementation project(":services-speech")
implementation project(":services-tilequery")
implementation project(":services-directions-refresh")
implementation project(":services-isochrone")
}

buildConfig {
Expand Down
74 changes: 74 additions & 0 deletions samples/src/main/java/com/mapbox/samples/BasicIsochrone.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.mapbox.samples;

import com.mapbox.api.isochrone.IsochroneCriteria;
import com.mapbox.api.isochrone.MapboxIsochrone;
import com.mapbox.geojson.Feature;
import com.mapbox.geojson.FeatureCollection;
import com.mapbox.geojson.Point;
import com.mapbox.sample.BuildConfig;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class BasicIsochrone {

public static void main(String[] args) {
getStandardIsochroneCallBuilder(true).enqueueCall(new Callback<FeatureCollection>() {
@Override
public void onResponse(Call<FeatureCollection> call, Response<FeatureCollection> response) {
System.out.println("Total results: " + response.body().features().size());
for (Feature feature : response.body().features()) {
if (feature.properties().has("color")) {
System.out.println("" + feature.properties().get("color").getAsString());
} else {
System.out.println("Unnamed feature.");
}
}

makeNoPolygonCall();
}

@Override
public void onFailure(Call<FeatureCollection> call, Throwable t) {
System.out.println("Request failed: " + t.getMessage());
t.printStackTrace();
}
});
}

private static void makeNoPolygonCall() {
getStandardIsochroneCallBuilder(false).enqueueCall(new Callback<FeatureCollection>() {
@Override
public void onResponse(Call<FeatureCollection> call, Response<FeatureCollection> response) {
System.out.println("Total results for no polygon isochrone call: " + response.body().features().size());
for (Feature feature : response.body().features()) {
if (feature.properties().has("color")) {
System.out.println("" + feature.properties().get("color").getAsString());
} else {
System.out.println("Unnamed feature.");
}
}
}

@Override
public void onFailure(Call<FeatureCollection> call, Throwable t) {
System.out.println("Request failed: " + t.getMessage());
t.printStackTrace();
}
});
}

private static MapboxIsochrone getStandardIsochroneCallBuilder(boolean includePolygons) {
return MapboxIsochrone.builder()
.accessToken(BuildConfig.MAPBOX_ACCESS_TOKEN)
.profile(IsochroneCriteria.PROFILE_WALKING)
.addContoursMinutes(14, 35, 53)
.polygons(includePolygons)
.generalize(2f)
.denoise(.4f)
.addContoursColors("80f442", "403bd3", "bc404c")
.coordinates(Point.fromLngLat(-122.42901, 37.806332))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static String formatDistributions(List<Integer[]> distributions) {
/**
* Converts String array with approaches values
* to a string ready for API consumption.
* An approache could be unrestricted, curb or null.
* An approach could be unrestricted, curb or null.
*
* @param approaches a string representing approaches to each coordinate.
* @return a formatted string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

import retrofit2.Response;

/**
* @since 4.4.0
*/
class DirectionsResponseFactory {

private final MapboxDirections mapboxDirections;
Expand Down
1 change: 1 addition & 0 deletions services-isochrone/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
17 changes: 17 additions & 0 deletions services-isochrone/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apply plugin: 'java-library'

dependencies {
api project(":services-core")
api project(":services-geojson")

// Annotations
compileOnly dependenciesList.supportAnnotation

// AutoValue
compileOnly dependenciesList.autoValue
compileOnly dependenciesList.autoValueGson

// Test Dependencies
testImplementation dependenciesList.okhttp3Mockwebserver
testImplementation project(path: ':services-core', configuration: 'testOutput')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.mapbox.api.isochrone;

import android.support.annotation.StringDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* Constants that should be used when using the Isochrone API.
*
* @since 4.6.0
*/
public class IsochroneCriteria {


/**
* For walking routing. This profile shows routes that are short and safe for cyclist, avoiding
* highways and preferring streets with bike lanes.
*
* @since 4.6.0
*/
public static final String PROFILE_WALKING = "walking";

/**
* For car routing. This profile shows the fastest routes by
* preferring high-speed roads like highways.
*
* @since 4.6.0
*/
public static final String PROFILE_DRIVING = "driving";

/**
* For bicycle routing. This profile shows routes that are short and safe for cyclist, avoiding
* highways and preferring streets with bike lanes.
*
* @since 4.6.0
*/
public static final String PROFILE_CYCLING = "cycling";

/**
* Queries for a specific geometry type selector.
*
* @since 4.6.0
*/
@Retention(RetentionPolicy.SOURCE)
@StringDef( {
PROFILE_WALKING,
PROFILE_DRIVING,
PROFILE_CYCLING
})
public @interface IsochroneProfile {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.mapbox.api.isochrone;

import com.mapbox.geojson.FeatureCollection;
import com.mapbox.geojson.Point;

import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
import retrofit2.http.Query;

/**
* Interface that defines the Isochrone API service.
*
* @since 4.6.0
*/
public interface IsochroneService {

/**
* Constructs the HTTP request for the specified parameters.
*
* @param profile A Mapbox Directions routing profile ID. Options are
* {@link IsochroneCriteria#PROFILE_DRIVING} for travel times by car,
* {@link IsochroneCriteria#PROFILE_WALKING} for pedestrian and hiking travel
* times,and {@link IsochroneCriteria#PROFILE_CYCLING} for travel times by bicycle.
* @param coordinates A {@link Point} object which represents a {longitude,latitude} coordinate
* pair around which to center the isochrone lines.
* @param contoursMinutes A single String which has a comma-separated time in minutes to use for
* each isochrone contour.
* @param accessToken A valid Mapbox access token.
* @param contoursColors The colors to use for each isochrone contour, specified as hex values
* without a leading # (for example, ff0000 for red). If this parameter is
* used, there must be the same number of colors as there are entries in
* contours_minutes. If no colors are specified, the Isochrone API will
* assign a default rainbow color scheme to the output.
* @param polygons Specify whether to return the contours as GeoJSON polygons (true) or
* linestrings (false, default). When polygons=true, any contour that
* forms a ring is returned as a polygon.
* @param denoise A floating point value from 0.0 to 1.0 that can be used to remove
* smaller contours. The default is 1.0. A value of 1.0 will only
* return the largest contour for a given time value. A value of 0.5
* drops any contours that are less than half the area of the largest
* contour in the set of contours for that same time value.
* @param generalize A positive floating point value in meters used as the tolerance for
* Douglas-Peucker generalization. There is no upper bound. If no value is
* specified in the request, the Isochrone API will choose the most
* optimized generalization to use for the request. Note that the
* generalization of contours can lead to self-intersections, as well
* as intersections of adjacent contours.
*
* @return a {@link FeatureCollection} in a Call wrapper
* @since 4.6.0
*/
@GET("/isochrone/v1/{profile}/{coordinates}")
Call<FeatureCollection> getCall(
@Path("profile") String profile,
@Path("coordinates") String coordinates,
@Query("contours_minutes") String contoursMinutes,
@Query("access_token") String accessToken,
@Query("contours_colors") String contoursColors,
@Query("polygons") Boolean polygons,
@Query("denoise") Float denoise,
@Query("generalize") Float generalize);
}
Loading