Commit 91bcf77f authored by Rodrigo Tapia-McClung's avatar Rodrigo Tapia-McClung

Add /mbtiles route

parent 866f9324
const MBTiles = require('@mapbox/mbtiles');
const p = require("path");
// Enable CORS and set correct mime type/content encoding
let header = {
"Access-Control-Allow-Origin":"*",
"Access-Control-Allow-Headers":"Origin, X-Requested-With, Content-Type, Accept",
"Content-Type":"application/x-protobuf",
"Content-Encoding":"gzip"
};
// Route which handles requests like the following: /<mbtiles-name>/0/1/2.pbf
module.exports = function(app) {
app.get('/data/:source/mbtiles/:z/:x/:y.pbf', function(req, res) {
new MBTiles(p.join(__dirname, `/public/${req.params.source}.mbtiles`), function(err, mbtiles) {
mbtiles.getTile(req.params.z, req.params.x, req.params.y, function(err, tile, headers) {
if (err) {
res.set({"Content-Type": "text/plain"});
res.status(404).send('Tile rendering error: ' + err + '\n');
} else {
res.set(header);
res.send(tile);
}
});
if (err) console.log("error opening database");
});
});
}
\ No newline at end of file
......@@ -19,32 +19,8 @@ app.use(logger('combined', {
}));
app.use(cors());
// Enable CORS and set correct mime type/content encoding
let header = {
"Access-Control-Allow-Origin":"*",
"Access-Control-Allow-Headers":"Origin, X-Requested-With, Content-Type, Accept",
"Content-Type":"application/x-protobuf",
"Content-Encoding":"gzip"
};
app.use('/', express.static(__dirname + '/public'));
// Route which handles requests like the following: /<mbtiles-name>/0/1/2.pbf
app.get('/denue/:z/:x/:y.pbf', function(req, res) {
new MBTiles(p.join(__dirname, '/public/outC.mbtiles'), function(err, mbtiles) {
mbtiles.getTile(req.params.z, req.params.x, req.params.y, function(err, tile, headers) {
if (err) {
res.set({"Content-Type": "text/plain"});
res.status(404).send('Tile rendering error: ' + err + '\n');
} else {
res.set(header);
res.send(tile);
}
});
if (err) console.log("error opening database");
});
});
const {Pool} = require('pg');
const dbconfig = require('./config/dbconfig.json');
const readOnlyPool = new Pool(dbconfig);
......@@ -59,6 +35,7 @@ const geobuf = require('./geobuf.js')(app, readOnlyPool);
const listLayers = require('./list_layers.js')(app, readOnlyPool);
const query = require('./query.js')(app, readOnlyPool);
const geojsonmvt = require('./geojsonmvt.js')(app, readOnlyPool);
const mbtiles = require('./mbtiles.js')(app, readOnlyPool);
const server = app.listen(pgserverconfig.port);
server.setTimeout(600000);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment