diff --git a/README.md b/README.md index fcf9ac1f2..eb7823489 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,7 @@ -#Windwalker 0.0.3 +#Windwalker Install Node 0.12: http://nodejs.org/dist/v0.12.0/x64/node-v0.12.0-x64.msi -This is derived from a very early version of Windshaft. - -It uses modified MapBox modules [grainstore] and [millstone] to allow it to run under Windows or Linux. - - - [grainstore]: - [millstone]: - +This is derived from a very early version of [Windshaft](https://github.com/CartoDB/Windshaft) which is probably better if you can run under Linux and PostGIS. The purpose of this module is that it uses modified MapBox modules [grainstore](http://github.com/BHare1985/grainstore) and [millstone](http://github.com/BHare1985/millstone) to allow it to run under Windows or Linux. diff --git a/examples/server.js b/examples/server.js index 03118c228..308e4a9f5 100644 --- a/examples/server.js +++ b/examples/server.js @@ -6,10 +6,10 @@ var Windshaft = require('../lib'); var _ = require('underscore'); + var config = { dbtype: 'mssql', geom_type: 'polygon', - tileRoute: '/:dbname/tiles/:table/:z/:x/:y.*', grainstore: { map: {srid: 3857}, datasource: { @@ -25,6 +25,7 @@ var config = { polygon: "::line {line-color: red; line-width: 4; line-join: round; line-cap: round;}", }, }, + showErrors: true, enableCors: true, parameterParser: function(req, callback){ @@ -37,8 +38,82 @@ var config = { } }; -// Initialize tile server on port 4000 -var ws = new Windshaft.Server(config); -ws.listen(4000); +// Initialize with configuration and get back express4 server object +var app = new Windshaft.Server(config); + +//Enable compression for grid tiles (requires module) +//app.use(compression()) // Will not compress png by default, see module + +// Use morgan logger with "dev" log type (requires module) +//app.use(morgan("dev")); + + +// Setup fakemaps +app.setupMap('fakemap'); +app.setupMap('fakemap2', { dbtype: 'postgres' }); // Use postgres instead of mssql + +//Setup custom tile route for fakemap, +app.get('/fakemaps/:z/:x/:y.*', function (req, res) { + app.processTileRoute('fakemap', req, res); + app.processTileRoute('fakemap2', req, res, app.parameterParser); +}); + + +//Setup a map with key "map1" with overriding configuration +// This is the map we will use in the viewer +app.setupMap('map1', { + grainstore: { + properties: { + 'cache-features': 'on' + } + } +}); + +//Setup custom tile route, alternatively use config.tileRoute +app.get('/:dbname/tiles/:table/:z/:x/:y.*', function (req, res) { + app.processTileRoute('map1', req, res, app.parameterParser, app.beforeTileRender, app.afterTileRender); +}); + + + +app.parameterParser = function(req, callback){ + // This is where pre-processing comes in place. I set the interactivity + // field to be name so it popups on the map + req.params.interactivity = 'name'; + + // Convert every query variable to a request parameter (sql, style, table, etc) + _.extend(req.params, req.query); + + // send the finished req object on + callback(null,req); +}; + + +app.beforeTileRender = function(req, res, callback) { + // Great place to check if tile has been modified and rather or not to send + // a 304 and skip a database call. Just set tile to non-null or the tile body + // and getting the tile will be skipped + + //Setup fake header to showcase beforeTileRender() function + res.setHeader('x-beforeTileRender', new Date()); + + var tile = null; + var headers = null; + callback(null, tile, headers); +}; + + +app.afterTileRender = function(req, res, tile, headers, callback) { + // Great place to save processed tiles to a cache and to be checked in beforeTileRender + // You have access to the tile and current headers for logic/processing + + //Setup fake header to showcase beforeTileRender() function + headers['x-afterTileRender'] = new Date(); + return callback(null, tile, headers); +}; + -console.log("map tiles are now being served out of: http://localhost:4000" + config.tileRoute); +// Have the server listen on port 4000 +var listener = app.listen(4000, function(){ + console.log("map tiles are now being served out of: http://localhost:" + listener.address().port + config.tileRoute); +}); \ No newline at end of file diff --git a/lib/server.js b/lib/server.js index e3a1791b0..c8e721ec5 100644 --- a/lib/server.js +++ b/lib/server.js @@ -6,17 +6,7 @@ var RenderCache = require('./render_cache'); var _ = require('underscore'); var lodash = require('lodash'); var Step = require('step'); -var compression = require('compression'); -var morgan = require('morgan') -function shouldCompress(req, res) { - if (req.headers['Content-Type'] !== 'application/json') { - return false; - } - - return compression.filter(req, res) -} - module.exports = function(opts){ var opts = opts || {}; @@ -34,14 +24,7 @@ module.exports = function(opts){ // initialize express server var app = express(); - - app.use(compression({filter: shouldCompress})) - if(opts.logRequests) { - var logType = (typeof opts.logRequests === "string") ? opts.logRequests : "dev"; - app.use(morgan(logType)) - } - // extend app with all opts propeties and methods _.extend(app, opts); diff --git a/package.json b/package.json index 91b710ed7..58ff268df 100644 --- a/package.json +++ b/package.json @@ -27,13 +27,11 @@ } ], "dependencies": { - "compression": "1.5.2", "express": "4.13.4", "generic-pool": "1.0.12", "grainstore": "https://github.com/BHare1985/grainstore/tarball/1.1.0-hare2", "lodash": "4.4.0", "mapnik": "3.4.5", - "morgan": "1.7.0", "qs": "5.2.0", "step": "0.0.6", "tilelive": "5.8.2",