s2-tools
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
77 lines • 2.82 kB
TypeScript
import { PointCluster, PointIndex } from '../../../dataStructures';
import type { MultiMapStore } from '../../../dataStore';
import type { LayerGuide, StringifiedLayerGuide } from '../..';
import type { ElevationPoint, RGBA } from '../../..';
import type { Encoding, Scheme } from 's2-tilejson';
import type { Face, Features, Properties, VectorFeatures } from '../../../geometry';
/** Take in options that will be used to create a tiled data correctly */
export interface InitMessage {
/** Message type */
type: 'init';
/** id of the worker */
id: number;
/** The sources that will be used to create the tile */
layerGuides: StringifiedLayerGuide[];
/** The scheme that will be used to decide the projection and store method */
scheme?: Scheme;
/** The encoding that will be used to compress the tile */
encoding?: Encoding;
}
/** Take in a feature that will be added to the tile */
export interface FeatureMessage {
/** Message type */
type: 'feature';
/** The name of the source to add the feature to */
sourceName: string;
/** The feature to add to the tile */
feature: Features;
}
/** We want to track the associated layer for each feature */
export interface FeatureMetadata extends Properties {
layerName: string;
}
/** A built tile that is ready to be written to the filesystem */
export interface BuiltTile {
face: Face;
zoom: number;
x: number;
y: number;
data: Uint8Array;
}
/** Convert a vector feature to a collection of tiles and store each tile feature */
export default class VectorTileWorker {
#private;
id: number;
layerGuides: LayerGuide[];
scheme: Scheme;
encoding: Encoding;
vectorStore: MultiMapStore<VectorFeatures<FeatureMetadata>>;
clusterStores: {
[layerName: string]: PointCluster;
};
rasterStore: PointIndex<RGBA>;
elevationStore: PointIndex<ElevationPoint>;
/**
* Tile-ize input vector features and store them
* @param event - the init message or a feature message
*/
onmessage(event: Bun.MessageEvent<InitMessage | FeatureMessage>): void;
/**
* Tile-ize input vector features and store them
* @param message - the init message or a feature message
*/
handleMessage(message: InitMessage | FeatureMessage): void;
/** Iterate through all the stores and sort/cluster as needed */
sort(): Promise<void>;
/**
* Iterate through the stores and build tiles, gzip compressing as we go
* @yields - a built tile
*/
buildTiles(): AsyncGenerator<BuiltTile>;
/**
* Store a feature across all appropriate zooms
* @param message - the message to pull the feature and source info from
*/
storeFeature(message: FeatureMessage): void;
}
//# sourceMappingURL=tileWorker.d.ts.map