Skip to content

Instantly share code, notes, and snippets.

@kamataryo
Last active July 5, 2020 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamataryo/4987092fe1975dcf367ad7000858f834 to your computer and use it in GitHub Desktop.
Save kamataryo/4987092fe1975dcf367ad7000858f834 to your computer and use it in GitHub Desktop.
Calculate tile size
// $ npm install turf tilebelt # dependencies
const turf = require("turf");
const tilebelt = require('tilebelt');
const calc = () => {
const lon = 10;
for (let z = 1; z < 31; z++) {
for (let lat = 0; lat < 90; lat += 10) {
const [x, y] = tilebelt.pointToTile(lon, lat, z);
const geometry = tilebelt.tileToGeoJSON([x, y, z]);
const points = geometry.coordinates[0];
let side1 = turf.distance(points[0], points[1]);
let top = turf.distance(points[1], points[2]);
let side2 = turf.distance(points[2], points[3]);
let bottom = turf.distance(points[3], points[4]);
console.log([z, lat, Math.max(bottom, top)].join(","));
}
}
};
calc();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment