[Tilecache] Configuration of MapServer,
Tilecache and Openlayers Together [SOLVED]
David Alda Fernandez de Lezea
dalda at ikt.es
Fri Jan 22 03:02:10 EST 2010
Hello list,
After been a long time trying to cofigure all these services, I finally managed to get it work. In my case, I wanted to have some WMS base layers being tiled with tilecache, and some overlays tiled with tilecache too. So I'm going to explain all the steps I followed to achieve that. This can be helpful for anybody who wants to do the same thing.
My Installation Software:
- MapServer (ms4w package) Version 5.2.1
-WMS Server Version 1.1.1
- Tilecache 2.10
- OpenLayers 2.8
Steps:
1) In the WMS Server Mapfile, define a global extent (EXTENT tag)
2) Do not define any extent at Layer level, I mean, NO "wms_extent" into de Layer METADATA
3) In the file tilecache.cfg:
- At the layer definition level, define a bbox equal to the global extent defined in the Mapfile
- At the layer definition level, define a maxResolution equal to ( MAX(X) - MIN(X) ) / 512
(This point is specified in Tilecache documentation. SEE README - Configuration)
4) In OpenLayers code:
- At map object definition level, do NOT specify maxExtent and maxResolution value (in my case is not necessary, but in other situations it might be)
- At layer object definition level, to the layer configuration parameters, add these parameters:
- maxExtent = bbox defined in tilecache.cfg
- maxResolution = maxResolution defined in tilecache.cfg
(This las point is specified in Tilecache documentation. SEE README - Using Tilecache with OpenLayers)
"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."
Also is important to note what we have to do if we use OpenLayers-Tilecache as Overlays:
"If you are using TileCache for overlays, you should set the 'reproject' option on the layer to 'false'"
Now with an example:
WMS MapServer Mapfile
MAP
NAME "WMSSERVER"
STATUS ON
EXTENT 460000 4710000 610000 4820000
SHAPEPATH "shapes/"
FONTSET "misc/fonts/fonts.txt"
SYMBOLSET "misc/symbols/symbols.sym"
....
Tilecache - tilecache.cfg
[mylayer]
type=WMSLayer
layers=wmslayername #name of the layer in WMS
srs=EPSG:23030
maxResolution=292.96875 #This is (610000 - 460000)/512
bbox=460000, 4710000, 610000, 4820000
url=your_wms_url
extent_type=loose
JavaScript Code - OpenLayers
var map, layer;
map = new OpenLayers.Map( $('map'), {projection: new OpenLayers.Projection("EPSG:23030"), units: 'm'});
//A Raster base layer
layer = new OpenLayers.Layer.WMS("Orthophoto","http://localhost/cgi-bin/tilecache-2.10/tilecache.py?",
{layers: 'this_name_should_be_that_the_one_defined_in_tilecache.cfg',format: 'image/png; mode=24bit',alpha : 'true',transparent: 'true'},{isBaseLayer: true, projection: 'EPSG:23030',units: 'm', maxExtent: new OpenLayers.Bounds(460000, 4710000, 610000, 4820000), maxResolution: 292.96875});
layer.transitionEffect = 'resize';
map.addLayer(layer);
//A vector layer as overlay
layer = new OpenLayers.Layer.WMS( "Parcels","http://localhost/cgi-bin/tilecache-2.10/tilecache.py?",
{layers: 'this_name_should_be_that_the_one_defined_in_tilecache.cfg'},{isBaseLayer: false, units: 'm', reproject: false, maxExtent: new OpenLayers.Bounds(460000, 4710000, 610000, 4820000), maxResolution: 292.96875} );
map.addLayer(layer);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToMaxExtent();
This worked for me. I hope this can be useful for anybody.
Thanks to Simon Mercier, Joel Bandibas and specially to Manel Clos.
Un saludo,
··················································································
David Alda Fernández de Lezea
Lurralde eta Biodibertsitate Saila / Dpto. de Territorio y Biodiversidad
IKT
Granja Modelo s/n · 01192 · Arkaute (Araba)
··················································································
Tlfnos.: 945-00-32-95 Fax: 945-00.32.90
··················································································
email: dalda at ikt.es web: www.ikt.es
··················································································
More information about the Tilecache
mailing list