[Tilecache] Configuration of TileCache and OpenLayers -- SOLVED

Jonathan W. Lowe jlowe at giswebsite.com
Sat Feb 16 01:48:53 EST 2008


Solution:

How typical...once I gave up and begged for help from the mailing list,
I was able to figure out the answer on my own.

The missing line in my html file was "maxResolution: 20" as shown:

var map_options = {
>                                 maxExtent: tilecacheBbox,
				  maxResolution: 20,
>                                 projection:"EPSG:26943",
>                                 units: "meters",
>                                 numZoomLevels: 5
>                         };

"Where did the value of 20 come from?" fellow newbies might ask.  For
any others encountering similar problems, what helped me most was the
following "recipe":

1) Just to get things going with simple integer values, in the Mapserver
mapfile, set an EXTENT whose X values define a width exactly divisible
by 512.

For a projected example in the California Stateplane Zone III projection
(EPSG:26943), "EXTENT 1838500 648999 1848740 659239" has a width of
1848740 - 1838500 = 10240, and 10240 / 512 = 20 (i.e. divisible with no
remainder).

Those working in Geographic coordinates won't have the luxury of a width
greater than or equal to 512. Not to worry -- you'll just be working
with a lot of decimal places.  For example,  "EXTENT 113.8 22.1 114.5
22.6" has a width of 114.5 - 113.8 = 0.7, and 0.7 / 512 = 0.0013671875.

2) In the tilecache.cfg, set the bbox value to the same set of
coordinates as the mapfile extent (but with commas rather than spaces
between the values), for example, "bbox=1838500,648999,1848740,659239"
or "bbox=113.8,22.1,114.5,22.6".

3) In the OpenLayers html file, set the map options maxExtent to the
same set of coordinates as the mapfile EXTENT and tilecache.cfg bbox,
such as "maxExtent : new OpenLayers.Bounds( 1838500, 648999, 1848740,
659239)", and set the map options maxResolution to the mapfile EXTENT
width divided by 512.  For example, "maxResolution : 20".

Or, in the geographic coordinates example, "maxResolution :
0.0013671875".

Once an initial set of tiles is displaying as intended, adjusting any
single parameter value in any of the three files (mapfile, tilecache.cfg
or OpenLayers html) lets you discover what's possible and what isn't,
and how the configurations fit together.

Happy mapping!

On Fri, 2008-02-15 at 20:42 +0000, Jonathan W. Lowe wrote:
> TileCachers:
> 
> Newbie support request...  Can anyone spot what must be a naive mistake
> in how I've set up the following TileCache and OpenLayers test?  
> 
> The first two tests were encouraging, but the combining TileCache and
> OpenLayers failed despite many tweaks to many configuration values.
> 
> To debug, I copied samples of the OpenLayers WMS requests from apache's
> access_log into a browser and got a resolution error indicating that the
> BBOX values OpenLayers requested did not match the fixed resolutions of
> the TileCache layer.
> 
> For example:  
> 
> http://www.giswebsite.com/cgi-bin/tilecache/tilecache.cgi?
> LAYERS=tcbox&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&
> REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&
> SRS=EPSG%3A26943&BBOX=1843540,654759,1843900,655119&WIDTH=256&HEIGHT=256
> 
> ...returns:
> 
> An error occurred: can't find resolution index for 1.406250. 
> Available resolutions are:  [40.0, 20.0, 10.0, 5.0, 2.5]
> 
> Looks like the tiles are not appearing in the html page because the WMS
> requests fail.  So, I suspect some configuration error, although have
> attempted to stick to the instructions, such as setting BBOX values
> identically across all files. 
> 
> Thanks in advance,
> Jonathan
> 
> 
> Installation details:
> 
> TileCache version:  2.01
> OpenLayers version: 2.5
> MapServer version: 5.0.2
> Python version: 2.4.4
> OS: FreeBSD
> 
> 
> Test details:
> 
> Test 1) Success!
> http://www.giswebsite.com/cgi-bin/tilecache/tilecache.cgi/1.0.0/tcbox/0/0/0.png
> 
> Test 2) Success!
> http://www.giswebsite.com/cgi-bin/tilecache/tilecache.cgi?
> LAYERS=tcbox&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&
> SRS=EPSG:26943&BBOX=1838500,648999,1848740,659239&WIDTH=256&HEIGHT=256&
> 
> Test 3) Failure!
> http://www.giswebsite.com/demos/tcbox.html
> 
> 
> Test 3 configuration details:
> 
> a) Contents of tilecache.cfg layer [tcbox]:
> 
> [tcbox]
> type=MapServerLayer
> mapfile=/home/gisweb/www/cgi-bin/tcbox.map
> layers=parks
> extension=png
> size=256,256
> bbox=1838500,648999,1848740,659239
> srs=EPSG:26943
> levels=5
> metaTile=true
> metaSize=5,5
> metaBuffer=10
> mime_type=image/png
> 
> 
> b) Relevant contents of Mapserver mapfile, tcbox.map:
> 
> # Berkeley test area in California Stateplane, zone III, NAD83, Meters.
> MAP
> NAME "tcbox"
> EXTENT 1838500 648999 1848740 659239
> SIZE 256 256
> IMAGETYPE PNG
> IMAGEQUALITY 85
> INTERLACE off
> RESOLUTION 96
> UNITS meters
> TRANSPARENT off
> OUTPUTFORMAT
>   NAME png
>   DRIVER "GD/PNG"
>   MIMETYPE "image/png"
>   IMAGEMODE RGB
>   EXTENSION "png"
>   FORMATOPTION  "INTERLACE=OFF"
> END
> PROJECTION
>  "init=epsg:26943"
> END
> <...etc..>
> 
> c) Contents of OpenLayers page, tcbox.html:
> 
> <html  xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
> <head>
> <title>TileCache PoC</title>
> <link REL="shortcut icon" TYPE="image/ico" href="/favicon.ico" />
> <meta http-equiv="Content-Type" content="text/html;
> charset=utf-8"></meta>
>     <style type="text/css">
>         #map {
>             width: 256px;
>             height: 256px;
>             border: 1px solid gray;
>         }
>     </style>
>     <script type="text/javascript" src="../lib/OpenLayers.js"></script>
>     <script type="text/javascript">
>                 var map, vectors, controls, match;
>                 var tilecacheBbox = new OpenLayers.Bounds(
> 					1838500,648999,1848740,659239);
>                 function init(){
>                         var lon = 1843620;
>                         var lat = 654119;
>                         var zoom = 3
>                         OpenLayers.IMAGE_RELOAD_ATTEMPTS = 1;
>                         var map_options = {
>                                 maxExtent: tilecacheBbox,
>                                 projection:"EPSG:26943",
>                                 units: "meters",
>                                 numZoomLevels: 5
>                         };
>                         map = new OpenLayers.Map("map", map_options);
>                         layer = new OpenLayers.Layer.WMS(
>                                 "tcbox",
>            "http://www.giswebsite.com/cgi-bin/tilecache/tilecache.cgi?",
>                                 {layers: 'tcbox', format: 'image/png' }
>                         );
>                         map.addLayers([layer]);
>                         map.setCenter(
> 				new OpenLayers.LonLat(lon, lat), zoom);
>                         map.addControl(
> 				new OpenLayers.Control.MousePosition());
>                 };
>     </script>
> </head>
> <body onload="init()">
>       <div id="map"></div>
> </body>
> </html>
> 
> -----------------------
> 
> _______________________________________________
> Tilecache mailing list
> Tilecache at openlayers.org
> http://openlayers.org/mailman/listinfo/tilecache
> 




More information about the Tilecache mailing list