Skip to content

Instantly share code, notes, and snippets.

@patrykkalinowski
patrykkalinowski / savetiles.js
Created August 29, 2023 08:57
Code to save slippy map tiles to indexedDB as blobs. Uses Dexie
function lon2tile(lon,zoom) {
return (Math.floor((lon+180)/360*Math.pow(2,zoom)))
}
function 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)))
}
async function downloadTile(zoom, column, tile) {
let row = await db.tiles.get({