Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Can Tilelive host many mbtiles files? #220

Open
ev0065 opened this issue May 21, 2020 · 1 comment
Open

Can Tilelive host many mbtiles files? #220

ev0065 opened this issue May 21, 2020 · 1 comment

Comments

@ev0065
Copy link

ev0065 commented May 21, 2020

Hi,

I am using a tilelive server to host my mbtiles files and load them locally. Currently, my server looks like this (taken from this post):

var express = require('express');
var http = require('http');
var app = express();
var tilelive = require('@mapbox/tilelive');
require('@mapbox/mbtiles').registerProtocols(tilelive);

tilelive.load('mbtiles://./file.mbtiles', function(err, source) {

    if (err) {
        throw err;
    }
    app.set('port', 7777);

    app.use(function(req, res, next) {
        res.header("Access-Control-Allow-Origin", "*");
        res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
        next();
    });

    app.get(/^\/v2\/tiles\/(\d+)\/(\d+)\/(\d+).pbf$/, function(req, res){

        var z = req.params[0];
        var x = req.params[1];
        var y = req.params[2];

        console.log('get tile %d, %d, %d', z, x, y);

        source.getTile(z, x, y, function(err, tile, headers) {
            if (err) {
                res.status(404)
                res.send(err.message);
                console.log(err.message);
            } else {
              res.set(headers);
              res.send(tile);
            }
        });
    });

    http.createServer(app).listen(app.get('port'), function() {
        console.log('Express server listening on port ' + app.get('port'));
    });
});

But, I want to be able to host multiple mbtiles files. For instance, if tilelive could load file1.mbtiles and file2.mbtiles. Then, my query could look like localhost:7777/v2/tiles/file1/{z}/{x}/{y}.pbf. But, I'm not sure how to specify tilelive to load multiple tiles.

Please let me know if you have any ideas. Thanks!

@tsemerad
Copy link

tsemerad commented Oct 9, 2020

Hi @ev0065. Have you looked at tessera? I've been using it to host multiple mbtiles files. It works with any tilelive source. It might be more than you need for your problem, but looking at its source code should show you how it handled this problem.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants