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

v0.1.6

Published

Map tile rendering guided by a Mapbox style document

Downloads

15

Readme

tile-kiln

Map tile rendering guided by a Mapbox style document

Inputs map data (both raster and vector) and renders it into tiles. Styling is guided by a document following the Mapbox style specification.

Please note: many features in Mapbox's specification are not implemented. tile-kiln is intended to be an 80/20 solution for vector tile rendering: implementing ~80% of the style specification with 20% of the code.

Note also: to make the code simpler, rendering is done with [Canvas 2D] methods, rather than trying to re-implement basic things (like drawing lines) in WebGL. This necessarily means that tile-kiln will be slower than WebGL renderers. If you just need a fast, full-featured vector map, try Mapbox GL JS.

Check out the simple single-tile example with dynamic style changes. Like the simple code, but need one more feature? We welcome pull requests!

Layer Groups

tile-kiln implements layer groups as an extension to the style specification. These enable pre-rendering of groups of layers. The styles or data for a group can be modified, and the re-rendered group can then be re-composited with the other groups, without needing to re-render the other groups.

To define layer groups, simply add the following property to the style of EVERY layer:

"tilekiln-group": "<group-name>",

Note that the style layers for any group MUST be listed in order, not interleaved.

To re-render one layer group, first modify the styles for the group as needed. Then set

tile.laminae[groupName].rendered = false;
tile.rendered = false;

and call tileKiln.redraw(tile). Layer groups with

tile.laminae[group].rendered === true && tile.laminae[group].visible === true

will simply be re-composited into the final image, without change.

Initialization

tileKiln.init takes a parameter object with the following properties:

  • style (REQUIRED): A URL pointing to a Mapbox style document.
  • token (OPTIONAL): A Mapbox API token. Required if style URL and tile endpoints follow the Mapbox shorthand (mapbox://...).
  • size (OPTIONAL): The size in pixels of the rendered tiles (always square). Defaults to 512.
  • callback (OPTIONAL): A function which will be executed when the initialization is complete.

Initialization is asynchronous because of the HTTP calls to retrieve the style document, and any TileJSON documents referenced from within the style.

API

Initialization returns an object with the following properties:

  • style: A link to the style document.
  • groups: An array of the group names found in the supplied style document.
  • create(z, x, y\[, callback\]): Creates a new tile object at the specified z/x/y indices. Immediately returns the object, but requests data and renders it asynchronously. Optionally executes callback when complete.
  • hideGroup(name): Sets visibility = false for the supplied layer group name.
  • showGroup(name): Sets visibility = true for the supplied layer group name.
  • redraw(tile\[, callback\]): re-renders an existing tile (e.g., after a change to the style document). Assumes all the data for the tile has already been loaded and parsed. For layer groups: only re-renders the layers within the group IF group.rendered = false AND group.visible = true.
  • activeDrawCalls(): Returns the number of tiles in the rendering queue.
  • sortTasks(ranking): Re-orders the rendering tasks in the queue, based on the value of ranking(tile.id). Tasks with a smaller ranking value will be rendered first (starting from rank 1).
  • ready: A (Boolean) flag indicating whether the kiln is ready to start making tiles (i.e., styles have been loaded and parsed).