forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaflet.d.ts
1450 lines (1188 loc) · 48.8 KB
/
leaflet.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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for Leaflet.js 1.0.0-rc3
// Project: https://github.com/Leaflet/Leaflet
// Definitions by: Alejandro Sánchez <https://github.com/alejo90>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../geojson/geojson.d.ts" />
declare namespace L {
export interface CRS {
latLngToPoint(latlng: LatLng, zoom: number): Point;
latLngToPoint(latlng: LatLngLiteral, zoom: number): Point;
latLngToPoint(latlng: LatLngTuple, zoom: number): Point;
pointToLatLng(point: Point): LatLng;
pointToLatLng(point: PointTuple): LatLng;
project(latlng: LatLng): Point;
project(latlng: LatLngLiteral): Point;
project(latlng: LatLngTuple): Point;
unproject(point: Point): LatLng;
unproject(point: PointTuple): LatLng;
scale(zoom: number): number;
zoom(scale: number): number;
getProjectedBounds(zoom: number): Bounds;
distance(latlng1: LatLng, latlng2: LatLng): number;
distance(latlng1: LatLngLiteral, latlng2: LatLngLiteral): number;
distance(latlng1: LatLngTuple, latlng2: LatLngTuple): number;
wrapLatLng(latlng: LatLng): LatLng;
wrapLatLng(latlng: LatLngLiteral): LatLng;
wrapLatLng(latlng: LatLngTuple): LatLng;
code: string;
wrapLng: [number, number];
wrapLat: [number, number];
infinite: boolean;
}
export namespace CRS {
export const EPSG3395: CRS;
export const EPSG3857: CRS;
export const EPSG4326: CRS;
export const Earth: CRS;
export const Simple: CRS;
}
export interface Projection {
project(latlng: LatLng): Point;
project(latlng: LatLngLiteral): Point;
project(latlng: LatLngTuple): Point;
unproject(point: Point): LatLng;
unproject(point: PointTuple): LatLng;
bounds: LatLngBounds;
}
export namespace Projection {
export const LonLat: Projection;
export const Mercator: Projection;
export const SphericalMercator: Projection;
}
export interface LatLng {
equals(otherLatLng: LatLng, maxMargin?: number): boolean;
equals(otherLatLng: LatLngLiteral, maxMargin?: number): boolean;
equals(otherLatLng: LatLngTuple, maxMargin?: number): boolean;
toString(): string;
distanceTo(otherLatLng: LatLng): number;
distanceTo(otherLatLng: LatLngLiteral): number;
distanceTo(otherLatLng: LatLngTuple): number;
wrap(): LatLng;
toBounds(sizeInMeters: number): LatLngBounds;
lat: number;
lng: number;
alt: number;
}
export interface LatLngLiteral {
lat: number;
lng: number;
}
export type LatLngTuple = [number, number];
type LatLngExpression = LatLng | LatLngLiteral | LatLngTuple;
export function latLng(latitude: number, longitude: number, altitude?: number): LatLng;
export function latLng(coords: LatLngTuple): LatLng;
export function latLng(coords: [number, number, number]): LatLng;
export function latLng(coords: LatLngLiteral): LatLng;
export function latLng(coords: {lat: number, lng: number, alt: number}): LatLng;
export interface LatLngBounds {
extend(latlng: LatLng): this;
extend(latlng: LatLngLiteral): this;
extend(latlng: LatLngTuple): this;
extend(otherBounds: LatLngBounds): this;
extend(otherBounds: LatLngBoundsLiteral): this;
pad(bufferRatio: number): LatLngBounds; // does this modify the current instance or does it return a new one?
getCenter(): LatLng;
getSouthWest(): LatLng;
getNorthEast(): LatLng;
getNorthWest(): LatLng;
getSouthEast(): LatLng;
getWest(): number;
getSouth(): number;
getEast(): number;
getNorth(): number;
contains(otherBounds: LatLngBounds): boolean;
contains(otherBounds: LatLngBoundsLiteral): boolean;
contains(latlng: LatLng): boolean;
contains(latlng: LatLngLiteral): boolean;
contains(latlng: LatLngTuple): boolean;
intersects(otherBounds: LatLngBounds): boolean;
intersects(otherBounds: LatLngLiteral): boolean;
overlaps(otherBounds: Bounds): boolean; // investigate if this is really bounds and not latlngbounds
overlaps(otherBounds: BoundsLiteral): boolean;
toBBoxString(): string;
equals(otherBounds: LatLngBounds): boolean;
equals(otherBounds: LatLngBoundsLiteral): boolean;
isValid(): boolean;
}
export type LatLngBoundsLiteral = Array<LatLngTuple>;
type LatLngBoundsExpression = LatLngBounds | LatLngBoundsLiteral;
export function latLngBounds(southWest: LatLng, northEast: LatLng): LatLngBounds;
export function latLngBounds(southWest: LatLngLiteral, northEast: LatLngLiteral): LatLngBounds;
export function latLngBounds(southWest: LatLngTuple, northEast: LatLngTuple): LatLngBounds;
export function latLngBounds(latlngs: LatLngBoundsLiteral): LatLngBounds;
export type PointTuple = [number, number];
export interface Point {
clone(): Point;
add(otherPoint: Point): Point; // investigate if this mutates or returns a new instance
add(otherPoint: PointTuple): Point;
subtract(otherPoint: Point): Point;
subtract(otherPoint: PointTuple): Point;
divideBy(num: number): Point;
multiplyBy(num: number): Point;
scaleBy(scale: Point): Point;
scaleBy(scale: PointTuple): Point;
unscaleBy(scale: Point): Point;
unscaleBy(scale: PointTuple): Point;
round(): Point;
floor(): Point;
ceil(): Point;
distanceTo(otherPoint: Point): Point;
distanceTo(otherPoint: PointTuple): Point;
equals(otherPoint: Point): boolean;
equals(otherPoint: PointTuple): boolean;
contains(otherPoint: Point): boolean;
contains(otherPoint: PointTuple): boolean;
toString(): string;
}
type PointExpression = Point | PointTuple;
export function point(x: number, y: number, round?: boolean): Point;
export function point(coords: PointTuple): Point;
export function point(coords: {x: number, y: number}): Point;
export type BoundsLiteral = Array<PointTuple>;
export interface Bounds {
extend(point: Point): this;
extend(point: PointTuple): this;
getCenter(round?: boolean): Point;
getBottomLeft(): Point;
getTopRight(): Point;
getSize(): Point;
contains(otherBounds: Bounds): boolean;
contains(otherBounds: BoundsLiteral): boolean;
contains(point: Point): boolean;
contains(point: PointTuple): boolean;
intersects(otherBounds: Bounds): boolean;
intersects(otherBounds: BoundsLiteral): boolean;
overlaps(otherBounds: Bounds): boolean;
overlaps(otherBounds: BoundsLiteral): boolean;
min: Point;
max: Point;
}
type BoundsExpression = Bounds | BoundsLiteral;
export function bounds(topLeft: Point, bottomRight: Point): Bounds;
export function bounds(topLeft: PointTuple, bottomRight: PointTuple): Bounds;
export function bounds(points: Array<Point>): Bounds;
export function bounds(points: BoundsLiteral): Bounds;
export type EventHandlerFn = (event: Event) => void;
export type EventHandlerFnMap = {[type: string]: EventHandlerFn};
/**
* A set of methods shared between event-powered classes (like Map and Marker).
* Generally, events allow you to execute some function when something happens
* with an object (e.g. the user clicks on the map, causing the map to fire
* 'click' event).
*/
export interface Evented {
/**
* Adds a listener function (fn) to a particular event type of the object.
* You can optionally specify the context of the listener (object the this
* keyword will point to). You can also pass several space-separated types
* (e.g. 'click dblclick').
*/
on(type: string, fn: EventHandlerFn, context?: Object): this;
/**
* Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
*/
on(eventMap: EventHandlerFnMap): this;
/**
* Removes a previously added listener function. If no function is specified,
* it will remove all the listeners of that particular event from the object.
* Note that if you passed a custom context to on, you must pass the same context
* to off in order to remove the listener.
*/
off(type: string, fn?: EventHandlerFn, context?: Object): this;
/**
* Removes a set of type/listener pairs.
*/
off(eventMap: EventHandlerFnMap): this;
/**
* Removes all listeners to all events on the object.
*/
off(): this;
/**
* Fires an event of the specified type. You can optionally provide a data
* object — the first argument of the listener function will contain its properties.
* The event might can optionally be propagated to event parents.
*/
fire(type: string, data?: Object, propagate?: boolean): this;
/**
* Returns true if a particular event type has any listeners attached to it.
*/
listens(type: string): boolean;
/**
* Behaves as on(...), except the listener will only get fired once and then removed.
*/
once(type: string, fn: EventHandlerFn, context?: Object): this;
/**
* Behaves as on(...), except the listener will only get fired once and then removed.
*/
once(eventMap: EventHandlerFnMap): this;
/**
* Adds an event parent - an Evented that will receive propagated events
*/
addEventParent(obj: Evented): this;
/**
* Removes an event parent, so it will stop receiving propagated events
*/
removeEventParent(obj: Evented): this;
/**
* Alias for on(...)
*
* Adds a listener function (fn) to a particular event type of the object.
* You can optionally specify the context of the listener (object the this
* keyword will point to). You can also pass several space-separated types
* (e.g. 'click dblclick').
*/
addEventListener(type: string, fn: EventHandlerFn, context?: Object): this;
/**
* Alias for on(...)
*
* Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
*/
addEventListener(eventMap: EventHandlerFnMap): this;
/**
* Alias for off(...)
*
* Removes a previously added listener function. If no function is specified,
* it will remove all the listeners of that particular event from the object.
* Note that if you passed a custom context to on, you must pass the same context
* to off in order to remove the listener.
*/
removeEventListener(type: string, fn: EventHandlerFn, context?: Object): this;
/**
* Alias for off(...)
*
* Removes a set of type/listener pairs.
*/
removeEventListener(eventMap: EventHandlerFnMap): this;
/**
* Alias for off()
*
* Removes all listeners to all events on the object.
*/
clearAllEventListeners(): this;
/**
* Alias for once(...)
*
* Behaves as on(...), except the listener will only get fired once and then removed.
*/
addOneTimeEventListener(type: string, fn: EventHandlerFn, context?: Object): this;
/**
* Alias for once(...)
*
* Behaves as on(...), except the listener will only get fired once and then removed.
*/
addOneTimeEventListener(eventMap: EventHandlerFnMap): this;
/**
* Alias for fire(...)
*
* Fires an event of the specified type. You can optionally provide a data
* object — the first argument of the listener function will contain its properties.
* The event might can optionally be propagated to event parents.
*/
fireEvent(type: string, data?: Object, propagate?: boolean): this;
/**
* Alias for listens(...)
*
* Returns true if a particular event type has any listeners attached to it.
*/
hasEventListeners(type: string): boolean;
}
interface LayerOptions {
pane?: string;
}
interface InteractiveLayerOptions extends LayerOptions {
interactive?: boolean;
}
export interface Layer extends Evented {
addTo(map: Map): this;
remove(): this;
removeFrom(map: Map): this;
getPane(name?: string): HTMLElement;
// Popup methods
bindPopup(content: string, options?: PopupOptions): this;
bindPopup(content: HTMLElement, options?: PopupOptions): this;
bindPopup(content: (layer: Layer) => Content, options?: PopupOptions): this;
bindPopup(content: Popup): this;
unbindPopup(): this;
openPopup(): this;
openPopup(latlng: LatLng): this;
openPopup(latlng: LatLngLiteral): this;
openPopup(latlng: LatLngTuple): this;
closePopup(): this;
togglePopup(): this;
isPopupOpen(): boolean;
setPopupContent(content: string): this;
setPopupContent(content: HTMLElement): this;
setPopupContent(content: Popup): this;
getPopup(): Popup;
// Tooltip methods
bindTooltip(content: string, options?: TooltipOptions): this;
bindTooltip(content: HTMLElement, options?: TooltipOptions): this;
bindTooltip(content: (layer: Layer) => Content, options?: TooltipOptions): this;
bindTooltip(content: Tooltip, options?: TooltipOptions): this;
unbindTooltip(): this;
openTooltip(): this;
openTooltip(latlng: LatLng): this;
openTooltip(latlng: LatLngLiteral): this;
openTooltip(latlng: LatLngTuple): this;
closeTooltip(): this;
toggleTooltip(): this;
isTooltipOpen(): boolean;
setTooltipContent(content: string): this;
setTooltipContent(content: HTMLElement): this;
setTooltipContent(content: Tooltip): this;
getTooltip(): Tooltip;
// Extension methods
onAdd(map: Map): this;
onRemove(map: Map): this;
getEvents(): {[name: string]: (event: Event) => void};
getAttribution(): string;
beforeAdd(map: Map): this;
}
export interface GridLayerOptions {
tileSize?: number | Point;
opacity?: number;
updateWhenIdle?: boolean;
updateWhenZooming?: boolean;
updateInterval?: number;
attribution?: string;
zIndex?: number;
bounds?: LatLngBoundsExpression;
minZoom?: number;
maxZoom?: number;
noWrap?: boolean;
pane?: string;
className?: string;
keepBuffer?: number;
}
export interface GridLayer extends Layer {
bringToFront(): this;
bringToBack(): this;
getAttribution(): string;
getContainer(): HTMLElement;
setOpacity(opacity: number): this;
setZIndex(zIndex: number): this;
isLoading(): boolean;
redraw(): this;
getTileSize(): Point;
}
export function gridLayer(options?: GridLayerOptions): GridLayer;
export interface TileLayerOptions extends GridLayerOptions {
minZoom?: number;
maxZoom?: number;
maxNativeZoom?: number;
subdomains?: string | Array<string>;
errorTileUrl?: string;
zoomOffset?: number;
tms?: boolean;
zoomReverse?: boolean;
detectRetina?: boolean;
crossOrigin?: boolean;
}
export interface TileLayer extends GridLayer {
setUrl(url: string, noRedraw?: boolean): this;
}
export function tileLayer(urlTemplate: string, options?: TileLayerOptions): TileLayer;
export interface WMSOptions extends TileLayerOptions {
layers: string;
styles?: string;
format?: string;
transparent?: boolean;
version?: string;
crs?: CRS;
uppercase?: boolean;
}
export interface WMS extends TileLayer {
setParams(params: Object, noRedraw?: boolean): this;
}
export namespace tileLayer {
export function wms(baseUrl: string, options: WMSOptions): WMS;
}
export interface ImageOverlayOptions extends LayerOptions {
opacity?: number;
alt?: string;
interactive?: boolean;
attribution?: string;
crossOrigin?: boolean;
}
export interface ImageOverlay extends Layer {
setOpacity(opacity: number): this;
bringToFront(): this;
bringToBack(): this;
setUrl(url: string): this;
}
export function imageOverlay(imageUrl: string, bounds: LatLngBoundsExpression, options?: ImageOverlayOptions): ImageOverlay;
export type LineCapShape = 'butt' | 'round' | 'square' | 'inherit';
export type LineJoinShape = 'miter' | 'round' | 'bevel' | 'inherit';
export type FillRule = 'nonzero' | 'evenodd' | 'inherit';
export interface PathOptions extends InteractiveLayerOptions {
stroke?: boolean;
color?: string;
weight?: number;
opacity?: number;
lineCap?: LineCapShape;
lineJoin?: LineJoinShape;
dashArray?: string;
dashOffset?: string;
fill?: boolean;
fillColor?: string;
fillOpacity?: number;
fillRule?: FillRule;
renderer?: Renderer;
className?: string;
}
export interface Path extends Layer {
redraw(): this;
setStyle(style: PathOptions): this;
bringToFront(): this;
bringToBack(): this;
}
export interface PolylineOptions extends PathOptions {
smoothFactor?: number;
noClip?: boolean;
}
interface InternalPolyline extends Path {
getLatLngs(): Array<LatLng>;
setLatLngs(latlngs: Array<LatLng>): this;
setLatLngs(latlngs: Array<LatLngLiteral>): this;
setLatLngs(latlngs: Array<LatLngTuple>): this;
isEmpty(): boolean;
getCenter(): LatLng;
getBounds(): LatLngBounds;
addLatLng(latlng: LatLng): this;
addLatLng(latlng: LatLngLiteral): this;
addLatLng(latlng: LatLngTuple): this;
addLatLng(latlng: Array<LatLng>): this; // these three overloads aren't explicitly noted in the docs
addLatLng(latlng: Array<LatLngLiteral>): this;
addLatLng(latlng: Array<LatLngTuple>): this;
}
export interface Polyline extends InternalPolyline {
toGeoJSON(): GeoJSON.LineString | GeoJSON.MultiLineString;
}
export function polyline(latlngs: Array<LatLng>, options?: PolylineOptions): Polyline;
export function polyline(latlngs: Array<LatLngLiteral>, options?: PolylineOptions): Polyline;
export function polyline(latlngs: Array<LatLngTuple>, options?: PolylineOptions): Polyline;
export function polyline(latlngs: Array<Array<LatLng>>, options?: PolylineOptions): Polyline;
export function polyline(latlngs: Array<Array<LatLngLiteral>>, options?: PolylineOptions): Polyline;
export function polyline(latlngs: Array<Array<LatLngTuple>>, options?: PolylineOptions): Polyline;
export interface Polygon extends InternalPolyline {
toGeoJSON(): GeoJSON.Polygon | GeoJSON.MultiPolygon;
}
export function polygon(latlngs: Array<LatLng>, options?: PolylineOptions): Polygon;
export function polygon(latlngs: Array<LatLngLiteral>, options?: PolylineOptions): Polygon;
export function polygon(latlngs: Array<LatLngTuple>, options?: PolylineOptions): Polygon;
export function polygon(latlngs: Array<Array<LatLng>>, options?: PolylineOptions): Polygon;
export function polygon(latlngs: Array<Array<LatLngLiteral>>, options?: PolylineOptions): Polygon;
export function polygon(latlngs: Array<Array<LatLngTuple>>, options?: PolylineOptions): Polygon;
export interface Rectangle extends Polygon {
setBounds(latLngBounds: LatLngBounds): this;
setBounds(latLngBounds: LatLngBoundsLiteral): this;
}
export function rectangle(latLngBounds: LatLngBounds, options?: PolylineOptions): Rectangle;
export function rectangle(latLngBounds: LatLngBoundsLiteral, options?: PolylineOptions): Rectangle;
export interface CircleMarkerOptions extends PathOptions {
radius?: number;
}
export interface CircleMarker extends Path {
toGeoJSON(): GeoJSON.Point;
setLatLng(latLng: LatLng): this;
setLatLng(latLng: LatLngLiteral): this;
setLatLng(latLng: LatLngTuple): this;
getLatLng(): LatLng;
setRadius(radius: number): this;
getRadius(): number;
}
export function circleMarker(latlng: LatLng, options?: CircleMarkerOptions): CircleMarker;
export function circleMarker(latlng: LatLngLiteral, options?: CircleMarkerOptions): CircleMarker;
export function circleMarker(latlng: LatLngLiteral, options?: CircleMarkerOptions): CircleMarker;
export interface CircleOptions extends PathOptions {
radius?: number;
}
export interface Circle extends CircleMarker {
setRadius(radius: number): this;
getRadius(): number;
getBounds(): LatLngBounds;
}
export function circle(latlng: LatLng, options?: CircleOptions): Circle;
export function circle(latlng: LatLngLiteral, options?: CircleOptions): Circle;
export function circle(latlng: LatLngTuple, options?: CircleOptions): Circle;
export function circle(latlng: LatLng, radius: number, options?: CircleOptions): Circle;
export function circle(latlng: LatLngLiteral, radius: number, options?: CircleOptions): Circle;
export function circle(latlng: LatLngTuple, radius: number, options?: CircleOptions): Circle;
export interface RendererOptions extends LayerOptions {
padding?: number;
}
export interface Renderer extends Layer {}
export interface SVG extends Renderer {}
export namespace SVG {
export function create(name: string): SVGElement;
export function pointsToPath(rings: Array<Point>, close: boolean): string;
export function pointsToPath(rings: Array<PointTuple>, close: boolean): string;
}
export function svg(options?: RendererOptions): SVG;
export interface Canvas extends Renderer {}
export function canvas(options?: RendererOptions): Canvas;
/**
* Used to group several layers and handle them as one.
* If you add it to the map, any layers added or removed from the group will be
* added/removed on the map as well. Extends Layer.
*/
export interface LayerGroup extends Layer {
/**
* Returns a GeoJSON representation of the layer group (as a GeoJSON GeometryCollection).
*/
toGeoJSON(): GeoJSON.GeometryCollection;
/**
* Adds the given layer to the group.
*/
addLayer(layer: Layer): this;
/**
* Removes the given layer from the group.
*/
removeLayer(layer: Layer): this;
/**
* Removes the layer with the given internal ID from the group.
*/
removeLayer(id: number): this;
/**
* Returns true if the given layer is currently added to the group.
*/
hasLayer(layer: Layer): boolean;
/**
* Removes all the layers from the group.
*/
clearLayers(): this;
/**
* Calls methodName on every layer contained in this group, passing any additional parameters.
* Has no effect if the layers contained do not implement methodName.
*/
invoke(methodName: string, ...params: Array<any>): this;
/**
* Iterates over the layers of the group,
* optionally specifying context of the iterator function.
*/
eachLayer(fn: (layer: Layer) => void, context?: Object): this;
/**
* Returns the layer with the given internal ID.
*/
getLayer(id: number): Layer;
/**
* Returns an array of all the layers added to the group.
*/
getLayers(): Array<Layer>;
/**
* Calls setZIndex on every layer contained in this group, passing the z-index.
*/
setZIndex(zIndex: number): this;
/**
* Returns the internal ID for a layer
*/
getLayerId(layer: Layer): number;
}
/**
* Create a layer group, optionally given an initial set of layers.
*/
export function layerGroup(layers: Array<Layer>): LayerGroup;
/**
* Extended LayerGroup that also has mouse events (propagated from
* members of the group) and a shared bindPopup method.
*/
export interface FeatureGroup extends LayerGroup {
/**
* Sets the given path options to each layer of the group that has a setStyle method.
*/
setStyle(style: PathOptions): this;
/**
* Brings the layer group to the top of all other layers
*/
bringToFront(): this;
/**
* Brings the layer group to the top [sic] of all other layers
*/
bringToBack(): this;
/**
* Returns the LatLngBounds of the Feature Group (created from
* bounds and coordinates of its children).
*/
getBounds(): LatLngBounds;
}
/**
* Create a feature group, optionally given an initial set of layers.
*/
export function featureGroup(layers?: Array<Layer>): FeatureGroup;
type StyleFunction = (feature: GeoJSON.Feature<GeoJSON.GeometryObject>) => PathOptions;
export interface GeoJSONOptions extends LayerOptions {
/**
* A Function defining how GeoJSON points spawn Leaflet layers.
* It is internally called when data is added, passing the GeoJSON point
* feature and its LatLng.
*
* The default is to spawn a default Marker:
*
* ```
* function(geoJsonPoint, latlng) {
* return L.marker(latlng);
* }
* ```
*/
pointToLayer?: (geoJsonPoint: GeoJSON.Point, latlng: LatLng) => Layer; // should import GeoJSON typings
/**
* A Function defining the Path options for styling GeoJSON lines and polygons,
* called internally when data is added.
*
* The default value is to not override any defaults:
*
* ```
* function (geoJsonFeature) {
* return {}
* }
* ```
*/
style?: StyleFunction;
/**
* A Function that will be called once for each created Feature, after it
* has been created and styled. Useful for attaching events and popups to features.
*
* The default is to do nothing with the newly created layers:
*
* ```
* function (feature, layer) {}
* ```
*/
onEachFeature?: (feature: GeoJSON.Feature<GeoJSON.GeometryObject>, layer: Layer) => void;
/**
* A Function that will be used to decide whether to show a feature or not.
*
* The default is to show all features:
*
* ```
* function (geoJsonFeature) {
* return true;
* }
* ```
*/
filter?: (geoJsonFeature: GeoJSON.Feature<GeoJSON.GeometryObject>) => boolean;
/**
* A Function that will be used for converting GeoJSON coordinates to LatLngs.
* The default is the coordsToLatLng static method.
*/
coordsToLatLng?: (coords: [number, number] | [number, number, number]) => LatLng; // check if LatLng has an altitude property
}
/**
* Represents a GeoJSON object or an array of GeoJSON objects.
* Allows you to parse GeoJSON data and display it on the map. Extends FeatureGroup.
*/
export interface GeoJSON extends FeatureGroup {
/**
* Adds a GeoJSON object to the layer.
*/
addData(data: GeoJSON.GeoJsonObject): Layer;
/**
* Resets the given vector layer's style to the original GeoJSON style,
* useful for resetting style after hover events.
*/
resetStyle(layer: Layer): Layer;
/**
* Changes styles of GeoJSON vector layers with the given style function.
*/
setStyle(style: StyleFunction): this;
/**
* Creates a Layer from a given GeoJSON feature. Can use a custom pointToLayer
* and/or coordsToLatLng functions if provided as options.
*/
geometryToLayer(featureData: GeoJSON.Feature<GeoJSON.GeometryObject>, options?: GeoJSONOptions): Layer;
/**
* Creates a LatLng object from an array of 2 numbers (longitude, latitude) or
* 3 numbers (longitude, latitude, altitude) used in GeoJSON for points.
*/
coordsToLatLng(coords: [number, number]): LatLng;
coordsToLatLng(coords: [number, number, number]): LatLng;
/**
* Creates a multidimensional array of LatLngs from a GeoJSON coordinates array.
* levelsDeep specifies the nesting level (0 is for an array of points, 1 for an array of
* arrays of points, etc., 0 by default).
* Can use a custom coordsToLatLng function.
*/
coordsToLatLngs(coords: Array<number>, levelsDeep?: number, coordsToLatLng?: (coords: [number, number] | [number, number, number]) => LatLng): LatLng[]; // Not entirely sure how to define arbitrarily nested arrays
/**
* Reverse of coordsToLatLng
*/
latLngToCoords(latlng: LatLng): [number, number] | [number, number, number];
/**
* Reverse of coordsToLatLngs closed determines whether the first point should be
* appended to the end of the array to close the feature, only used when levelsDeep is 0.
* False by default.
*/
latLngsToCoords(latlngs: Array<LatLng>, levelsDeep?: number, closed?: boolean): [number, number] | [number, number, number];
/**
* Normalize GeoJSON geometries/features into GeoJSON features.
*/
asFeature(geojson: GeoJSON.GeometryObject): GeoJSON.Feature<GeoJSON.GeometryObject>;
asFeature(geojson: GeoJSON.Feature<GeoJSON.GeometryObject>): GeoJSON.Feature<GeoJSON.GeometryObject>;
}
/**
* Creates a GeoJSON layer.
*
* Optionally accepts an object in GeoJSON format to display on the
* map (you can alternatively add it later with addData method) and
* an options object.
*/
export function geoJSON(geojson?: GeoJSON.GeoJsonObject, options?: GeoJSONOptions): GeoJSON;
type Zoom = boolean | 'center';
export interface MapOptions {
preferCanvas?: boolean;
// Control options
attributionControl?: boolean;
zoomControl?: boolean;
// Interaction options
closePopupOnClick?: boolean;
zoomSnap?: number;
zoomDelta?: number;
trackResize?: boolean;
boxZoom?: boolean;
doubleClickZoom?: Zoom;
dragging?: boolean;
// Map state options
crs?: CRS;
center?: LatLngExpression;
zoom?: number;
minZoom?: number;
maxZoom?: number;
layers?: Array<Layer>;
maxBounds?: LatLngBoundsExpression;
renderer?: Renderer;
// Animation options
fadeAnimation?: boolean;
markerZoomAnimation?: boolean;
transform3DLimit?: number;
zoomAnimation?: boolean;
zoomAnimationThreshold?: number;
// Panning inertia options
inertia?: boolean;
inertiaDeceleration?: number;
inertiaMaxSpeed?: number;
easeLinearity?: number;
worldCopyJump?: boolean;
maxBoundsViscosity?: number;
// Keyboard navigation options
keyboard?: boolean;
keyboardPanDelta?: number;
// Mousewheel options
scrollWheelZoom?: Zoom;
wheelDebounceTime?: number;
wheelPxPerZoomLevel?: number;
// Touch interaction options
tap?: boolean;
tapTolerance?: number;
touchZoom?: Zoom;
bounceAtZoomLimits?: boolean;
}
export type ControlPosition = 'topleft' | 'topright' | 'bottomleft' | 'bottomright';
export interface ControlOptions {
position?: ControlPosition;
}
export interface Control {
getPosition(): ControlPosition;
setPosition(position: ControlPosition): this;
getContainer(): HTMLElement;
addTo(map: Map): this;
remove(): this;
// Extension methods
onAdd(map: Map): HTMLElement;
onRemove(map: Map): void;
}
export namespace Control {
export interface ZoomOptions extends ControlOptions {
zoomInText?: string;
zoomInTitle?: string;
zoomOutText?: string;
zoomOutTitle?: string;
}
export interface Zoom extends Control {}
export interface AttributionOptions extends ControlOptions {
prefix?: string | boolean;
}
export interface Attribution extends Control {
setPrefix(prefix: string): this;
addAttribution(text: string): this;
removeAttribution(text: string): this;
}
export interface LayersOptions extends ControlOptions {
collapsed?: boolean;
autoZIndex?: boolean;
hideSingleBase?: boolean;
}
export interface Layers extends Control {
addBaseLayer(layer: Layer, name: string): this;
addOverlay(layer: Layer, name: string): this;
removeLayer(layer: Layer): this;
expand(): this;
collapse(): this;
}