Created
July 13, 2021 00:12
-
-
Save cbeddow/32390f22879473cb3137e16a44cb3a26 to your computer and use it in GitHub Desktop.
Tilesplitter example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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