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-retriever

v0.0.7

Published

Load vector tiles from sources described in MapLibre style documents

Downloads

20

Readme

tile-retriever

tests

Load vector tiles from sources described in MapLibre style documents

tile-retriever inputs a source object from a MapLibre style document, and constructs a tile retriever function.

The retriever function inputs a set of tile coordinates of the form { z, x, y } and a callback function. It then retrieves the tile from the endpoints specified in the source, and executes the callback function with the tile's layers and features as a dictionary of GeoJSON FeatureCollections.

Using tile-retriever, you can play with the basic demo, build your own GIS code from scratch, or anything in between!

Initialization

A new tile retriever function is instantiated as follows:

import * as tileRetriever from "tile-retriever";

const retrieve = tileRetriever.init({ source, defaultID });

where the initialization parameters are:

  • .source (REQUIRED): A MapLibre source object. MUST be of type vector or geojson, with all external information (TileJSON description, or GeoJSON data) already retrieved and present in the object (NOT linked via URLs). You can ensure the data is already retrieved by loading the style with the .loadStyle method from tile-stencil
  • .defaultID: Only relevant for GeoJSON sources. Will be used as the layer name for the retrieved GeoJSON

Requesting a tile

The retriever function has the following signature:

const request = retrieve(tileCoords, callback);

where tileCoords has properties { z, x, y }, corresponding to the indices of the desired tile.

If you call the retrieve function, and then decide you don't need the tile, you can abort the request using the returned request object:

request.abort();

Handling the returned tile data

The callback supplied to the retrieve function has the following signature

function callback(error, json) {
  if (error) throw error;

  console.log(json);
}

The returned JSON data is a dictionary of layers, keyed on the original name from the source vector tile layer. (For geojson sources, there will only be one layer, with the key being the supplied defaultID.) The value of each layer is a GeoJSON FeatureCollection.

Example:

{
  "layer1": { "type": "FeatureCollection", "features": [...] },
  "layer2": { "type": "FeatureCollection", "features": [...] },
  ...
}