UNPKG

s2maps-gpu

Version:

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

68 lines (67 loc) 2.9 kB
import { GlyphSource, ImageSource, JSONSource, LocalSource, MarkerSource, S2PMTilesSource, S2TilesSource, Session, Source, SpriteSource, TexturePack } from './source/index.js'; import type { UrlMap } from 'util/index.js'; import type { Analytics, GPUType, LayerDefinition, Projection } from 'style/style.spec.js'; import type { SourceWorkerMessages } from './worker.spec.js'; /** Store map of all source types */ type SourceMap = Record<string, Source | S2PMTilesSource | S2TilesSource | JSONSource | LocalSource | MarkerSource>; /** Each map has it's own store of these properties */ interface Map { projection: Projection; gpuType: GPUType; minzoom: number; maxzoom: number; analytics: Analytics; experimental: boolean; sources: SourceMap; layers: LayerDefinition[]; glyphs: Record<string, GlyphSource>; sprites: Record<string, SpriteSource>; /** e.g. { apiURL: string, ... } */ urls: UrlMap; texturePack: TexturePack; images: ImageSource; } /** * # SOURCE WORKER * * The source worker builds the appropriate module defined * by the style "sources" object. All tile requests are forwarded to the source * worker, where the worker properly builds the requests. Upon creation of a request, * the request string is passed to a tile worker to run the fetch and then consequently * process. * * GEOJSON / S2JSON is a unique case where the source worker just builds the json * locally to avoid processing the same json multiple times per tile worker. * * The glyph map is processed by the source worker. All data is localized to * the source worker. When a tile worker requests glyph data, the source will * scale up the map and send off the x-y position along with the width-height of * each glyph requested. * * SOURCE TYPES * S2Tile - a compact s2tiles file where we request tiles of many file types and compression types * GeoJSON - a json file containing geo-spatial data * S2JSON - a json file modeled much like geojson * Glyph - either a font or icon file stored in a pbf structure * LocalSource -> local build tile information * default -> assumed the location has a metadata. json at root with a "s2cellid.ext" file structure * * SESSION TOKEN * This is a pre-approved JWT token for any calls made to api.opens2.com or api.s2maps.io * when building requests, we take the current time, run a black box digest to hash, and return: * { h: 'first-five-chars', t: '1620276149967' } // h -> hash ; t -> timestamp ('' + Date.now()) * (now - timestamp) / 1000 = seconds passed */ export default class SourceWorker { #private; workers: Array<MessageChannel['port2']>; session: Session; /** { mapID: Map } */ maps: Record<string, Map>; /** * Handle source worker's messages * @param msg - incoming message */ onMessage(msg: MessageEvent<SourceWorkerMessages>): void; } export {};