Skip to content

Commit afe9e88

Browse files
author
Cameron Mace
authored
Adds missing docs and cleans things up in static map module (#690)
* Adds missing docs and cleans things up in static map module * made Osana’s suggested change
1 parent c14dbeb commit afe9e88

8 files changed

Lines changed: 207 additions & 48 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.mapbox.core.utils;
2+
3+
import java.awt.Color;
4+
5+
/**
6+
* Utils class for assisting with color transformations and other operations being done on colors.
7+
*
8+
* @since 3.0.0
9+
*/
10+
public final class ColorUtils {
11+
12+
private ColorUtils() {
13+
// No Instance.
14+
}
15+
16+
/**
17+
* Converts a {@link Color} object to a hex string that can then be used in a URL when making API
18+
* request. Note that this does <b>Not</b> add the hex key before the string.
19+
*
20+
* @param color the color which needs to be converted
21+
* @return the hex color value as a string
22+
* @since 3.0.0
23+
*/
24+
public static String toHexString(Color color) {
25+
String hexColor
26+
= String.format("%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue());
27+
28+
if (hexColor.length() < 6) {
29+
hexColor = "000000".substring(0, 6 - hexColor.length()) + hexColor;
30+
}
31+
return hexColor;
32+
}
33+
}

services-staticmap/src/main/java/com/mapbox/api/staticmap/v1/MapboxStaticMap.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,22 @@
44
import android.support.annotation.IntRange;
55
import android.support.annotation.NonNull;
66
import android.support.annotation.Nullable;
7-
87
import com.google.auto.value.AutoValue;
8+
import com.mapbox.api.staticmap.v1.models.StaticMarkerAnnotation;
99
import com.mapbox.api.staticmap.v1.models.StaticPolylineAnnotation;
1010
import com.mapbox.core.constants.Constants;
11-
import com.mapbox.api.staticmap.v1.models.StaticMarkerAnnotation;
12-
import com.mapbox.geojson.GeoJson;
13-
import com.mapbox.geojson.Point;
11+
import com.mapbox.core.exceptions.ServicesException;
1412
import com.mapbox.core.utils.MapboxUtils;
1513
import com.mapbox.core.utils.TextUtils;
16-
import com.mapbox.core.exceptions.ServicesException;
14+
import com.mapbox.geojson.GeoJson;
15+
import com.mapbox.geojson.Point;
16+
import okhttp3.HttpUrl;
1717

1818
import java.util.ArrayList;
1919
import java.util.Arrays;
2020
import java.util.List;
2121
import java.util.Locale;
2222

23-
import okhttp3.HttpUrl;
24-
2523
/**
2624
* Static maps are standalone images that can be displayed in your mobile app without the aid of a
2725
* mapping library like the Mapbox Android SDK. They look like an embedded map without interactivity
@@ -37,6 +35,9 @@
3735
@AutoValue
3836
public abstract class MapboxStaticMap {
3937

38+
private static final String BEFORE_LAYER = "before_layer";
39+
private static final String CAMERA_AUTO = "auto";
40+
4041
@Nullable
4142
abstract String accessToken();
4243

@@ -125,11 +126,11 @@ public HttpUrl url() {
125126
urlBuilder.addPathSegment(TextUtils.join(",", annotations.toArray()));
126127
}
127128

128-
urlBuilder.addPathSegment(cameraAuto() ? StaticMapCriteria.CAMERA_AUTO
129+
urlBuilder.addPathSegment(cameraAuto() ? CAMERA_AUTO
129130
: generateLocationPathSegment());
130131

131132
if (beforeLayer() != null) {
132-
urlBuilder.addQueryParameter(StaticMapCriteria.BEFORE_LAYER, beforeLayer());
133+
urlBuilder.addQueryParameter(BEFORE_LAYER, beforeLayer());
133134
}
134135
if (!attribution()) {
135136
urlBuilder.addQueryParameter("attribution", "false");
@@ -176,7 +177,7 @@ public static Builder builder() {
176177
.styleId(StaticMapCriteria.STREET_STYLE)
177178
.baseUrl(Constants.BASE_API_URL)
178179
.user(Constants.MAPBOX_USER)
179-
.cameraPoint(Point.fromLngLat(0d,0d))
180+
.cameraPoint(Point.fromLngLat(0d, 0d))
180181
.cameraAuto(false)
181182
.attribution(true)
182183
.width(250)
@@ -398,6 +399,13 @@ public abstract Builder staticPolylineAnnotations(
398399

399400
abstract MapboxStaticMap autoBuild();
400401

402+
/**
403+
* This uses the provided parameters set using the {@link Builder} and creates a new
404+
* {@link MapboxStaticMap} object.
405+
*
406+
* @return a new instance of {@link MapboxStaticMap}
407+
* @since 2.1.0
408+
*/
401409
public MapboxStaticMap build() {
402410
MapboxStaticMap staticMap = autoBuild();
403411

@@ -406,8 +414,7 @@ public MapboxStaticMap build() {
406414
+ " token.");
407415
}
408416

409-
410-
if (staticMap.styleId() == null || staticMap.styleId().isEmpty()) {
417+
if (staticMap.styleId().isEmpty()) {
411418
throw new ServicesException("You need to set a map style.");
412419
}
413420
return staticMap;

services-staticmap/src/main/java/com/mapbox/api/staticmap/v1/StaticMapCriteria.java

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,121 @@
66

77
import java.lang.annotation.Retention;
88

9-
9+
/**
10+
* Constant values related to the Static Map API can be found in this class.
11+
*
12+
* @since 3.0.0
13+
*/
1014
public final class StaticMapCriteria {
1115

16+
/**
17+
* The Static Maps marker shape and size will be small.
18+
*
19+
* @since 3.0.0
20+
*/
1221
public static final String SMALL_PIN = "pin-s";
1322

23+
/**
24+
* The Static Maps marker shape and size will be medium.
25+
*
26+
* @since 3.0.0
27+
*/
1428
public static final String MEDIUM_PIN = "pin-m";
1529

30+
/**
31+
* The Static Maps marker shape and size will be large.
32+
*
33+
* @since 3.0.0
34+
*/
1635
public static final String LARGE_PIN = "pin-l";
1736

18-
static final String CAMERA_AUTO = "auto";
19-
20-
static final String BEFORE_LAYER = "before_layer";
21-
37+
/**
38+
* Mapbox Streets is a comprehensive, general-purpose map that emphasizes accurate, legible
39+
* styling of road and transit networks.
40+
*
41+
* @since 3.0.0
42+
*/
2243
public static final String STREET_STYLE = "streets-v10";
44+
45+
/**
46+
* Mapbox Outdoors is a general-purpose map with curated tilesets and specialized styling tailored
47+
* to hiking, biking, and the most adventurous use cases.
48+
*
49+
* @since 3.0.0
50+
*/
2351
public static final String OUTDOORS_STYLE = "outdoors-v10";
52+
53+
54+
/**
55+
* Mapbox Light style's a subtle, full-featured map designed to provide geographic context while
56+
* highlighting the data on your analytics dashboard, data visualization, or data overlay.
57+
*
58+
* @since 3.0.0
59+
*/
2460
public static final String LIGHT_STYLE = "light-v9";
61+
62+
/**
63+
* Mapbox Dark style's a subtle, full-featured map designed to provide geographic context while
64+
* highlighting the data on your analytics dashboard, data visualization, or data overlay.
65+
*
66+
* @since 3.0.0
67+
*/
2568
public static final String DARK_STYLE = "dark-v9";
69+
70+
/**
71+
* Mapbox Satellite is our full global base map that is perfect as a blank canvas or an overlay
72+
* for your own data.
73+
*
74+
* @since 3.0.0
75+
*/
2676
public static final String SATELLITE_STYLE = "satellite-v9";
77+
78+
/**
79+
* Mapbox Satellite Streets combines our Mapbox Satellite with vector data from Mapbox Streets.
80+
* The comprehensive set of road, label, and POI information brings clarity and context to the
81+
* crisp detail in our high-resolution satellite imagery.
82+
*
83+
* @since 3.0.0
84+
*/
2785
public static final String SATELLITE_STREETS_STYLE = "satellite-streets-v10";
2886

87+
/**
88+
* Navigation specific style that shows only the necessary information while a user is driving.
89+
*
90+
* @since 3.0.0
91+
*/
2992
public static final String NAVIGATION_PREVIEW_DAY = "navigation-preview-day-v2";
93+
94+
/**
95+
* Navigation specific style that shows only the necessary information while a user is driving.
96+
*
97+
* @since 3.0.0
98+
*/
3099
public static final String NAVIGATION_PREVIEW_NIGHT = "navigation-preview-night-v2";
100+
101+
/**
102+
* Navigation specific style that shows only the necessary information while a user is driving.
103+
*
104+
* @since 3.0.0
105+
*/
31106
public static final String NAVIGATION_GUIDANCE_DAY = "navigation-guidance-day-v2";
107+
108+
/**
109+
* Navigation specific style that shows only the necessary information while a user is driving.
110+
*
111+
* @since 3.0.0
112+
*/
32113
public static final String NAVIGATION_GUIDANCE_NIGHT = "navigation-guidance-night-v2";
33114

34115
private StaticMapCriteria() {
35-
// Empty private constructor since only static methods are found inside class.
116+
throw new AssertionError("No Instances.");
36117
}
37118

119+
/**
120+
* Retention policy for the pin parameter in the Static Map Marker Annotation API.
121+
*
122+
* @since 3.0.0
123+
*/
38124
@Retention(SOURCE)
39125
@StringDef( {
40126
SMALL_PIN,

services-staticmap/src/main/java/com/mapbox/api/staticmap/v1/models/StaticMarkerAnnotation.java

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package com.mapbox.api.staticmap.v1.models;
22

3+
import static android.support.annotation.RestrictTo.Scope.LIBRARY;
4+
import static com.mapbox.core.utils.ColorUtils.toHexString;
5+
36
import android.support.annotation.Nullable;
7+
import android.support.annotation.RestrictTo;
48
import com.google.auto.value.AutoValue;
59
import com.mapbox.api.staticmap.v1.StaticMapCriteria;
6-
import com.mapbox.geojson.Point;
7-
import com.mapbox.core.utils.TextUtils;
10+
import com.mapbox.api.staticmap.v1.StaticMapCriteria.MarkerCriteria;
811
import com.mapbox.core.exceptions.ServicesException;
12+
import com.mapbox.core.utils.TextUtils;
13+
import com.mapbox.geojson.Point;
914

1015
import java.awt.Color;
1116
import java.util.Locale;
@@ -32,6 +37,13 @@ public static Builder builder() {
3237
.name(StaticMapCriteria.MEDIUM_PIN);
3338
}
3439

40+
/**
41+
* <em>Used Internally</em>
42+
*
43+
* @return a String representing the marker part of the URL
44+
* @since 2.1.0
45+
*/
46+
@RestrictTo(LIBRARY)
3547
public String url() {
3648
String url;
3749
if (iconUrl() != null) {
@@ -86,7 +98,7 @@ public abstract static class Builder {
8698
* @return this builder for chaining options together
8799
* @since 2.1.0
88100
*/
89-
public abstract Builder name(@StaticMapCriteria.MarkerCriteria String name);
101+
public abstract Builder name(@MarkerCriteria String name);
90102

91103
/**
92104
* Marker symbol. Options are an alphanumeric label "a" through "z", "0" through "99", or a
@@ -96,7 +108,6 @@ public abstract static class Builder {
96108
* @return this builder for chaining options together
97109
* @since 2.1.0
98110
*/
99-
// TODO place a filter on only accepted labels
100111
public abstract Builder label(String label);
101112

102113
/**
@@ -118,10 +129,25 @@ public abstract static class Builder {
118129
*/
119130
public abstract Builder lnglat(Point lnglat);
120131

132+
/**
133+
* a percent-encoded URL for the marker image. Can be of type PNG or JPG.
134+
*
135+
* @param url an encoded URL for the marker image
136+
* @return this builder for chaining options together
137+
* @since 2.1.0
138+
*/
121139
public abstract Builder iconUrl(@Nullable String url);
122140

123141
abstract StaticMarkerAnnotation autoBuild();
124142

143+
/**
144+
* Build a new marker instance and pass it into
145+
* {@link com.mapbox.api.staticmap.v1.MapboxStaticMap} in order to use it during your Static Map
146+
* API request.
147+
*
148+
* @return a new instance of {@link StaticMarkerAnnotation}
149+
* @since 2.1.0
150+
*/
125151
public StaticMarkerAnnotation build() {
126152
StaticMarkerAnnotation marker = autoBuild();
127153
if (marker.lnglat() == null) {
@@ -131,13 +157,4 @@ public StaticMarkerAnnotation build() {
131157
return marker;
132158
}
133159
}
134-
135-
// TODO move to utils class
136-
public static final String toHexString(Color color) {
137-
String hexColour = Integer.toHexString(color.getRGB() & 0xffffff);
138-
if (hexColour.length() < 6) {
139-
hexColour = "000000".substring(0, 6 - hexColour.length()) + hexColour;
140-
}
141-
return hexColour;
142-
}
143160
}

services-staticmap/src/main/java/com/mapbox/api/staticmap/v1/models/StaticPolylineAnnotation.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.mapbox.api.staticmap.v1.models;
22

3+
import static android.support.annotation.RestrictTo.Scope.LIBRARY;
4+
import static com.mapbox.core.utils.ColorUtils.toHexString;
5+
36
import android.support.annotation.FloatRange;
47
import android.support.annotation.NonNull;
58
import android.support.annotation.Nullable;
69

10+
import android.support.annotation.RestrictTo;
711
import com.google.auto.value.AutoValue;
812
import com.mapbox.api.staticmap.v1.MapboxStaticMap;
913
import com.mapbox.geojson.utils.PolylineUtils;
@@ -32,6 +36,13 @@ public static Builder builder() {
3236
return new AutoValue_StaticPolylineAnnotation.Builder();
3337
}
3438

39+
/**
40+
* <em>Used Internally</em>
41+
*
42+
* @return a String representing the marker part of the URL
43+
* @since 2.1.0
44+
*/
45+
@RestrictTo(LIBRARY)
3546
public String url() {
3647
StringBuilder sb = new StringBuilder();
3748

@@ -142,18 +153,9 @@ public abstract static class Builder {
142153
* {@link StaticMarkerAnnotation} object which can be passed into the {@link MapboxStaticMap}
143154
* request.
144155
*
145-
* @return a new instance of StaticPolylineAnnotation
156+
* @return a new instance of {@link StaticPolylineAnnotation}
146157
* @since 2.1.0
147158
*/
148159
public abstract StaticPolylineAnnotation build();
149160
}
150-
151-
// TODO move to utils class
152-
public static final String toHexString(Color color) {
153-
String hexColour = Integer.toHexString(color.getRGB() & 0xffffff);
154-
if (hexColour.length() < 6) {
155-
hexColour = "000000".substring(0, 6 - hexColour.length()) + hexColour;
156-
}
157-
return hexColour;
158-
}
159161
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Package containing all the Static Map annotations avaliable.
3+
*
4+
* @since 3.0.0
5+
*/
6+
package com.mapbox.api.staticmap.v1.models;

0 commit comments

Comments
 (0)