Can I have multiple server URLs with OpenLayers.Layer.TMS pointing at the mbtiles.php and my mbtiles file as in https://github.com/bmcbride/PHP-MBTiles-Server?

I have been trying to implement three servers as in this example to get multiple urls: http://openlayers.org/dev/examples/multiserver.html but have had no luck.

My three servers are:


My OpenLayers code is:

var normaltave06 = new OpenLayers.Layer.TMS("June Average Temperature", "mbtiles.php", {
        getURL: normaltave06URL,
        isBaseLayer: false
function normaltave06URL (bounds) {
        var db = "normaltave06.mbtiles";
        var res = this.map.getResolution();
        var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
        var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
        var z = this.map.getZoom();
        return "http://tile1.dendrite.ca/mbtiles.php?db="+db+"&z="+z+"&x="+x+"&y="+((1 << z) - y - 1);

This code is working with one server, can anybody suggest a way to return all three servers as the tile source in this example?

2 Answers 2


You won't be able to use the normal approach (as you linked to for the multiserver example), since that assumes that tiles are reachable directly.

Instead, you could modify the normaltave06URL example to "spread" its queries for each tile across multiple servers (e.g. some kind of round-robin, or perhaps just random).

If you have local servers and not many local users, this may not be a lot faster though - perhaps the "slowness" you are trying to work around isn't really that the browser can't make enough concurrent connections, but instead its a problem with the server configuration (or some other issue). You could try unpacking the mbtiles file(s), and then with-and-without the normal multiserver approach, see if the speed improves.


A more efficient way to serve mbtiles files is to use Infostreams fork of mbtiles-php found at https://github.com/infostreams/mbtiles-php

I found the best documentation for this at http://blog.thematicmapping.org/2012/11/exploring-mapbox-stack-mbtiles-tilejson.html

Instead of using OpenLayers.Layer.TMS, you can use OpenLayers.Layer.XYZ which does allow multiple server URLs and buffering etc. I am finding that I get much better performance.

Here is the code for OpenLayers that I have working:

var normaltave06 = new OpenLayers.Layer.XYZ("June Average Temperature", [
    ], {
        isBaseLayer: false
  • If that solves your problem, can you mark it as answered?
    – BradHards
    Commented Mar 18, 2013 at 3:12
  • It only lets you mark that your own question is answered after 24 hours.
    – CDavis
    Commented Mar 18, 2013 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.