[GIS] OpenLayers with the own OSM data server

mapnikopenlayers-2openstreetmaptiles

I've gone through the process of setting up my own OSM database / tile server by setting up PostGIS, importing the Planet.osm data snapshot (took a few days), and setup Mapnik / cascadenik, etc. I can manually render my own sample tiles with generate_image.py and I can manually produce tilesets with generate_tiles.py. I've spend a decent amount of time generating my own custom style template using cascadenik and generated tiles from it, which I'm quite happy with.

My new issue is setting up a sample slippy map with OpenLayers to run on the same server…

I've got it somewhat configured and working; setup Apache, mod_python, TileCache, etc. It renders tiles into the slippy map, but I think I've got the parameters all screwed up in OpenLayers. Here's what I've got currently (which renders what looks like empty ocean at all zoom levels):

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <script src="http://openlayers.org/api/OpenLayers.js"></script> 
    <script type="text/javascript">
        var map;

        function init() {
                map = new OpenLayers.Map ("map", {
                        maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
                        maxResolution: 156543.0399,
                        numZoomLevels: 19,
                        units: 'm',
                        projection: new OpenLayers.Projection("EPSG:900913"),
                        displayProjection: new OpenLayers.Projection("EPSG:4326")
                } );

                layer = new OpenLayers.Layer.TMS( "OSM", "/tilecache/tilecache.py/", {layername: 'osm', type: 'png'} );
                map.addLayer(layer);
                map.addControl(new OpenLayers.Control.PanZoomBar());
                map.setCenter(new OpenLayers.LonLat(-82.686195, 27.84788), 12)
        }
        </script> 
  </head>
<body onload="init()">
    <div id="map"></div>
</body>
</html>

I feel that something's wrong with the layer options parameters, but I can't find good documentation describing the standard parameters to be used for displaying general OSM tiles rendered by Mapnik…

Is there something obvious that I'm missing that would cause this problem?

Here's all I have in the tilecache.cfg, too:

[cache]
type=Disk
base=/tmp/tilecache
[osm]
type=Mapnik
spherical_mercator=true
mapfile=/home/user/mapfile.xml

Best Answer

One note: I recommend mod_wsgi over mod_python. And it is important to either use Apache prefork with mod_python or (ideally) mod_wsgi in daemon mode with threads=1 and processes=N (where N is best matched to number of logical processors). mod_wsgi in daemon mode can be used with either Apache prefork or worker. The reason for this is that TileCache caches the mapnik.Map object and it should not therefore be shared across threads. Mapnik core is perfectly threadsafe, but multithreaded server applications need to create an instance of a mapnik.Map object per thread. Mod_tile and Paleoserver are examples of an applications that support multithreaded rendering in this way, but TileCache does not support this. However, running TileCache + Mapnik + mod_wsgi daemon mode with threads=1 is a fine route, and on a machine with multiple cores should be speedy enough for most purposes.

As far as your layer config try adding "serviceVersion":

var tms = new OpenLayers.Layer.TMS("TileCache Mapnik Layer",url, { serviceVersion: "1.0.0", layername: "osm", type: "png" });

Related Question