Skip to content
Documentation menu
docs / tile-reference · raw .md

@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 in website/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.

bash
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

ts
import { /* … */ } from "@mapmap/tile";

Functions (@mapmap/tile)

init, tile, tileWithReport, version

init

Function

ts
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.

ParameterTypeDefaultDescription
moduleOrPath?string | URL | Response | WebAssembly.Modulenot stated

Example

ts
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

ts
function tile(input: TileInput, options?: TileOptions): Promise<Uint8Array>;

Tile GeoJSON into a .pmtiles archive. Rejects with an Error naming the problem.

ParameterTypeDefaultDescription
inputTileInputrequired
options?TileOptionsnot stated

Options and types: TileInput, TileOptions.

Example

ts
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

ts
function tileWithReport(input: TileInput, options?: TileOptions): Promise<{
    archive: Uint8Array;
    report: TileReport;
}>;

As tile, with the counts the CLI prints.

ParameterTypeDefaultDescription
inputTileInputrequired
options?TileOptionsnot stated

Options and types: TileInput, TileOptions.

Example

ts
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

ts
function version(): string;

The package version. In the browser, call after init().

Interfaces (@mapmap/tile)

TileOptions, TileProgress, TileReport

TileOptions

Interface

ts
interface TileOptions
PropertyTypeDefaultDescription
layer?string"data"MVT layer name: the source-layer your style references. Default "data".
minzoom?number0Shallowest zoom to build. Default 0.
maxzoom?number14Deepest zoom to build, at most 22. Default 14; renderers overzoom past it.
name?stringthe layer nameTitle recorded in the archive metadata. Default: the layer name.
attribution?stringnot statedCredit 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 LinesHow to read the input. Default "auto": one document is GeoJSON, one per line is GeoJSON Lines.
maxInputBytes?number256 MiBRefuse inputs larger than this. Default 256 MiB.
onProgress?(progress: TileProgress) => voidnot statedCalled after each zoom level.

TileProgress

Interface

ts
interface TileProgress

Progress after each zoom level.

PropertyTypeDefaultDescription
zoomnumberrequiredThe zoom just finished.
tilesnumberrequiredTiles written so far, across every zoom.
minzoomnumberrequiredFirst zoom of the run.
maxzoomnumberrequiredLast zoom of the run.

TileReport

Interface

ts
interface TileReport
PropertyTypeDefaultDescription
layerstringrequired
featuresnumberrequiredFeatures read from the input.
tilesnumberrequiredTiles written.
perZoomRecord<string, number>requiredTiles 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.
minzoomnumberrequiredShallowest zoom the archive holds tiles for.
maxzoomnumberrequiredDeepest zoom the archive holds tiles for.
bytesnumberrequiredArchive size in bytes.

Types (@mapmap/tile)

TileInput

TileInput

Type

ts
type TileInput = string | Uint8Array | ArrayBuffer | ArrayBufferView;

GeoJSON or GeoJSON Lines, as text or UTF-8 bytes.