Skip to content

Instantly share code, notes, and snippets.

@cbeddow
Created July 13, 2021 00:12
Show Gist options
  • Save cbeddow/32390f22879473cb3137e16a44cb3a26 to your computer and use it in GitHub Desktop.
Save cbeddow/32390f22879473cb3137e16a44cb3a26 to your computer and use it in GitHub Desktop.
Tilesplitter example
interface TileCoords {
x: number;
y: number;
z: number;
}
const getParentTileCoords = (childTile: TileCoords, parentLevel: number): TileCoords => {
const deltaZ = childTile.z - parentLevel;
const scale = Math.pow(2, deltaZ);
return {
'x': Math.floor(childTile.x / scale),
'y': Math.floor(childTile.y / scale),
'z': parentLevel,
};
}
const buildTileURL = (template: string, tileCoords: TileCoords): string => {
return template
.replace('[[x]]', `${tileCoords.x}`)
.replace('[[y]]', `${tileCoords.y}`)
.replace('[[z]]', `${tileCoords.z}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment