Public
Edited
Dec 14, 2022
Importers
Insert cell
Insert cell
getZXYTile = ({ lat, lng, zoom }) => {
// return ZXY array
return [zoom, lon2tile(lng, zoom), lat2tile(lat, zoom)];
}
Insert cell
lon2tile = (lon, zoom) => {
return Math.floor(((lon + 180) / 360) * Math.pow(2, zoom));
}
Insert cell
lat2tile = (lat, zoom) => {
return Math.floor(
((1 -
Math.log(
Math.tan((lat * Math.PI) / 180) + 1 / Math.cos((lat * Math.PI) / 180)
) /
Math.PI) /
2) *
Math.pow(2, zoom)
);
}
Insert cell
tile2long = (x, z) => {
return (x / Math.pow(2, z)) * 360 - 180;
}
Insert cell
tile2lat = (y, z) => {
var n = Math.PI - (2 * Math.PI * y) / Math.pow(2, z);
return (180 / Math.PI) * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more