Skip to content

Render Leaflet compatible map tiles and UTFGrids using node-canvas on Heroku

License

Notifications You must be signed in to change notification settings

LocalData/nodetiles-core

 
 

Repository files navigation

Nodetiles-Core

Build Status Dependency Status Coverage Status Code Climate NPM version

Nodetiles-core is a javascript library for rendering map tiles suitable for slippy-maps and static images. Features include:

  • Flexible Data-connectors: We offer GeoJson and Shapefile connectors out-of-the-box, but it's easy to build your own.
  • Map Projections: Transform data between more 3,900+ EPSG projections using Proj4.js
  • CartoCSS Support: We support many (if not most) stylesheet features of CartoCSS making it trivial to import your map styles from tools like Tilemill
  • Slippy-map URL helpers: Easily serve map tiles, UTFGrids, and Tile.json. Check out nodetiles-init for a simple scaffold.
  • Static maps: If slippy-maps aren't your style, generate static images of any dimension; checkout nodetiles-example-static for examples.
  • Joyfully simple, pluggable, flexible, powerful: We built Nodetiles to be easily understandable, extensible and a joy to use. It's built with Javascript and tries to provide a solid foundation of tools that are still easy to understand, extend or replace depending on your needs. File an issue if Nodetiles can't do what you need.

Screenshot

Nodetiles Screenshot

Example

/* Set up the libraries */
var nodetiles = require('nodetiles-core'),
    GeoJsonSource = nodetiles.datasources.GeoJson,
    Projector = nodetiles.projector,
    fs = require('fs'); // we'll output to a file

/* Create your map context */
var map = new nodetiles.Map({
    projection: "EPSG:4326" // set the projection of the map
});

/* Add some data */
map.addData(new GeoJsonSource({
  name: "world",
  path: __dirname + '/countries.geojson',
  projection: "EPSG:900913"
}));

/* Link your Carto stylesheet */
map.addStyle(fs.readFileSync('./style.mss','utf8'));

/* Render out the map to a file */
map.render({
  // Make sure your bounds are in the same projection as the map
  bounds: {minX: -180, minY: -90, maxX: 180, maxY: 90},
  width: 800,   // number of pixels to output
  height: 400,
  callback: function(err, canvas) {
    var file = fs.createWriteStream(__dirname + '/map.png'),
        stream = canvas.createPNGStream();

    stream.on('data', function(chunk){
      file.write(chunk);
    });

    stream.on('end', function(){
      console.log('Saved map.png!');
    });
  }
});


Magic filtering

To filter objects where a key exists or not, you can use styles with the keyword '$undefined'

[myfield='$undefined']

or

[myfield!='$undefined']

Thanks

Big THANKS to Tom Carden whose original gist inspired this project. He also has other very useful projects.

Projections

Supported projections

Developing

npx mocha

Common errors

If you have issues installing canvas on OS X, you may need to explicitly set the path to pkgconfig:

export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig

Copyright

Copyright (c) 2012-2014 Code for America. See LICENSE for details.

About

Render Leaflet compatible map tiles and UTFGrids using node-canvas on Heroku

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%