npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tile-worker

v0.1.8

Published

Load and parse map tiles on Web Worker threads

Downloads

23

Readme

tile-worker

tests

Load and parse map tiles on Web Worker threads

Tiles are requested (via HTTP) from the URL endpoints specified in one of the sources specified in a MapLibre style document's 'sources' property. The returned tile data is parsed from the vector tile format to GeoJSON. This part of the work is delegated to the tile-retriever module.

The GeoJSON data is then re-mixed to a new set of layers defined by the style layers in the style document. The re-mixed data is also converted to WebGL buffers and other custom structures that can be rendered more quickly, e.g. by tile-setter. This part of the work is delegated to the tile-mixer module.

tile-worker manages tile-retriever and tile-mixer instances on Web Worker threads. The buffer data returned from the Workers is then loaded to the GPU. Loading tasks are broken up into chunks and submitted one at a time via the chunked-queue module, to avoid jank on the main thread.

Initialization

A tile-worker instance can be initialized as follows:

import * as tileWorker from 'tile-worker';

const loader = tileWorker.init(parameters);

The supplied parameters object has the following properties

  • threads: Number of Web Workers that will be used to load and parse tiles from the API. Default: 2
  • context: A WebGL context wrapper, as created by the tile-gl method initGLpaint. The returned buffer data will be loaded to the WebGL context by this wrapper
  • queue: an instance of chunked-queue to use for managing long-running tasks. If not supplied, tile-mixer will initialize its own queue
  • source: The desired source value from the 'sources' property of the style document. Note that any 'url' property will be ignored. The relevant TileJSON properties MUST be supplied directly. REQUIRED
  • glyphs: The glyphs property from the style document. Used for processing text labels in symbol layers
  • spriteData: The data referenced in the sprite property from the style document, loaded into an object with properties { image, meta }, as returned by tile-stencil
  • layers: An array containing the layers from the style document that use data from the specified source. REQUIRED

API

Initialization returns an object that you can use to request and process a tile, as follows:

const request = loader.request({ z, x, y, getPriority, callback });

where the parameters are:

  • z, x, y (REQUIRED): The coordinate indices of the desired tile
  • getPriority: An optional function (with no arguments) that will return the current priority of this tile. This can be used to dynamically prioritize loading tasks. See chunked-queue for details
  • callback (REQUIRED): A callback function which will be executed with the signature callback(error, data) when the request is complete

The return value is a request handle, which can be used to cancel the request as follows:

request.abort();

Other API methods on the loader object include:

  • .activeTasks(): Returns the (integer) number of active tasks
  • .workerTasks(): Returns the number of tasks active on worker threads
  • .queuedTasks(): Returns the number of tasks queued on the main thread
  • .terminate(): Cancels all tasks and terminates the Web Workers