mapbox / mapbox/tilelive

Can Tilelive host many mbtiles files?

Open
#220 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
540
Forks
106
PR merge metrics
No merged PRs in 30d

Description

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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the tilelive.load call and the Express tile route shown in the issue. Determine how a requested file name can select among file1.mbtiles and file2.mbtiles while preserving tile retrieval. Done means the server serves tiles from the selected MBTiles file through the proposed /v2/tiles/file1/{z}/{x}/{y}.pbf form.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.