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

leaflet.vectortiles

v0.0.1

Published

Render vector tiles on an L.GridLayer with an L.Canvas renderer

Downloads

4

Readme

Leaflet.VectorTiles

Render (GeoJSON) vector tiles on an L.GridLayer with an L.Canvas renderer

This extension also includes L.FontCanvas which extends L.Canvas with the capability of rendering fonts (useful for icon fonts).

API documentation is in API.md.

Dependencies

  • Leaflet 1.0.3 (note that it will work in Leaflet 1.0.0 but performance if very bad)

Usage

Include the following in your HTML header:

<link rel="stylesheet" href="leaflet.css"/>
<script src="leaflet-src.js"></script>
<script src="Leaflet.VectorTiles.js"></script>

Note: Leaflet.VectorTiles.js must come after Leaflet

Example:

var map = L.map('map', {
  renderer: new L.FontCanvas()
});

var url = 'http://mytiles.party/{z}/{x}/{y}';

var vtLayer = new L.VectorTiles(url, {
  getFeatureId: function(feature) {
    return feature.properties.id;
  },
  debug: true, // to show tile boundaries
  style: {
    treeType: {
      oak: {
        color: 'green',
        font: '10px icomoon',
        content: '\ue91a'
      },
      pine: {
        color: 'red'
      }
    },
    building: {
      guggenheim: {
        color: 'purple',
        font: '20px icomoon',
        content: '\ue915' // house icon
      }
    }
  }
});

vtLayer.addTo(map);

All styling is by feature properties. The keys in the style option are property names and the keys in those objects correspond to values.

Developing

npm run build

The above outputs a bundle named leaflet.vector-tiles.js

npm run build-dev

Outputs the bundle with a source map for easier debugging

To run the example app, start the development server:

npm start

Now do:

cd example
npm install
npm start

and then point your browser to http://localhost:12345

Tiles

As is, for each tile, the library expects the tile server to respond with an array like:

[
  {
    layer: <string>, // layer name
    features: <GeoJSON FeatureCollection> // features in this layer
  },
  ...
]

Quirks

Performance

Performance is in very bad in Leaflet 1.0.0. It is much better in Leaflet 1.0.3.

Panning

tileunload doesn't fire on pan so old tiles stick around as you pan around.

Leaflet.FontCanvas

The FontCanvas class acutally doesn't have anything to do with this library. It should be removed and implemented as a separate extension.

TODO

  • Styling by layer

  • On zoom and pan every tile is reloaded and rerendered even though tiles almost never change. Figure out how to reuse tiles across zoom levels.