Documentation menu
@mapmap/tile reference
Generated from the published @mapmap/tile 0.1.0 type declarations by
website/scripts/sdk-reference.mjs. Do not edit by hand: change the JSDoc in the package, or the examples inwebsite/content/sdk-reference/tile.examples.md, and regenerate.
Every public export of the GeoJSON-to-PMTiles tiler, in the browser and in Node. The command line (mapmap-tile) is described in SDKs & installation.
npm install @mapmap/tile@0.1.0
Other SDK references: @mapmap/maps, @mapmap/points, @mapmap/core, @mapmap/react-native, @mapmap/voice, MapMapKit, ai.mapmap:core.
8 exports across 1 entry point: 4 functions, 3 interfaces, 1 type.
How to read this page
Each entry gives the declaration as published, the JSDoc description, and a table of parameters or properties with their types. The Default column quotes the default the source states (an @default tag or a "Default ..." sentence in the JSDoc). "required" means the property must be given; "not stated" means the source gives no default, so none is claimed here. Classes, factories and the main entry functions each carry a minimal example; examples marked from the source are the package's own @example.
Contents
@mapmap/tile: 8 exports
@mapmap/tile
import { /* … */ } from "@mapmap/tile";
Functions (@mapmap/tile)
init, tile, tileWithReport, version
init
Function
function init(moduleOrPath?: string | URL | Response | WebAssembly.Module): Promise<unknown>;
Load the WASM (browser only; a no-op in Node). tile calls it for you.
| Parameter | Type | Default | Description |
|---|---|---|---|
moduleOrPath? | string | URL | Response | WebAssembly.Module | not stated |
Example
import { init, version } from "@mapmap/tile";
// Optional: tile() loads the WASM itself. Call init() first to load it early, or to read version().
await init();
console.log(version());
tile
Function
function tile(input: TileInput, options?: TileOptions): Promise<Uint8Array>;
Tile GeoJSON into a .pmtiles archive. Rejects with an Error naming the problem.
| Parameter | Type | Default | Description |
|---|---|---|---|
input | TileInput | required | |
options? | TileOptions | not stated |
Options and types: TileInput, TileOptions.
Example
import { tile } from "@mapmap/tile";
const geojson = await (await fetch("/sites.geojson")).text();
const archive = await tile(geojson, { layer: "sites", maxzoom: 12, attribution: "© OpenStreetMap contributors" });
const url = URL.createObjectURL(new Blob([archive as BlobPart], { type: "application/vnd.pmtiles" }));
console.log(url);
tileWithReport
Function
function tileWithReport(input: TileInput, options?: TileOptions): Promise<{
archive: Uint8Array;
report: TileReport;
}>;
As tile, with the counts the CLI prints.
| Parameter | Type | Default | Description |
|---|---|---|---|
input | TileInput | required | |
options? | TileOptions | not stated |
Options and types: TileInput, TileOptions.
Example
import { tileWithReport } from "@mapmap/tile";
const { archive, report } = await tileWithReport('{"type":"FeatureCollection","features":[]}', {
onProgress: (p) => console.log(`zoom ${p.zoom}: ${p.tiles} tiles`),
});
console.log(report.features, report.tiles, report.bounds, archive.byteLength);
version
Function
function version(): string;
The package version. In the browser, call after init().
Interfaces (@mapmap/tile)
TileOptions, TileProgress, TileReport
TileOptions
Interface
interface TileOptions
| Property | Type | Default | Description |
|---|---|---|---|
layer? | string | "data" | MVT layer name: the source-layer your style references. Default "data". |
minzoom? | number | 0 | Shallowest zoom to build. Default 0. |
maxzoom? | number | 14 | Deepest zoom to build, at most 22. Default 14; renderers overzoom past it. |
name? | string | the layer name | Title recorded in the archive metadata. Default: the layer name. |
attribution? | string | not stated | Credit recorded in the archive metadata. ODbL requires one for OpenStreetMap-derived data. |
format? | "auto" | "geojson" | "geojsonl" | "auto": one document is GeoJSON, one per line is GeoJSON Lines | How to read the input. Default "auto": one document is GeoJSON, one per line is GeoJSON Lines. |
maxInputBytes? | number | 256 MiB | Refuse inputs larger than this. Default 256 MiB. |
onProgress? | (progress: TileProgress) => void | not stated | Called after each zoom level. |
TileProgress
Interface
interface TileProgress
Progress after each zoom level.
| Property | Type | Default | Description |
|---|---|---|---|
zoom | number | required | The zoom just finished. |
tiles | number | required | Tiles written so far, across every zoom. |
minzoom | number | required | First zoom of the run. |
maxzoom | number | required | Last zoom of the run. |
TileReport
Interface
interface TileReport
| Property | Type | Default | Description |
|---|---|---|---|
layer | string | required | |
features | number | required | Features read from the input. |
tiles | number | required | Tiles written. |
perZoom | Record<string, number> | required | Tiles per zoom, keyed by zoom. A zoom where every feature is too small to draw has 0. |
bounds | [number, number, number, number] | required | [west, south, east, north] in degrees. |
minzoom | number | required | Shallowest zoom the archive holds tiles for. |
maxzoom | number | required | Deepest zoom the archive holds tiles for. |
bytes | number | required | Archive size in bytes. |
Types (@mapmap/tile)
TileInput
Type
type TileInput = string | Uint8Array | ArrayBuffer | ArrayBufferView;
GeoJSON or GeoJSON Lines, as text or UTF-8 bytes.