cdbtiles is a tilelive backend plug-in for CouchDB
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


cdbtiles is a tilelive.js backend (source/sink) plug-in for CouchDB

Q: What the heck does that mean?

A: With this installed, you can use CouchDB to read/write map image tiles from other tilelive.js sources/sinks (mbtiles, Mapnik, TileJSON, S3, etc.)

Q: Come again?

A: You can use CouchDB to serve maps over HTTP.

Q: Why would one want to do that?

A: For the same reasons you might want to do anything else with CouchDB... As one example, you could write a self-contained CouchApp with mapping functionality.

Q: Where do the maps come from?

A: That's a really big question. Many days of poking around may be required to fully grok what you are asking here.

Places to start:


You need node.js. Then:

 npm install cdbtiles

Nice! Now what?


Obviously, this works with (and depends upon) tilelive.js and CouchDB.

For example: Let's say you already have map tiles rendered with TileMill sitting in a .mbtiles file, and using something like TileStream to serve tiles alongside an application server isn't doing it for you. And you also happen to have a CouchDB server running locally.

You should be able to easily copy all of your data from the .mbtiles file to your local CouchDB (and then replicate it on from there) by setting up these other things:

 npm install tilelive
 npm install mbtiles

And then:

 ./node_modules/tilelive/bin/copy -s pyramid --minzoom=10 --maxzoom=18  "mbtiles:///Users/user/maps/Columbus.mbtiles" "cdbtiles://"

The copy command above is a sample application provided by tilelive.js, and it has a bunch more options that you should check out. Tilelive is actually an API that any other app can use, so cdbtiles should enable CouchDB to play nicely with apps and other data sources/sinks that also support tilelive. The source and sink URIs have custom protocols (mbtiles: and cdbtiles:) that tilelive knows what to do with via the backend plugins you've now installed.

Important limitation: Currently cdbtiles automatically clears (as in destroys and rebuilds) the destination database. So you can't use this to copy multiple different tilesets into the same DB, or update just part of a tileset. It is not recommended to keep any other JSON documents in the same DB as your map tiles! You have been warned.

Now, if you point a Leaflet enabled web page page to{z}_{x}_{y}/tile you'll be serving up map tiles from CouchDB. Put that webpage in your CouchDB as well (left as an excercise for the reader), and you now have a self-contained map/application server running on CouchDB.

For what it's worth, this also lets you serve up the TileJSON information for your maps, just use: