|
1 | | -import { ZoomTransform } from "d3"; |
| 1 | +import { ZoomTransform } from "d3-zoom"; |
2 | 2 |
|
3 | | -declare module "d3" { |
4 | | - type Tile = [number, number, number]; |
| 3 | +export type Tile = [number, number, number]; |
5 | 4 |
|
6 | | - interface Tiles extends Array<Tile> { |
7 | | - translate: [number, number]; |
8 | | - scale: number; |
9 | | - } |
10 | | - |
11 | | - interface TileLayout { |
12 | | - /** |
13 | | - * Computes the set of tiles to display given the current settings, |
14 | | - * computing the scale and translate by invoking the corresponding |
15 | | - * accessors with the given arguments. Returns an array of [x, y, z] |
16 | | - * arrays representing the x- (horizontal), y- (vertical) and z- (zoom) |
17 | | - * coordinates of the visible tiles. The returned tiles array also has |
18 | | - * tiles.scale and tiles.translate properties which together with an |
19 | | - * individual tile’s x and y determine the intended location of the tile |
20 | | - * in the viewport. |
21 | | - */ |
22 | | - (): Tiles; |
23 | | - (t: ZoomTransform): Tiles; |
24 | | - |
25 | | - /** |
26 | | - * If size is specified, sets this tile layout’s viewport size to the |
27 | | - * specified array of numbers [width, height] and returns this tile |
28 | | - * layout. If size is not specified, returns the current viewport size, |
29 | | - * which defaults to [960, 500]. This is a convenience method for setting |
30 | | - * the viewport extent to [[0, 0], [width, height]]. |
31 | | - */ |
32 | | - size(): [number, number]; |
33 | | - size(size: [number, number]): this; |
| 5 | +export interface Tiles extends Array<Tile> { |
| 6 | + translate: [number, number]; |
| 7 | + scale: number; |
| 8 | +} |
34 | 9 |
|
35 | | - /** |
36 | | - * If scale is specified, sets this tile layout’s scale function and |
37 | | - * returns this tile layout. If scale is a function, it is invoked when |
38 | | - * the tile layout is invoked, being passed the same arguments as the tile |
39 | | - * layout; this function must return a number indicating the desired width |
40 | | - * and height of the world tile [0, 0, 0]. If scale is not a function, it |
41 | | - * assumed to be a constant number, and is wrapped in a function which |
42 | | - * returns the specified number. If scale is not specified, returns the |
43 | | - * current layout scale function. |
44 | | - */ |
45 | | - scale(): (...args: any[]) => number; |
46 | | - scale(scale: number | ((...args: any[]) => number)): this; |
| 10 | +export interface TileLayout { |
| 11 | + /** |
| 12 | + * Computes the set of tiles to display given the current settings, |
| 13 | + * computing the scale and translate by invoking the corresponding |
| 14 | + * accessors with the given arguments. Returns an array of [x, y, z] |
| 15 | + * arrays representing the x- (horizontal), y- (vertical) and z- (zoom) |
| 16 | + * coordinates of the visible tiles. The returned tiles array also has |
| 17 | + * tiles.scale and tiles.translate properties which together with an |
| 18 | + * individual tile’s x and y determine the intended location of the tile |
| 19 | + * in the viewport. |
| 20 | + */ |
| 21 | + (): Tiles; |
| 22 | + (t: ZoomTransform): Tiles; |
47 | 23 |
|
48 | | - /** |
49 | | - * If translate is specified, sets this tile layout’s translate function |
50 | | - * and returns this tile layout. If translate is a function, it is invoked |
51 | | - * when the tile layout is invoked, being passed the same arguments as the |
52 | | - * tile layout; this function must return an array of numbers [x, y] |
53 | | - * indicating the desired coordinates the center of the world tile [0, 0, |
54 | | - * 0]. If translate is not a function, it is assumed to be a constant |
55 | | - * array [x, y] and is wrapped in a function which returns the specified |
56 | | - * array. If translate is not specified, returns the current layout |
57 | | - * translate function. |
58 | | - */ |
59 | | - translate(): (...args: any[]) => [number, number]; |
60 | | - translate( |
61 | | - translate: [ |
62 | | - number, |
63 | | - number, |
64 | | - ] | ((...args: any[]) => [number, number]), |
65 | | - ): this; |
| 24 | + /** |
| 25 | + * If size is specified, sets this tile layout’s viewport size to the |
| 26 | + * specified array of numbers [width, height] and returns this tile |
| 27 | + * layout. If size is not specified, returns the current viewport size, |
| 28 | + * which defaults to [960, 500]. This is a convenience method for setting |
| 29 | + * the viewport extent to [[0, 0], [width, height]]. |
| 30 | + */ |
| 31 | + size(): [number, number]; |
| 32 | + size(size: [number, number]): this; |
66 | 33 |
|
67 | | - /** |
68 | | - * If zoomDelta is specified, sets this tile layout’s zoom offset to the |
69 | | - * specified number zoomDelta and returns this tile layout. If zoomDelta |
70 | | - * is not specified, returns the current zoom offset, which defaults to 0. |
71 | | - * The zoom offset affects which z-coordinate is chosen based on the |
72 | | - * current scale; the default zoom offset of 0 which choose the z that is |
73 | | - * closest the displayed size; a zoom offset of -1 will use z - 1, giving |
74 | | - * tiles that are twice as big (lower resolution); a zoom offset of +1 |
75 | | - * will use z + 1, giving tiles that are twice as small (higher |
76 | | - * resolution). The latter might be appropriate for showing 256×256 tiles |
77 | | - * in a 128×128 space on a high-resolution screen. |
78 | | - */ |
79 | | - zoomDelta(): number; |
80 | | - zoomDelta(zoomDelta: number): this; |
| 34 | + /** |
| 35 | + * If scale is specified, sets this tile layout’s scale function and |
| 36 | + * returns this tile layout. If scale is a function, it is invoked when |
| 37 | + * the tile layout is invoked, being passed the same arguments as the tile |
| 38 | + * layout; this function must return a number indicating the desired width |
| 39 | + * and height of the world tile [0, 0, 0]. If scale is not a function, it |
| 40 | + * assumed to be a constant number, and is wrapped in a function which |
| 41 | + * returns the specified number. If scale is not specified, returns the |
| 42 | + * current layout scale function. |
| 43 | + */ |
| 44 | + scale(): (...args: any[]) => number; |
| 45 | + scale(scale: number | ((...args: any[]) => number)): this; |
81 | 46 |
|
82 | | - /** |
83 | | - * If clamp is specified, sets tile.clampX and tile.clampY to the |
84 | | - * specified boolean clamp and returns this tile layout. If clamp is not |
85 | | - * specified, returns true if tile.clampX and tile.clampY are both true, |
86 | | - * and false otherwise. |
87 | | - */ |
88 | | - clamp(): boolean; |
89 | | - clamp(clamp: boolean): this; |
| 47 | + /** |
| 48 | + * If translate is specified, sets this tile layout’s translate function |
| 49 | + * and returns this tile layout. If translate is a function, it is invoked |
| 50 | + * when the tile layout is invoked, being passed the same arguments as the |
| 51 | + * tile layout; this function must return an array of numbers [x, y] |
| 52 | + * indicating the desired coordinates the center of the world tile [0, 0, |
| 53 | + * 0]. If translate is not a function, it is assumed to be a constant |
| 54 | + * array [x, y] and is wrapped in a function which returns the specified |
| 55 | + * array. If translate is not specified, returns the current layout |
| 56 | + * translate function. |
| 57 | + */ |
| 58 | + translate(): (...args: any[]) => [number, number]; |
| 59 | + translate( |
| 60 | + translate: [ |
| 61 | + number, |
| 62 | + number, |
| 63 | + ] | ((...args: any[]) => [number, number]), |
| 64 | + ): this; |
90 | 65 |
|
91 | | - /** |
92 | | - * If clamp is specified, sets whether or not the visible tiles will be |
93 | | - * clamped in the x-coordinate and returns this tile layout. If clamp is |
94 | | - * not specified, returns the current x-clamp, which defaults to true. If |
95 | | - * the x-clamp is false, then the tile layout will return tiles that are |
96 | | - * outside the “world” tile [0, 0, 0], with x-coordinates that are outside |
97 | | - * the normal bounds 0 ≤ x < 2^z. See d3.tileWrap for converting these |
98 | | - * coordinates to wrapped in-world coordinates. |
99 | | - */ |
100 | | - clampX(): boolean; |
101 | | - clampX(clamp: boolean): this; |
| 66 | + /** |
| 67 | + * If zoomDelta is specified, sets this tile layout’s zoom offset to the |
| 68 | + * specified number zoomDelta and returns this tile layout. If zoomDelta |
| 69 | + * is not specified, returns the current zoom offset, which defaults to 0. |
| 70 | + * The zoom offset affects which z-coordinate is chosen based on the |
| 71 | + * current scale; the default zoom offset of 0 which choose the z that is |
| 72 | + * closest the displayed size; a zoom offset of -1 will use z - 1, giving |
| 73 | + * tiles that are twice as big (lower resolution); a zoom offset of +1 |
| 74 | + * will use z + 1, giving tiles that are twice as small (higher |
| 75 | + * resolution). The latter might be appropriate for showing 256×256 tiles |
| 76 | + * in a 128×128 space on a high-resolution screen. |
| 77 | + */ |
| 78 | + zoomDelta(): number; |
| 79 | + zoomDelta(zoomDelta: number): this; |
102 | 80 |
|
103 | | - /** |
104 | | - * If clamp is specified, sets whether or not the visible tiles will be |
105 | | - * clamped in the y-coordinate and returns this tile layout. If clamp is |
106 | | - * not specified, returns the current y-clamp, which defaults to true. If |
107 | | - * the y-clamp is false, then the tile layout will return tiles that are |
108 | | - * outside the “world” tile [0, 0, 0], with y-coordinates that are outside |
109 | | - * the normal bounds 0 ≤ y < 2^z. See d3.tileWrap for converting these |
110 | | - * coordinates to wrapped in-world coordinates. See also tile.clampX. |
111 | | - */ |
112 | | - clampY(): boolean; |
113 | | - clampY(clamp: boolean): this; |
| 81 | + /** |
| 82 | + * If clamp is specified, sets tile.clampX and tile.clampY to the |
| 83 | + * specified boolean clamp and returns this tile layout. If clamp is not |
| 84 | + * specified, returns true if tile.clampX and tile.clampY are both true, |
| 85 | + * and false otherwise. |
| 86 | + */ |
| 87 | + clamp(): boolean; |
| 88 | + clamp(clamp: boolean): this; |
114 | 89 |
|
115 | | - /** |
116 | | - * If tileSize is specified, sets this tile layout’s tile width and height |
117 | | - * to the specified number tileSize and returns this tile layout. If |
118 | | - * tileSize is not specified, returns the current layout tile size, which |
119 | | - * defaults to 256. 256×256 is the most common tile size among tile |
120 | | - * providers. |
121 | | - */ |
122 | | - tileSize(): number; |
123 | | - tileSize(tileSize: number): this; |
| 90 | + /** |
| 91 | + * If clamp is specified, sets whether or not the visible tiles will be |
| 92 | + * clamped in the x-coordinate and returns this tile layout. If clamp is |
| 93 | + * not specified, returns the current x-clamp, which defaults to true. If |
| 94 | + * the x-clamp is false, then the tile layout will return tiles that are |
| 95 | + * outside the “world” tile [0, 0, 0], with x-coordinates that are outside |
| 96 | + * the normal bounds 0 ≤ x < 2^z. See d3.tileWrap for converting these |
| 97 | + * coordinates to wrapped in-world coordinates. |
| 98 | + */ |
| 99 | + clampX(): boolean; |
| 100 | + clampX(clamp: boolean): this; |
124 | 101 |
|
125 | | - /** |
126 | | - * If extent is specified, sets this tile layout’s viewport extent to the |
127 | | - * specified array [[x0, y0], [x1, y1]], where [x0, y0] is the top-left |
128 | | - * corner and [x1, y1] is the bottom-right corner, and returns this tile |
129 | | - * layout. If extent is not specified, returns the current viewport |
130 | | - * extent, which defaults to [[0, 0], [960, 500]]. Setting the viewport |
131 | | - * extent implicitly sets the viewport size. |
132 | | - */ |
133 | | - extent(): [[number, number], [number, number]]; |
134 | | - extent(extent: [[number, number], [number, number]]): this; |
135 | | - } |
| 102 | + /** |
| 103 | + * If clamp is specified, sets whether or not the visible tiles will be |
| 104 | + * clamped in the y-coordinate and returns this tile layout. If clamp is |
| 105 | + * not specified, returns the current y-clamp, which defaults to true. If |
| 106 | + * the y-clamp is false, then the tile layout will return tiles that are |
| 107 | + * outside the “world” tile [0, 0, 0], with y-coordinates that are outside |
| 108 | + * the normal bounds 0 ≤ y < 2^z. See d3.tileWrap for converting these |
| 109 | + * coordinates to wrapped in-world coordinates. See also tile.clampX. |
| 110 | + */ |
| 111 | + clampY(): boolean; |
| 112 | + clampY(clamp: boolean): this; |
136 | 113 |
|
137 | 114 | /** |
138 | | - * Constructs a new tile layout with the default settings. |
| 115 | + * If tileSize is specified, sets this tile layout’s tile width and height |
| 116 | + * to the specified number tileSize and returns this tile layout. If |
| 117 | + * tileSize is not specified, returns the current layout tile size, which |
| 118 | + * defaults to 256. 256×256 is the most common tile size among tile |
| 119 | + * providers. |
139 | 120 | */ |
140 | | - function tile(): TileLayout; |
| 121 | + tileSize(): number; |
| 122 | + tileSize(tileSize: number): this; |
141 | 123 |
|
142 | 124 | /** |
143 | | - * Given tile coordinates [x, y, z], where x and y may be outside the |
144 | | - * "world" tile [0, 0, 0], returns the wrapped tile coordinates [x′, y′, z] |
145 | | - * where j = 2 ^ z, x′ = x - ⌊x / j⌋ * j and y′ = y - ⌊y / j⌋ * j. This |
146 | | - * function is most commonly used in conjunction with tile.clampX to allow |
147 | | - * horizontal wrapping of web Mercator tiles. |
| 125 | + * If extent is specified, sets this tile layout’s viewport extent to the |
| 126 | + * specified array [[x0, y0], [x1, y1]], where [x0, y0] is the top-left |
| 127 | + * corner and [x1, y1] is the bottom-right corner, and returns this tile |
| 128 | + * layout. If extent is not specified, returns the current viewport |
| 129 | + * extent, which defaults to [[0, 0], [960, 500]]. Setting the viewport |
| 130 | + * extent implicitly sets the viewport size. |
148 | 131 | */ |
149 | | - function tileWrap(tile: [number, number, number]): [number, number, number]; |
| 132 | + extent(): [[number, number], [number, number]]; |
| 133 | + extent(extent: [[number, number], [number, number]]): this; |
150 | 134 | } |
| 135 | + |
| 136 | +/** |
| 137 | + * Constructs a new tile layout with the default settings. |
| 138 | + */ |
| 139 | +export function tile(): TileLayout; |
| 140 | + |
| 141 | +/** |
| 142 | + * Given tile coordinates [x, y, z], where x and y may be outside the |
| 143 | + * "world" tile [0, 0, 0], returns the wrapped tile coordinates [x′, y′, z] |
| 144 | + * where j = 2 ^ z, x′ = x - ⌊x / j⌋ * j and y′ = y - ⌊y / j⌋ * j. This |
| 145 | + * function is most commonly used in conjunction with tile.clampX to allow |
| 146 | + * horizontal wrapping of web Mercator tiles. |
| 147 | + */ |
| 148 | +export function tileWrap(tile: [number, number, number]): [number, number, number]; |
0 commit comments