[Tilecache] Calculating tile bounding boxes.

Dave Weaver zen13097 at zen.co.uk
Thu Jun 14 08:41:38 EDT 2007


I have Tilecache working nicely, sat between an OpenLayers front-end
and a MapServer back-end.

However, I need to replace the OpenLayers part with some code of my
own using WMS requests, and I'm struggling to get the tile bounding
box calculations work correctly.

First of all, here's are the Tilecache & OpenLayers configs I'm using
for my testing:

  [test]
  type=WMSLayer
  url=http://localhost:8080/cgi-bin/mapserv?map=map/Media_Base_Green.map&
  layers=lod5,lod8,lod11,states
  extension=jpg
  srs=EPSG:54004
  bbox=-20037508.34,-20037508.34,20037508.34,20037508.34
  maxResolution=156543.0339

       function init(){
            map = new OpenLayers.Map( $('map'), {
                        maxResolution: 156543.0339,
                        projection: 'EPSG:54004',
                        units: 'm',
                        maxExtent: new
OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)
            });
            layer = new OpenLayers.Layer.WMS( "green",
                    "/tilecache/tilecache.cgi?", {
                        layers: 'test',
                        format: 'image/png'
             } );
            map.addLayer(layer);

So, for the outermost zoom, where the whole earth fits in one 256x256
tile, my brain tells  the bounding box is obviously
(-20037508.34,-20037508.34,20037508.34,20037508.34), however
OpenLayers and TileCache work it out as (-20037508.34, -20037508.34,
20037508.3384, 20037508.3384)

My calculations reckon that at the next zoom level, the bounding box
for the lower left quadrant should be (-20037508.34,-20037508.34,0,0),
but when I try this in the URL:
  /tilecache/tilecache.cgi?LAYERS=test&FORMAT=image/png&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS=EPSG:54004&WIDTH=256&HEIGHT=256&BBOX=-20037508.34,-20037508.34,0,0

I get this error from TileCache:

  An error occurred: couldn't calculate tile index for layer test from
([-20037508.34, -20037508.34, 0.0, 0.0])

If I inspect the requests generated by OpenLayers, I see that it is
requesting the bounding box (-20037508.34, -20037508.34, -0.0008,
-0.0008) for the same tile, which works.

How do both OpenLayers and TileCache arrive at these values? Where am
I going wrong?

Many Thanks,
Dave.



More information about the Tilecache mailing list