Coder Social home page Coder Social logo

leaflet.vectortiles's Introduction

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.

leaflet.vectortiles's People

Contributors

eslivinski avatar kelvinabrokwa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.