|
| 1 | +import { ZoomTransform } from "d3"; |
| 2 | + |
| 3 | +declare module "d3" { |
| 4 | + type Tile = [number, number, number]; |
| 5 | + |
| 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; |
| 34 | + |
| 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; |
| 47 | + |
| 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; |
| 66 | + |
| 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; |
| 81 | + |
| 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; |
| 90 | + |
| 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; |
| 102 | + |
| 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; |
| 114 | + |
| 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; |
| 124 | + |
| 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 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * Constructs a new tile layout with the default settings. |
| 139 | + */ |
| 140 | + function tile(): TileLayout; |
| 141 | + |
| 142 | + /** |
| 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. |
| 148 | + */ |
| 149 | + function tileWrap(tile: [number, number, number]): [number, number, number]; |
| 150 | +} |
0 commit comments