Home

Awesome

tilestrata-postgis-geojson-tiles

Tilestrata plugin for generating geojson tiles from postgis.

Configuration

Example

var tilestrataPostGISGeoJSON = require('tilestrata-postgis-geojson-tiles');
var querystring = require('querystring');

var layer = server.layer('geojson-tiles', {minZoom: 5, maxZoom: 14});

// .../geojson-tiles/tile.json?id=12345
layer
  .route('tile.json')
    .use(headers({
      'Access-Control-Allow-Origin': '*'
    }))
    .use(tilestrataPostGISGeoJSON({
      geometryField: 'geom',
      sql: function(server, req) {
        var qs = querystring.parse(req.qs);
        var id = qs && qs.id ? parseInt(qs.id, 10) : null;

        return 'SELECT id, name, {geojson} FROM tablename WHERE ST_Intersects(geom, {bbox}) AND id = ' + id;
      },
      pgConfig: {
        username: 'postgres',
        password: 'password',
        host: 'localhost',
        port: '5432',
        database: 'postgres'
      }
    }));