summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/TileSet.java
blob: 1da8827d72c5de98ea735419841efb0ea480d60e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
package com.mapbox.mapboxsdk.style.sources;

import android.support.annotation.Size;

import com.mapbox.mapboxsdk.geometry.LatLng;

import java.util.HashMap;
import java.util.Map;

/**
 * Tile set
 *
 * @see <a href="https://github.com/mapbox/tilejson-spec/tree/master/2.1.0">The tileset specification</a>
 */
public class TileSet {
    private final String tilejson;
    private String name;
    private String description;
    private String version;
    private String attribution;
    private String template;
    private String legend;
    private String scheme;
    private final String[] tiles;
    private String[] grids;
    private String[] data;
    private Float minZoom;
    private Float maxZoom;
    private Float[] bounds;
    private Float[] center;

    /**
     * @param tilejson A semver.org style version number. Describes the version of the TileJSON spec that is implemented by this JSON object.
     * @param tiles    An array of tile endpoints. {z}, {x} and {y}, if present, are replaced with the corresponding integers.
     *                 If multiple endpoints are specified, clients may use any combination of endpoints. All endpoints MUST return the same
     *                 content for the same URL. The array MUST contain at least one endpoint.
     *                 Example: "http:localhost:8888/admin/1.0.0/world-light,broadband/{z}/{x}/{y}.png"
     */
    public TileSet(String tilejson, String... tiles) {
        this.tilejson = tilejson;
        this.tiles = tiles;
    }

    public String getTilejson() {
        return tilejson;
    }

    public String getName() {
        return name;
    }

    /**
     * A name describing the tileset. The name can
     * contain any legal character. Implementations SHOULD NOT interpret the
     * name as HTML.
     * "name": "compositing",
     */
    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    /**
     * A text description of the tileset. The
     * description can contain any legal character.
     * Implementations SHOULD NOT
     * interpret the description as HTML.
     * "description": "A simple, light grey world."
     */
    public void setDescription(String description) {
        this.description = description;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getAttribution() {
        return attribution;
    }

    /**
     * Default: null. Contains an attribution to be displayed
     * when the map is shown to a user. Implementations MAY decide to treat this
     * as HTML or literal text. For security reasons, make absolutely sure that
     * this field can't be abused as a vector for XSS or beacon tracking.
     * "attribution": "<a href='http:openstreetmap.org'>OSM contributors</a>",
     */
    public void setAttribution(String attribution) {
        this.attribution = attribution;
    }

    public String getTemplate() {
        return template;
    }

    /**
     * Contains a mustache template to be used to
     * format data from grids for interaction.
     * See https:github.com/mapbox/utfgrid-spec/tree/master/1.2
     * for the interactivity specification.
     * "template": "{{#__teaser__}}{{NAME}}{{/__teaser__}}"
     */
    public void setTemplate(String template) {
        this.template = template;
    }

    public String getLegend() {
        return legend;
    }

    /**
     * Contains a legend to be displayed with the map.
     * Implementations MAY decide to treat this as HTML or literal text.
     * For security reasons, make absolutely sure that this field can't be
     * abused as a vector for XSS or beacon tracking.
     * "legend": "Dangerous zones are red, safe zones are green"
     */
    public void setLegend(String legend) {
        this.legend = legend;
    }

    public String getScheme() {
        return scheme;
    }

    /**
     * Default: "xyz". Either "xyz" or "tms". Influences the y
     * direction of the tile coordinates.
     * The global-mercator (aka Spherical Mercator) profile is assumed.
     * "scheme": "xyz"
     */
    public void setScheme(String scheme) {
        this.scheme = scheme;
    }

    public String[] getTiles() {
        return tiles;
    }

    public String[] getGrids() {
        return grids;
    }

    /**
     * An array of interactivity endpoints. {z}, {x}
     * and {y}, if present, are replaced with the corresponding integers. If multiple
     * endpoints are specified, clients may use any combination of endpoints.
     * All endpoints MUST return the same content for the same URL.
     * If the array doesn't contain any entries, interactivity is not supported
     * for this tileset.     See https:github.com/mapbox/utfgrid-spec/tree/master/1.2
     * for the interactivity specification.
     * <p/>
     * Example: "http:localhost:8888/admin/1.0.0/broadband/{z}/{x}/{y}.grid.json"
     */
    public void setGrids(String... grids) {
        this.grids = grids;
    }

    public String[] getData() {
        return data;
    }

    /**
     * An array of data files in GeoJSON format.
     * {z}, {x} and {y}, if present,
     * are replaced with the corresponding integers. If multiple
     * endpoints are specified, clients may use any combination of endpoints.
     * All endpoints MUST return the same content for the same URL.
     * If the array doesn't contain any entries, then no data is present in
     * the map.
     * <p/>
     * "http:localhost:8888/admin/data.geojson"
     */
    public void setData(String... data) {
        this.data = data;
    }

    public float getMinZoom() {
        return minZoom;
    }

    /**
     * 0. >= 0, <= 22. An integer specifying the minimum zoom level.
     */
    public void setMinZoom(float minZoom) {
        this.minZoom = minZoom;
    }

    public float getMaxZoom() {
        return maxZoom;
    }

    /**
     * 0. >= 0, <= 22. An integer specifying the maximum zoom level.
     */
    public void setMaxZoom(float maxZoom) {
        this.maxZoom = maxZoom;
    }

    public Float[] getBounds() {
        return bounds;
    }

    /**
     * Default: [-180, -90, 180, 90]. The maximum extent of available map tiles. Bounds MUST define an area
     * covered by all zoom levels. The bounds are represented in WGS:84
     * latitude and longitude values, in the order left, bottom, right, top.
     * Values may be integers or floating point numbers.
     */
    public void setBounds(@Size(value = 4) Float... bounds) {
        this.bounds = bounds;
    }

    public Float[] getCenter() {
        return center;
    }

    /**
     * The first value is the longitude, the second is latitude (both in
     * WGS:84 values), the third value is the zoom level as an integer.
     * Longitude and latitude MUST be within the specified bounds.
     * The zoom level MUST be between minzoom and maxzoom.
     * Implementations can use this value to set the default location. If the
     * value is null, implementations may use their own algorithm for
     * determining a default location.
     */
    public void setCenter(@Size(value = 2) Float... center) {
        this.center = center;
    }

    public void setCenter(LatLng center) {
        this.center = new Float[]{(float) center.getLongitude(), (float) center.getLatitude()};
    }

    Map<String, Object> toValueObject() {
        Map<String, Object> result = new HashMap<>();
        result.put("tilejson", tilejson);
        result.put("tiles", tiles);

        if (name != null) {
            result.put("name", name);
        }
        if (description != null) {
            result.put("description", description);
        }
        if (version != null) {
            result.put("version", version);
        }
        if (attribution != null) {
            result.put("attribution", attribution);
        }
        if (template != null) {
            result.put("template", template);
        }
        if (legend != null) {
            result.put("legend", legend);
        }
        if (scheme != null) {
            result.put("scheme", scheme);
        }
        if (grids != null) {
            result.put("grids", grids);
        }
        if (data != null) {
            result.put("data", data);
        }
        if (minZoom != null) {
            result.put("minzoom", minZoom);
        }
        if (maxZoom != null) {
            result.put("maxzoom", maxZoom);
        }
        if (bounds != null) {
            result.put("bounds", bounds);
        }
        if (center != null) {
            result.put("center", center);
        }

        return result;
    }
}