Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions types/d3-tile/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!**/*.d.ts
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
93 changes: 93 additions & 0 deletions types/d3-tile/d3-tile-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import * as d3 from "d3";

// test variables
let tileLayout: d3.TileLayout;
let tile: d3.Tile;
let tiles: d3.Tiles;
let zoomTransform: d3.ZoomTransform;

// test tile() constructor
tileLayout = d3.tile();

// test invoke with no arguments
tiles = tileLayout();

// test invoke with ZoomTransform argument
zoomTransform = d3.zoomTransform(document.createElement("svg"));
tiles = tileLayout(zoomTransform);

// test size getter/setter
let sizeValue: [number, number] = tileLayout.size();
tileLayout = tileLayout.size([800, 600]);

// test scale getter/setter with number
let scaleFunc: (...args: any[]) => number = tileLayout.scale();
tileLayout = tileLayout.scale(256);
tileLayout = tileLayout.scale((...args: any[]) => 256);

// test translate getter/setter with array
let translateFunc: (...args: any[]) => [number, number] = tileLayout.translate();
tileLayout = tileLayout.translate([0, 0]);
tileLayout = tileLayout.translate((...args: any[]) => [0, 0]);

// test zoomDelta getter/setter
let zoomDeltaValue: number = tileLayout.zoomDelta();
tileLayout = tileLayout.zoomDelta(0);
tileLayout = tileLayout.zoomDelta(-1);
tileLayout = tileLayout.zoomDelta(1);

// test clamp getter/setter
let clampValue: boolean = tileLayout.clamp();
tileLayout = tileLayout.clamp(true);
tileLayout = tileLayout.clamp(false);

// test clampX getter/setter
let clampXValue: boolean = tileLayout.clampX();
tileLayout = tileLayout.clampX(true);
tileLayout = tileLayout.clampX(false);

// test clampY getter/setter
let clampYValue: boolean = tileLayout.clampY();
tileLayout = tileLayout.clampY(true);
tileLayout = tileLayout.clampY(false);

// test tileSize getter/setter
let tileSizeValue: number = tileLayout.tileSize();
tileLayout = tileLayout.tileSize(256);
tileLayout = tileLayout.tileSize(512);

// test extent getter/setter
let extentValue: [[number, number], [number, number]] = tileLayout.extent();
tileLayout = tileLayout.extent([[0, 0], [960, 500]]);
tileLayout = tileLayout.extent([[0, 0], [1920, 1080]]);

// test tiles array properties
let tilesLength: number = tiles.length;
let tilesScale: number = tiles.scale;
let tilesTranslate: [number, number] = tiles.translate;

// test tile coordinates
for (let i = 0; i < tiles.length; i++) {
let tileCoord: d3.Tile = tiles[i];
let x: number = tileCoord[0];
let y: number = tileCoord[1];
let z: number = tileCoord[2];
}

// test tileWrap function
let wrappedTile: [number, number, number] = d3.tileWrap([1, 2, 3]);
let wrappedX: number = wrappedTile[0];
let wrappedY: number = wrappedTile[1];
let wrappedZ: number = wrappedTile[2];

// test method chaining
tileLayout
.size([800, 600])
.scale(256)
.translate([0, 0])
.zoomDelta(0)
.clamp(true)
.clampX(true)
.clampY(true)
.tileSize(256)
.extent([[0, 0], [960, 500]]);
150 changes: 150 additions & 0 deletions types/d3-tile/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import { ZoomTransform } from "d3";

declare module "d3" {
type Tile = [number, number, number];

interface Tiles extends Array<Tile> {
translate: [number, number];
scale: number;
}

interface TileLayout {
/**
* Computes the set of tiles to display given the current settings,
* computing the scale and translate by invoking the corresponding
* accessors with the given arguments. Returns an array of [x, y, z]
* arrays representing the x- (horizontal), y- (vertical) and z- (zoom)
* coordinates of the visible tiles. The returned tiles array also has
* tiles.scale and tiles.translate properties which together with an
* individual tile’s x and y determine the intended location of the tile
* in the viewport.
*/
(): Tiles;
(t: ZoomTransform): Tiles;

/**
* If size is specified, sets this tile layout’s viewport size to the
* specified array of numbers [width, height] and returns this tile
* layout. If size is not specified, returns the current viewport size,
* which defaults to [960, 500]. This is a convenience method for setting
* the viewport extent to [[0, 0], [width, height]].
*/
size(): [number, number];
size(size: [number, number]): this;

/**
* If scale is specified, sets this tile layout’s scale function and
* returns this tile layout. If scale is a function, it is invoked when
* the tile layout is invoked, being passed the same arguments as the tile
* layout; this function must return a number indicating the desired width
* and height of the world tile [0, 0, 0]. If scale is not a function, it
* assumed to be a constant number, and is wrapped in a function which
* returns the specified number. If scale is not specified, returns the
* current layout scale function.
*/
scale(): (...args: any[]) => number;
scale(scale: number | ((...args: any[]) => number)): this;

