[Tilecache] OpenLayers, Tilecache and Custom Map using ImageLayer

Christopher Schmidt crschmidt at metacarta.com
Thu May 22 19:24:42 EDT 2008


On Thu, May 22, 2008 at 04:10:02PM -0700, Nathan Boettcher wrote:
> Hi All,
> 
>  
> 
> I toyed with it some more and went with the ImageLayer config option as
> someone suggested rather than using the gdal2tiles tool and trying to use
> the output.  So far it works, but I have a bit of a snag.  It only shows
> half the map!  Basically, using OpenLayers if I zoom all the way out at 0
> magnification I can see a single tile with the entire map (and a little bit
> of black).  Once I zoom in I only get the bottom half of the map.  I am
> totally clueless as to why Tilecache is only generating and showing me tiles
> for the lower half of the map.  Anyone got any ideas?  Is it OpenLayers
> somehow?  Below is my config and OpenLayers code:
> 
>  
> 
> Tilecache.cfg
> 
> -------------------
> 
> [tilecache_options]
> 
> path=G:/mapserver/
> 
>  
> 
> [cache]
> 
> type=Disk
> 
> base=G://mapserver/cache
> 
>  
> 
> [test]
> 
> type=ImageLayer
> 
> file=G:/mapserver/test.jpg
> 
> bbox=0,0,4000,5038
> 
> filebounds=0,0,4000,5038
> 
> maxresolution=16
> 
>  
> 
>  
> 
> OpenLayers:
> 
> --------------------
> 
>     <script src="http://openlayers.org/api/OpenLayers.js"></script>
> 
>     <script type="text/javascript">
> 
>         <!--
> 
>         var map, layer;
> 
>                         
> 
>         OpenLayers.Layer.TMS.prototype.getURL = function ( bounds ) {
> 
>             bounds=this.adjustBounds(bounds);
> 
>             var res=this.map.getResolution();
> 
>             var
> x=Math.round((bounds.left-this.tileOrigin.lon)/(res*this.tileSize.w));
> 
>             var
> y=Math.round((bounds.bottom-this.tileOrigin.lat)/(res*this.tileSize.h));
> 
>             var z=this.map.getZoom();
> 
>             var
> path=/*this.serviceVersion+"/"+*/this.layername+"/"+z+"/"+x+"/"+y+"."+this.t
> ype;
> 
>             var url=this.url;
> 
>             if(url instanceof Array)
> 
>             {
> 
>                         url=this.selectUrl(path,url);
> 
>             }
> 
>             return url+path;
> 
>             };
> 
>  
> 
>         function init(){
> 
>             map = new OpenLayers.Map('map');
> 
>             layer = new OpenLayers.Layer.TMS("Test TMS",
> "http://devmaps/tilecache.py/", {layername: 'test',
> type:'png',},{maxResolution: 16});

As it says in the TileCache docs:

"The most important thing to do is to ensure that the OpenLayers Layer
has the same resolutions and bounding box as your TileCache layer. You
can define the resolutions in OpenLayers via the 'resolutions' option or
the 'maxResolution' option on the layer. The maxExtent should be defined
to match the bbox parameter of the TileCache layer."

-- http://tilecache.org/readme.html#using-tilecache-with-openlayers

You'll need to set maxExtent next to maxResolution.

Also, the , after 'png' ill break IE.

-- Chris




More information about the Tilecache mailing list