UNPKG

s2maps-gpu

Version:

S2 Maps GPU - An open source, high-performance, and GPU-accelerated map engine for rendering large-scale, interactive maps.

42 lines (41 loc) 1.5 kB
import { S2PMTilesReader } from 'gis-tools/index.js'; import Source from './source.js'; /** * # S2 PMTiles Source * * Wrapper for the `S2PMTilesReader`. Fetch tiles as needed. */ export default class S2PMTilesSource extends Source { version = 1; reader; /** @param mapID - the id of the map to build tiles for */ async build(mapID) { this.reader = new S2PMTilesReader(this.path, true); const metadata = await this.reader.getMetadata(); // modify the type to ensure we are using a vector metadata.type = 'vector'; this._buildMetadata(metadata, mapID); } /** * Here, we use the memory mapped file directory tree system to find our data * @param mapID - the id of the map * @param tile - the tile request * @param sourceName - the name of the source */ async _tileRequest(mapID, tile, sourceName) { const { type, session, size } = this; const { parent, type: tileType } = tile; const { face, zoom, i, j } = parent ?? tile; const bytes = tileType === 'S2' ? await this.reader.getTileS2(face, zoom, i, j) : await this.reader.getTile(zoom, i, j); if (bytes !== undefined) { const data = bytes.buffer; const worker = session.requestWorker(); worker.postMessage({ mapID, type, tile, sourceName, data, size }, [data]); } else { this._flush(mapID, tile, sourceName); } } }