9

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

1 Answer 1

8

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" });

3
  • Thanks! That fixed the problem, but now setCenter isn't working -- I think it's going to the correct zoom level, but it's centered at ll = (0, 0) (off Africa)... Possibly a problem with meters vs. dec. degrees? Also, thanks for the advice re: mod_wsgi. I'll set it up that way and see if I can get better performance. I'm running in a VM with 6 cores and 12 GB RAM, so it should be plenty for some fast rendering / caching.
    – colemanm
    Oct 22, 2010 at 20:09
  • 2
    The OSM coordinates are in meters, so you'll have to set the center in projected meters. See docs.openlayers.org/library/… . Oct 23, 2010 at 12:56
  • Thanks, looks like that was my problem -- when using setCenter with coords in meters it works.
    – colemanm
    Oct 26, 2010 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.