Skip to content

Commit 666c1ab

Browse files
author
Cameron Mace
committed
geojson module setup
1 parent 2c7cdab commit 666c1ab

58 files changed

Lines changed: 4325 additions & 35 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.idea/gradle.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2-
31
buildscript {
42

53
repositories {
@@ -8,14 +6,12 @@ buildscript {
86
}
97
dependencies {
108
classpath 'com.android.tools.build:gradle:3.0.0-beta5'
11-
12-
// NOTE: Do not place your application dependencies here; they belong
13-
// in the individual module build.gradle files
149
}
1510
}
1611

1712
allprojects {
1813
apply from: "${rootDir}/gradle/dependencies.gradle"
14+
apply from: "${rootDir}/gradle/codeQuality.gradle"
1915
repositories {
2016
google()
2117
jcenter()

gradle/codeQuality.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apply plugin: 'checkstyle'
2+
3+
checkstyle {
4+
toolVersion = pluginVersion.checkstyle
5+
showViolations = true
6+
}

gradle/dependencies.gradle

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
ext {
22

33
version = [
4-
autoValue: '1.5',
5-
autoValueGson: '0.5.0',
6-
junit: '4.12'
4+
autoValue : '1.5',
5+
autoValueGson : '0.5.0',
6+
junit : '4.12',
7+
supportLibVersion: '26.0.2',
8+
gson : '2.8.0'
79
]
810

9-
dependenciesList = [
10-
autoValue: "com.google.auto.value:auto-value:${version.autoValue}",
11-
autoValueGson: "com.ryanharter.auto.value:auto-value-gson:${version.autoValueGson}",
12-
junit: "junit:junit:${version.junit}",
11+
pluginVersion = [
12+
checkstyle: '8.2'
1313
]
1414

15+
dependenciesList = [
16+
autoValue : "com.google.auto.value:auto-value:${version.autoValue}",
17+
autoValueGson : "com.ryanharter.auto.value:auto-value-gson:${version.autoValueGson}",
18+
junit : "junit:junit:${version.junit}",
19+
supportAnnotation: "com.android.support:support-annotations:${version.supportLibVersion}",
20+
gson : "com.google.code.gson:gson:${version.gson}"
21+
]
1522

16-
17-
18-
19-
20-
21-
22-
23-
24-
25-
26-
}
23+
pluginDependencies = [
24+
checkstyle: "com.puppycrawl.tools:checkstyle:${pluginVersion.checkstyle}"
25+
]
26+
}

services-directions/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apply plugin: 'java-library'
2+
3+
dependencies {
4+
implementation fileTree(dir: 'libs', include: ['*.jar'])
5+
}
6+
7+
sourceCompatibility = "1.7"
8+
targetCompatibility = "1.7"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.mapbox.services_directions;
2+
3+
public class MapboxDirections {
4+
}

services-geojson/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ targetCompatibility = "1.7"
55

66
dependencies {
77

8+
compile project(":services")
9+
10+
// Annotations
11+
compileOnly dependenciesList.supportAnnotation
12+
813
// AutoValue
914
compileOnly dependenciesList.autoValue
1015
compileOnly dependenciesList.autoValueGson
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
package com.mapbox.geojson;
2+
3+
import android.support.annotation.FloatRange;
4+
import android.support.annotation.NonNull;
5+
import com.google.auto.value.AutoValue;
6+
import com.google.gson.GsonBuilder;
7+
import com.mapbox.geojson.gson.MapboxAdapterFactory;
8+
import com.mapbox.geojson.gson.PointSerializer;
9+
10+
import java.io.Serializable;
11+
12+
import static com.mapbox.services.Constants.MAX_LATITUDE;
13+
import static com.mapbox.services.Constants.MAX_LONGITUDE;
14+
import static com.mapbox.services.Constants.MIN_LATITUDE;
15+
import static com.mapbox.services.Constants.MIN_LONGITUDE;
16+
17+
/**
18+
* A GeoJson object MAY have a member named "bbox" to include information on the coordinate range
19+
* for its Geometries, Features, or FeatureCollections.
20+
* <p>
21+
* This class simplifies the build process for creating a bounding box and working with them when
22+
* deserialized. specific parameter naming helps define which coordinates belong where when a
23+
* bounding box instance is being created. Note that since GeoJson objects only have the option of
24+
* including a bounding box JSON element, the {@code bbox} value returned by a GeoJson object might
25+
* be null.
26+
* <p>
27+
* At a minimum, a bounding box will have two {@link Point}s or four coordinates which define the
28+
* box. A 3rd dimensional bounding box can be produced if elevation or altitude is defined.
29+
*
30+
* @since 3.0.0
31+
*/
32+
@AutoValue
33+
public abstract class BoundingBox implements Serializable {
34+
35+
/**
36+
* Define a new instance of this class by passing in two {@link Point}s, representing both the
37+
* southwest and northwest corners of the bounding box.
38+
*
39+
* @param southwest represents the bottom left corner of the bounding box when the camera is
40+
* pointing due north
41+
* @param northeast represents the top right corner of the bounding box when the camera is
42+
* pointing due north
43+
* @return a new instance of this class defined by the provided points
44+
* @since 3.0.0
45+
*/
46+
public static BoundingBox fromPoints(@NonNull Point southwest, @NonNull Point northeast) {
47+
return new AutoValue_BoundingBox(southwest, northeast);
48+
}
49+
50+
/**
51+
* Define a new instance of this class by passing in four coordinates in the same order they would
52+
* appear in the serialized GeoJson form. Limits are placed on the minimum and maximum coordinate
53+
* values which can exist and comply with the GeoJson spec.
54+
*
55+
* @param west the left side of the bounding box when the map is facing due north
56+
* @param south the bottom side of the bounding box when the map is facing due north
57+
* @param east the right side of the bounding box when the map is facing due north
58+
* @param north the top side of the bounding box when the map is facing due north
59+
* @return a new instance of this class defined by the provided coordinates
60+
* @since 3.0.0
61+
*/
62+
public static BoundingBox fromCoordinates(
63+
@FloatRange(from = MIN_LONGITUDE, to = MAX_LONGITUDE) double west,
64+
@FloatRange(from = MIN_LATITUDE, to = MAX_LATITUDE) double south,
65+
@FloatRange(from = MIN_LONGITUDE, to = MAX_LONGITUDE) double east,
66+
@FloatRange(from = MIN_LATITUDE, to = MAX_LATITUDE) double north) {
67+
return new AutoValue_BoundingBox(Point.fromLngLat(west, south), Point.fromLngLat(east, north));
68+
}
69+
70+
/**
71+
* Define a new instance of this class by passing in four coordinates in the same order they would
72+
* appear in the serialized GeoJson form. Limits are placed on the minimum and maximum coordinate
73+
* values which can exist and comply with the GeoJson spec.
74+
*
75+
* @param west the left side of the bounding box when the map is facing due north
76+
* @param south the bottom side of the bounding box when the map is facing due north
77+
* @param southwestAltitude the southwest corner altitude or elevation when the map is facing due
78+
* north
79+
* @param east the right side of the bounding box when the map is facing due north
80+
* @param north the top side of the bounding box when the map is facing due north
81+
* @param northEastAltitude the northeast corner altitude or elevation when the map is facing due
82+
* north
83+
* @return a new instance of this class defined by the provided coordinates
84+
* @since 3.0.0
85+
*/
86+
public static BoundingBox fromCoordinates(
87+
@FloatRange(from = MIN_LONGITUDE, to = MAX_LONGITUDE) double west,
88+
@FloatRange(from = MIN_LATITUDE, to = MAX_LATITUDE) double south,
89+
double southwestAltitude,
90+
@FloatRange(from = MIN_LONGITUDE, to = MAX_LONGITUDE) double east,
91+
@FloatRange(from = MIN_LATITUDE, to = MAX_LATITUDE) double north,
92+
double northEastAltitude) {
93+
return new AutoValue_BoundingBox(
94+
Point.fromLngLat(west, south, southwestAltitude),
95+
Point.fromLngLat(east, north, northEastAltitude));
96+
}
97+
98+
/**
99+
* Provides the {@link Point} which represents the southwest corner of this bounding box when the
100+
* map is facing due north.
101+
*
102+
* @return a {@link Point} which defines this bounding boxes southwest corner
103+
* @since 3.0.0
104+
*/
105+
@NonNull
106+
public abstract Point southwest();
107+
108+
/**
109+
* Provides the {@link Point} which represents the northeast corner of this bounding box when the
110+
* map is facing due north.
111+
*
112+
* @return a {@link Point} which defines this bounding boxes northeast corner
113+
* @since 3.0.0
114+
*/
115+
@NonNull
116+
public abstract Point northeast();
117+
118+
/**
119+
* Convenience method for getting the bounding box most westerly point (longitude) as a double
120+
* coordinate.
121+
*
122+
* @return the most westerly coordinate inside this bounding box
123+
* @since 3.0.0
124+
*/
125+
public double west() {
126+
return southwest().longitude();
127+
}
128+
129+
/**
130+
* Convenience method for getting the bounding box most southerly point (latitude) as a double
131+
* coordinate.
132+
*
133+
* @return the most southerly coordinate inside this bounding box
134+
* @since 3.0.0
135+
*/
136+
public double south() {
137+
return southwest().latitude();
138+
}
139+
140+
/**
141+
* Convenience method for getting the bounding box most easterly point (longitude) as a double
142+
* coordinate.
143+
*
144+
* @return the most easterly coordinate inside this bounding box
145+
* @since 3.0.0
146+
*/
147+
public double east() {
148+
return northeast().longitude();
149+
}
150+
151+
/**
152+
* Convenience method for getting the bounding box most westerly point (longitude) as a double
153+
* coordinate.
154+
*
155+
* @return the most westerly coordinate inside this bounding box
156+
* @since 3.0.0
157+
*/
158+
public double north() {
159+
return northeast().latitude();
160+
}
161+
162+
/**
163+
* This takes the currently defined values found inside this instance and converts it to a GeoJson
164+
* string.
165+
*
166+
* @return a JSON string which represents this Bounding box
167+
* @since 3.0.0
168+
*/
169+
public String toJson() {
170+
GsonBuilder gson = new GsonBuilder();
171+
gson.registerTypeAdapterFactory(MapboxAdapterFactory.create());
172+
gson.registerTypeAdapter(Point.class, new PointSerializer());
173+
return gson.create().toJson(this);
174+
}
175+
}

0 commit comments

Comments
 (0)