forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapbox.d.ts
453 lines (328 loc) · 11.9 KB
/
mapbox.d.ts
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
// Type definitions for Mapbox 1.6.3
// Project: https://www.mapbox.com/mapbox.js/
// Definitions by: Maxime Fabre <https://github.com/anahkiasen/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../leaflet/leaflet.d.ts"/>
//////////////////////////////////////////////////////////////////////
///////////////////////////// MAP OBJECT /////////////////////////////
//////////////////////////////////////////////////////////////////////
// Map
//////////////////////////////////////////////////////////////////////
declare module L.mapbox {
var accessToken: string;
/**
* Create and automatically configure a map with layers, markers, and interactivity.
*/
function map(element: string, id: string, options?: MapOptions): L.mapbox.Map;
function map(element: string, tilejson: any, options?: MapOptions): L.mapbox.Map;
interface MapOptions extends L.MapOptions {
featureLayer? : FeatureLayerOptions;
gridLayer? : any;
tileLayer? : TileLayerOptions;
infoControl? : ControlOptions;
legendControl? : ControlOptions;
shareControl? : ShareControlOptions;
}
interface FilterFunction {
(feature: any): boolean;
}
interface Map extends L.Map {
tileLayer : L.mapbox.TileLayer;
gridLayer : L.mapbox.GridLayer;
featureLayer : L.mapbox.FeatureLayer;
gridControl : L.mapbox.GridControl;
infoControl : L.mapbox.InfoControl;
legendControl : L.mapbox.LegendControl;
shareControl : L.mapbox.ShareControl;
addLayer(layer: any): any;
getTileJSON(): any;
}
}
//////////////////////////////////////////////////////////////////////
/////////////////////////////// LAYERS ///////////////////////////////
//////////////////////////////////////////////////////////////////////
// TileLayer
//////////////////////////////////////////////////////////////////////
declare module L.mapbox {
/**
* You can add a tiled layer to your map with L.mapbox.tileLayer(), a simple interface to layers from Mapbox and elsewhere.
*/
function tileLayer(id: string, options?: TileLayerOptions): L.mapbox.TileLayer;
function tileLayer(tilejson: any, options?: TileLayerOptions): L.mapbox.TileLayer;
interface TileLayerOptions extends L.TileLayerOptions {
retinaVersion?: string;
}
interface TileLayer extends L.TileLayer {
/**
* Returns this layer's TileJSON object which determines its tile source, zoom bounds and other metadata.
*/
getTileJSON(): any;
/**
* Set the image format of tiles in this layer. You can use lower-quality tiles in order to load maps faster
*/
setFormat(format: string): TileLayer;
}
}
// GridLayer
//////////////////////////////////////////////////////////////////////
declare module L.mapbox {
/**
* An L.mapbox.gridLayer loads UTFGrid tiles of interactivity into your map, which you can easily access with L.mapbox.gridControl.
*/
function gridLayer(id: string): L.mapbox.GridLayer;
function gridLayer(tilejson: any): L.mapbox.GridLayer;
interface GridLayer {
active(): boolean;
addTo(map: L.mapbox.Map): any;
onAdd(map: L.mapbox.Map): any;
onRemove(): any;
/**
* Bind an event handler to a given event on this L.mapbox.gridLayer instance. GridLayers expose a number of useful events that give you access to UTFGrid data as the user interacts with the map.
*/
on(event: string, handler: Function, context?: any): any;
/**
* Returns this layer's TileJSON object which determines its tile source, zoom bounds and other metadata.
*/
getTileJSON(): any;
/**
* Load data for a given latitude, longitude point on the map, and call the callback function with that data, if any.
*/
getData(latlng: L.LatLng, callback: Function): any;
}
}
// FeatureLayer
//////////////////////////////////////////////////////////////////////
declare module L.mapbox {
/**
* L.mapbox.featureLayer provides an easy way to integrate GeoJSON from Mapbox and elsewhere into your map.
*/
function featureLayer(): L.mapbox.FeatureLayer;
function featureLayer(id: string, options?: FeatureLayerOptions): L.mapbox.FeatureLayer;
function featureLayer(geojson: any, options?: FeatureLayerOptions): L.mapbox.FeatureLayer;
interface FeatureLayerOptions {
filter? : FilterFunction;
sanitizer? : (template: string) => string;
}
interface FeatureLayer extends L.FeatureGroup<L.ILayer> {
/**
* Load GeoJSON data for this layer from the URL given by url.
*/
loadURL(url: string): any;
/**
* Load marker GeoJSON data from a map with the given id on Mapbox.
*/
loadID(id: string): any;
/**
* Sets the filter function for this data layer.
*/
setFilter(filter: FilterFunction): any;
/**
* Gets the filter function for this data layer.
*/
getFilter(): FilterFunction;
/**
* Set the contents of a markers layer: run the provided features through
* the filter function and then through the factory function to create
* elements for the map. If the layer already has features, they are
* replaced with the new features. An empty array will clear the
* layer of all features.
*/
setGeoJSON(geojson: any): L.mapbox.FeatureLayer;
/**
* Get the contents of this layer as GeoJSON data.
*/
getGeoJSON(): any;
}
}
//////////////////////////////////////////////////////////////////////
////////////////////////////// GEOCODING /////////////////////////////
//////////////////////////////////////////////////////////////////////
// Geocoder
//////////////////////////////////////////////////////////////////////
declare module L.mapbox {
/**
* A low-level interface to geocoding, useful for more complex uses and reverse-geocoding.
*/
function geocoder(id: string): L.mapbox.Geocoder;
interface Geocoder {
getURL(): string;
setURL(url: string): any;
setID(id: string): any;
setTileJSON(tilejson: any): any;
queryURL(url: string): string;
/**
* Queries the geocoder with a query string, and returns its result, if any.
*/
query(queryString: string, callback: Function): any;
/**
* Queries the geocoder with a location, and returns its result, if any.
*/
reverseQuery(location: any, callback: Function): any;
}
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////// CONTROLS ////////////////////////////
//////////////////////////////////////////////////////////////////////
declare module L.mapbox {
interface ControlOptions extends L.ControlOptions {
sanitizer?: (template: string) => string;
}
}
// InfoControl
//////////////////////////////////////////////////////////////////////
declare module L.mapbox {
/**
* A map control that shows a toggleable info container. If set, attribution is auto-detected from active layers and added to the info container.
*/
function infoControl(options?: ControlOptions): InfoControl;
interface InfoControl extends L.Control {
onAdd(map: L.mapbox.Map): any;
onRemove(map: L.mapbox.Map): any;
/**
* Adds an info string to infoControl.
*/
addInfo(info: string): any;
/**
* Removes an info string from infoControl
*/
removeInfo(info: string): any;
}
}
// LegendControl
//////////////////////////////////////////////////////////////////////
declare module L.mapbox {
/**
* A map control that shows legends added to maps in Mapbox.
* Legends are auto-detected from active layers.
*/
function legendControl(options?: ControlOptions): LegendControl;
interface LegendControl extends L.Control {
onAdd(map: L.mapbox.Map): any;
/**
* Adds a legend to the legendControl.
*/
addLegend(legend: string): any;
/**
* Removes a legend from the legendControl.
*/
removeLegend(legend: string): any;
}
}
// GridControl
//////////////////////////////////////////////////////////////////////
declare module L.mapbox {
/**
* Interaction is what we call interactive parts of maps that are created with
* the powerful tooltips & regions system in TileMill. Under the hood, it's powered by the open UTFGrid specification.
*/
function gridControl(layer: string, options?: GridControlOptions): GridControl;
interface GridControlOptions extends ControlOptions {
template? : string;
follow? : boolean;
pinnable? : boolean;
touchTeaser? : boolean;
location? : boolean;
}
interface GridControl extends L.Control {
onAdd(map: L.mapbox.Map): any;
onRemove(map: L.mapbox.Map): any;
/**
* If a tooltip is currently shown by the gridControl, hide and close it.
*/
hide(): any;
/**
* Change the Mustache template used to transform the UTFGrid data in the map's interactivity into HTML for display.
*/
setTemplate(template: string): any;
}
}
// GeocoderControl
//////////////////////////////////////////////////////////////////////
declare module L.mapbox {
/**
* Adds geocoder functionality as well as a UI element to a map. This uses the Mapbox Geocoding API.
*/
function geocoderControl(id: string, options?: GeocoderControlOptions): GeocoderControl;
interface GeocoderControlOptions extends L.ControlOptions {
keepOpen?: boolean;
}
interface GeocoderControl {
getURL(): string;
onAdd(map: L.mapbox.Map): any;
/**
* Set the url used for geocoding.
*/
setURL(url: string): any;
/**
* Set the map id used for geocoding.
*/
setID(id: string): any;
/**
* Set the TileJSON used for geocoding.
*/
setTileJSON(tilejson: any): any;
/**
* Bind a listener to an event emitted by the geocoder control. Supported additional events are
*/
on(event: string, callback: Function): any;
}
}
// ShareControl
//////////////////////////////////////////////////////////////////////
declare module L.mapbox {
/**
* Adds a "Share" button to the map, which can be used to share the map to Twitter or Facebook, or generate HTML for a map embed.
*/
function shareControl(id: string, options?: ShareControlOptions): ShareControl;
interface ShareControlOptions extends L.ControlOptions {
url?: string;
}
interface ShareControl extends L.Control {
onAdd(map: L.mapbox.Map): any;
}
}
//////////////////////////////////////////////////////////////////////
////////////////////////////// MARKERS ///////////////////////////////
//////////////////////////////////////////////////////////////////////
declare module L.mapbox.marker {
/**
* A core icon generator used in L.mapbox.marker.style
*/
function icon(feature: any): L.Icon;
/**
* An icon generator for use in conjunction with pointToLayer to generate markers from the Mapbox Markers API and support the simplestyle-spec for features.
*/
function style(feature: any, latlng: any): L.Marker;
}
//////////////////////////////////////////////////////////////////////
////////////////////////////// SIMPLESTYLE ///////////////////////////
//////////////////////////////////////////////////////////////////////
declare module L.mapbox.simplestyle {
/**
* Given a GeoJSON Feature with optional simplestyle-spec properties, return an options object formatted to be used as Leaflet Path options.
*/
function style(feature: any): L.PathOptions;
}
//////////////////////////////////////////////////////////////////////
/////////////////////////////// UTILITY //////////////////////////////
//////////////////////////////////////////////////////////////////////
declare module L.mapbox {
/**
* A HTML sanitization function, with the same effect as the default value of the sanitizer option of L.mapbox.featureLayer, L.mapbox.gridControl, and L.mapbox.legendControl.
*/
function sanitize(text: string): string;
/**
* A mustache template rendering function, as used by the templating feature provided by L.mapbox.gridControl.
*/
function template(template: string, data?: any): string;
}
//////////////////////////////////////////////////////////////////////
///////////////////////////// CONFIGURATION //////////////////////////
//////////////////////////////////////////////////////////////////////
declare module L.mapbox {
export class config {
static FORCE_HTTPS: boolean;
static HTTP_URLS: string[];
static HTTPS_URLS: string[];
}
}