/**
* If translate is specified, sets this tile layout’s translate function
* and returns this tile layout. If translate is a function, it is invoked
* when the tile layout is invoked, being passed the same arguments as the
* tile layout; this function must return an array of numbers [x, y]
* indicating the desired coordinates the center of the world tile [0, 0,
* 0]. If translate is not a function, it is assumed to be a constant
* array [x, y] and is wrapped in a function which returns the specified
* array. If translate is not specified, returns the current layout
* translate function.
*/
translate(): (...args: any[]) => [number, number];
translate(
translate: [
number,
number,
] | ((...args: any[]) => [number, number]),
): this;

/**
* If zoomDelta is specified, sets this tile layout’s zoom offset to the
* specified number zoomDelta and returns this tile layout. If zoomDelta
* is not specified, returns the current zoom offset, which defaults to 0.
* The zoom offset affects which z-coordinate is chosen based on the
* current scale; the default zoom offset of 0 which choose the z that is
* closest the displayed size; a zoom offset of -1 will use z - 1, giving
* tiles that are twice as big (lower resolution); a zoom offset of +1
* will use z + 1, giving tiles that are twice as small (higher
* resolution). The latter might be appropriate for showing 256×256 tiles
* in a 128×128 space on a high-resolution screen.
*/
zoomDelta(): number;
zoomDelta(zoomDelta: number): this;

/**
* If clamp is specified, sets tile.clampX and tile.clampY to the
* specified boolean clamp and returns this tile layout. If clamp is not
* specified, returns true if tile.clampX and tile.clampY are both true,
* and false otherwise.
*/
clamp(): boolean;
clamp(clamp: boolean): this;

/**
* If clamp is specified, sets whether or not the visible tiles will be
* clamped in the x-coordinate and returns this tile layout. If clamp is
* not specified, returns the current x-clamp, which defaults to true. If
* the x-clamp is false, then the tile layout will return tiles that are
* outside the “world” tile [0, 0, 0], with x-coordinates that are outside
* the normal bounds 0 ≤ x < 2^z. See d3.tileWrap for converting these
* coordinates to wrapped in-world coordinates.
*/
clampX(): boolean;
clampX(clamp: boolean): this;

/**
* If clamp is specified, sets whether or not the visible tiles will be
* clamped in the y-coordinate and returns this tile layout. If clamp is
* not specified, returns the current y-clamp, which defaults to true. If
* the y-clamp is false, then the tile layout will return tiles that are
* outside the “world” tile [0, 0, 0], with y-coordinates that are outside
* the normal bounds 0 ≤ y < 2^z. See d3.tileWrap for converting these
* coordinates to wrapped in-world coordinates. See also tile.clampX.
*/
clampY(): boolean;
clampY(clamp: boolean): this;

/**
* If tileSize is specified, sets this tile layout’s tile width and height
* to the specified number tileSize and returns this tile layout. If
* tileSize is not specified, returns the current layout tile size, which
* defaults to 256. 256×256 is the most common tile size among tile
* providers.
*/
tileSize(): number;
tileSize(tileSize: number): this;

/**
* If extent is specified, sets this tile layout’s viewport extent to the
* specified array [[x0, y0], [x1, y1]], where [x0, y0] is the top-left
* corner and [x1, y1] is the bottom-right corner, and returns this tile
* layout. If extent is not specified, returns the current viewport
* extent, which defaults to [[0, 0], [960, 500]]. Setting the viewport
* extent implicitly sets the viewport size.
*/
extent(): [[number, number], [number, number]];
extent(extent: [[number, number], [number, number]]): this;
}

/**
* Constructs a new tile layout with the default settings.
*/
function tile(): TileLayout;

/**
* Given tile coordinates [x, y, z], where x and y may be outside the
* "world" tile [0, 0, 0], returns the wrapped tile coordinates [x′, y′, z]
* where j = 2 ^ z, x′ = x - ⌊x / j⌋ * j and y′ = y - ⌊y / j⌋ * j. This
* function is most commonly used in conjunction with tile.clampX to allow
* horizontal wrapping of web Mercator tiles.
*/
function tileWrap(tile: [number, number, number]): [number, number, number];
}
20 changes: 20 additions & 0 deletions types/d3-tile/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"private": true,
"name": "@types/d3-tile",
"version": "1.0.9999",
"projects": [
"https://github.com/d3/d3-tile"
],
"dependencies": {
"@types/d3": "*"
},
"devDependencies": {
"@types/d3-tile": "workspace:."
},
"owners": [
{
"name": "Mouad Naciri",
"githubUsername": "NaciriMouad"
}
]
}
21 changes: 21 additions & 0 deletions types/d3-tile/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"module": "node16",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true
},
"files": [
"index.d.ts",
"d3-tile-tests.ts"
]
}
Loading