https://github.com/screamz/tiles-downloader
A small library to download map tiles
https://github.com/screamz/tiles-downloader
Last synced: 10 months ago
JSON representation
A small library to download map tiles
- Host: GitHub
- URL: https://github.com/screamz/tiles-downloader
- Owner: ScreamZ
- Created: 2024-11-17T14:45:48.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-05T17:41:04.000Z (over 1 year ago)
- Last Synced: 2025-04-19T12:34:41.438Z (about 1 year ago)
- Language: TypeScript
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Tiles downloader
> [!IMPORTANT]
> This module is ESM only.
This module allows you to download tiles from a tile server. Therefore you can use it to download tiles from OpenStreetMap, etc. for offline use or caching.
## Installation
```sh
npm install @codingspark/tiles-downloader
```
## Example usage
### Tiles downloading
Generic tiles download using `fetch` that works in browser and most server environments.
```ts
import path from "node:path";
import { downloadTiles } from "@codingspark/tiles-downloader";
await downloadTiles(
{
url: "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
zoomLevels: [14, 15, 16],
throttleConfig: { limit: 3, interval: 1000 },
bounds: {
minLat: 43.5704,
maxLat: 43.645,
minLon: 3.8095,
maxLon: 3.923,
},
},
async ({ x, y, z, buffer }) => {
const outputPath = path.join(
"./map",
z.toString(),
x.toString(),
`${y}.png`
);
console.log(`Writing tile ${z}/${x}/${y}`);
// Using bun but use anything you want to write the buffer to a file
Bun.write(outputPath, buffer);
}
);
```
### Generate tiles for a specific area
This can be useful if you want to only get tiles for a specific need or you want to manage downloading tiles by yourself.
```ts
import { computeTiles } from "@codingspark/tiles-downloader";
const tiles = computeTiles({
bounds: {
minLat: 43.5704,
maxLat: 43.645,
minLon: 3.8095,
maxLon: 3.923,
},
zoomLevels: [14, 15, 16],
});
```