gis-tools-ts
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
62 lines • 2.21 kB
JavaScript
import { TileStore, fileTypeToReader } from '../../index.js';
/**
* # Server Tile Worker
*
* A worker that, given a source and options, fetches the data, converts it to tiles,
* and handles requests
*/
class TileWorker {
/**
* Tile-ize input vector features and store them
* @param event - the init message or a feature message
*/
onmessage(event) {
const { data } = event;
if (data.type === 'init') {
if (event.ports !== undefined && event.ports.length !== 0)
this.
void this.
}
else if (event.type === 'tilerequest')
this.
}
/**
* Load worker. First message that comes in upon creation of this worker
* @param messagePort - the communication port to talk listen to a source worker's messages
* @param postPort - the communication port to send messages to the source worker
*/
this.
messagePort.onmessage = this.onmessage.bind(this);
}
/**
* Handle an init message
* @param event - the init message
*/
async
// setup reader and store, then build
const reader = await fileTypeToReader(event.url, event.inputType);
this.
await this.
}
/**
* Handle a tile request
* @param event - the tile request
*/
const { id } = event;
const tile = this.
const data = this.
const message = { type: 'tileresponse', id, data };
if (this.
this.
else
self.postMessage(message);
}
}
const tileWorker = new TileWorker();
self.onmessage = tileWorker.onmessage.bind(tileWorker);
//# sourceMappingURL=tileserve.worker.js.map