colouring-montreal/app/src/tiles/util.ts

29 lines
547 B
TypeScript
Raw Normal View History

2019-09-17 12:54:35 -04:00
import SphericalMercator from '@mapbox/sphericalmercator';
import { TileParams } from './types';
const TILE_SIZE = 256;
const mercator = new SphericalMercator({
size: TILE_SIZE
});
function getBbox(z, x, y) {
return mercator.bbox(x, y, z, false, '900913');
}
function getXYZ(bbox, z) {
return mercator.xyz(bbox, z, false, '900913')
}
function formatParams({ tileset, z, x, y, scale }: TileParams): string {
return `${tileset}/${z}/${x}/${y}@${scale}x`;
}
export {
TILE_SIZE,
getBbox,
getXYZ,
formatParams
};