UNPKG

s2maps-gpu

Version:

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

93 lines (92 loc) 3.11 kB
/** Local Source */ export default class LocalSource { name; isTimeFormat = false; styleLayers; session; textEncoder = new TextEncoder(); /** * @param name - the name of the source * @param session - the session * @param layers - the layers */ constructor(name, session, layers) { this.name = name; this.session = session; this.styleLayers = layers; } /** a no-op for local sources; nothing to build */ build() { /* no-op */ } /** * Get a tile * @param mapID - the map requesting the tile * @param tile - the tile request * @param flushMessage - the flush message to send a report to */ tileRequest(mapID, tile, flushMessage) { const { id, face, zoom, i, j } = tile; this.#flush(flushMessage); const data = { face, zoom, i, j, extent: 1, layers: { boundary: { extent: 1, length: 1, features: [ { extent: 1, properties: { id: String(id), face, zoom, i, j }, geometry: { type: 'Polygon', is3D: false, coordinates: [ [ { x: 0, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 1 }, { x: 0, y: 1 }, { x: 0, y: 0 }, ], ], }, }, ], }, name: { extent: 1, length: 1, features: [ { extent: 1, properties: { id: String(id), face, zoom, i, j }, geometry: { type: 'Point', is3D: false, coordinates: { x: 0.5, y: 0.5 }, }, }, ], }, }, }; // encode for transfer const uint8data = this.textEncoder.encode(JSON.stringify(data)).buffer; // request a worker and post const worker = this.session.requestWorker(); worker.postMessage({ mapID, type: 'jsondata', tile, sourceName: name, data: uint8data }, [ uint8data, ]); } /** @param flushMessage - flushMessage */ #flush(flushMessage) { const layers = this.styleLayers.filter((layer) => layer.source === this.name); for (const { layerIndex } of layers) flushMessage.layersToBeLoaded.add(layerIndex); } }