Skip to content

Commit 9fa87fb

Browse files
authored
Support for Tilequery API (#860)
* generate fixture for tilequery api * first stab at a client for tilequery api * adds sample cli with radius query * add javadoc * add sanity tests * No need to have TypeAdapterFactory GeoJsonAdapterFactory could be used instead Added tests
1 parent 56470d3 commit 9fa87fb

16 files changed

Lines changed: 831 additions & 29 deletions

File tree

Makefile

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,19 @@ directions-fixtures:
118118
curl "https://api.mapbox.com/directions/v5/mapbox/driving/-122.03067988107114,37.331808179989494;-122.03178702099605,37.3302383113533?voice_units=imperial&roundabout_exits=true&geometries=polyline&overview=full&steps=true&voice_instructions=true&banner_instructions=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
119119
-o services-directions/src/test/resources/directions_v5_banner_text.json
120120

121-
# Directions: route with maxspeed
121+
# Directions: route with maxspeed
122122
curl "https://api.mapbox.com/directions/v5/mapbox/driving-traffic/9.950072,52.150015;7.569915,52.916751?alternatives=true&geometries=polyline6&overview=full&steps=true&bearings=%3B&continue_straight=true&annotations=maxspeed&language=en&access_token=$(MAPBOX_ACCESS_TOKEN)" \
123123
-o services-directions/src/test/resources/directions_v5_max_speed_annotation.json
124124

125-
# Directions: route with sub (and lane data) in BannerInstructions
125+
# Directions: route with sub (and lane data) in BannerInstructions
126126
curl "https://api.mapbox.com/directions/v5/mapbox/driving/-122.403561,37.777689;-122.405786,37.770369.json?access_token=$(MAPBOX_ACCESS_TOKEN)&steps=true&geometries=polyline&banner_instructions=true" \
127127
-o services-directions/src/test/resources/directions_v5_banner_instructions.json
128128

129-
# Directions: route with approaches in request
129+
# Directions: route with approaches in request
130130
curl "https://api.mapbox.com/directions/v5/mapbox/driving/13.4301,52.5109;13.432507621760521,52.501725088556014?approaches=unrestricted;curb&access_token=$(MAPBOX_ACCESS_TOKEN)" \
131131
-o services-directions/src/test/resources/directions_v5_approaches.json
132132

133-
# Directions: includes waypoint_names
133+
# Directions: includes waypoint_names
134134
curl "https://api.mapbox.com/directions/v5/mapbox/cycling/-122.42,37.78;-77.03,38.91?steps=true&voice_instructions=true&banner_instructions=true&voice_units=imperial&waypoint_names=Home;Work&access_token=$(MAPBOX_ACCESS_TOKEN)" \
135135
-o services-directions/src/test/resources/directions_v5_waypoint_names.json
136136

@@ -150,11 +150,11 @@ mapmatching-fixtures:
150150
curl "https://api.mapbox.com/matching/v5/mapbox/driving/2.344003915786743,48.85805170891599;2.346750497817993,48.85727523615161;2.348681688308716,48.85936462637049;2.349550724029541,48.86084691113991;2.349550724029541,48.8608892614883;2.349625825881958,48.86102337068847;2.34982967376709,48.86125629633996?steps=true&tidy=true&waypoints=0;6&waypoint_names=Home;Work&banner_instructions=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
151151
-o services-matching/src/test/resources/mapmatching_v5_waypoint_names.json
152152

153-
# MapMatching with valid voiceLanguage
153+
# MapMatching with valid voiceLanguage
154154
curl "https://api.mapbox.com/matching/v5/mapbox/driving/$(MAP_MATCHING_COORDINATES)?steps=true&overview=full&geometries=polyline6&roundabout_exits=true&voice_instructions=true&language=en&access_token=$(MAPBOX_ACCESS_TOKEN)" \
155155
-o services-matching/src/test/resources/map_matching_v5_voice_language.json
156156

157-
# MapMatching with invalid voiceLanguage
157+
# MapMatching with invalid voiceLanguage
158158
curl "https://api.mapbox.com/matching/v5/mapbox/driving/$(MAP_MATCHING_COORDINATES)?steps=true&overview=full&geometries=polyline6&roundabout_exits=true&voice_instructions=true&language=he&access_token=$(MAPBOX_ACCESS_TOKEN)" \
159159
-o services-matching/src/test/resources/map_matching_v5_invalid_voice_language.json
160160

@@ -169,6 +169,14 @@ optimization-fixtures:
169169
curl "https://api.mapbox.com/optimized-trips/v1/mapbox/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219;13.418555,52.523215?roundtrip=true&distributions=3,1&access_token=$(MAPBOX_ACCESS_TOKEN)" \
170170
-o services-optimization/src/test/resources/optimized_trip_distributions.json
171171

172+
tilequery-fixtures:
173+
# Fetch features at Fort Mason, CA
174+
curl "https://api.mapbox.com/v4/mapbox.mapbox-streets-v7/tilequery/-122.42901,37.806332.json?access_token=$(MAPBOX_ACCESS_TOKEN)" \
175+
-o services-tilequery/src/test/resources/tilequery.json
176+
177+
# Fetch features at Fort Mason, CA
178+
curl "https://api.mapbox.com/v4/mapbox.mapbox-streets-v7/tilequery/-122.42901,37.806332.json?access_token=$(MAPBOX_ACCESS_TOKEN)&" \
179+
-o services-tilequery/src/test/resources/tilequery-all-params.json
180+
172181
clean:
173182
./gradlew clean
174-

samples/build.gradle

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ sourceCompatibility = JavaVersion.VERSION_1_8
55
targetCompatibility = JavaVersion.VERSION_1_8
66

77
dependencies {
8-
implementation project(":services-geocoding")
9-
implementation project(":services-optimization")
10-
implementation project(":services-geojson")
11-
implementation project(":services-matching")
12-
implementation project(":services-staticmap")
13-
implementation project(":services-speech")
8+
implementation project(":services-geocoding")
9+
implementation project(":services-optimization")
10+
implementation project(":services-geojson")
11+
implementation project(":services-matching")
12+
implementation project(":services-staticmap")
13+
implementation project(":services-speech")
14+
implementation project(":services-tilequery")
1415
}
1516

1617
buildConfig {
17-
packageName = 'com.mapbox.sample'
18-
buildConfigField 'String', 'MAPBOX_ACCESS_TOKEN', System.getenv("MAPBOX_ACCESS_TOKEN")
18+
packageName = 'com.mapbox.sample'
19+
buildConfigField 'String', 'MAPBOX_ACCESS_TOKEN', System.getenv("MAPBOX_ACCESS_TOKEN")
1920
}
2021

2122
sonarqube {
22-
skipProject = true
23-
}
23+
skipProject = true
24+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.mapbox.samples;
2+
3+
import com.mapbox.api.tilequery.MapboxTilequery;
4+
import com.mapbox.geojson.Feature;
5+
import com.mapbox.geojson.FeatureCollection;
6+
import com.mapbox.geojson.Point;
7+
import com.mapbox.sample.BuildConfig;
8+
9+
import retrofit2.Call;
10+
import retrofit2.Callback;
11+
import retrofit2.Response;
12+
13+
public class BasicTilequery {
14+
15+
public static void main(String[] args) {
16+
MapboxTilequery tilequery = MapboxTilequery.builder()
17+
.accessToken(BuildConfig.MAPBOX_ACCESS_TOKEN)
18+
.mapIds("mapbox.mapbox-streets-v7")
19+
.query(Point.fromLngLat(-122.42901, 37.806332))
20+
.radius(500)
21+
.limit(2)
22+
.geometry("point")
23+
.dedupe(true)
24+
.layers("poi_label,building")
25+
.build();
26+
27+
tilequery.enqueueCall(new Callback<FeatureCollection>() {
28+
@Override
29+
public void onResponse(Call<FeatureCollection> call, Response<FeatureCollection> response) {
30+
System.out.println("Total results: " + response.body().features().size());
31+
for (Feature feature : response.body().features()) {
32+
if (feature.properties().has("name")) {
33+
System.out.println("" + feature.properties().get("name").getAsString());
34+
} else {
35+
System.out.println("Unnamed feature.");
36+
}
37+
}
38+
}
39+
40+
@Override
41+
public void onFailure(Call<FeatureCollection> call, Throwable t) {
42+
System.out.println("Request failed: " + t.getMessage());
43+
t.printStackTrace();
44+
}
45+
});
46+
}
47+
}

services-tilequery/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

services-tilequery/build.gradle

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apply plugin: 'java-library'
2+
3+
dependencies {
4+
api project(":services-core")
5+
api project(":services-geojson")
6+
7+
// Annotations
8+
compileOnly dependenciesList.supportAnnotation
9+
10+
// AutoValue
11+
compileOnly dependenciesList.autoValue
12+
compileOnly dependenciesList.autoValueGson
13+
14+
// Test Dependencies
15+
testImplementation dependenciesList.okhttp3Mockwebserver
16+
testImplementation project(path: ':services-core', configuration: 'testOutput')
17+
}
18+
19+
apply from: "${rootDir}/gradle/checkstyle.gradle"
20+
apply from: "${rootDir}/gradle/jacoco.gradle"

0 commit comments

Comments
 (0)