Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

My configs:

# Rendering OpenStreetMap data with Mapnik; should use metaTiling to
# avoid labels across tile boundaries
[osm-map]
type=MapnikLayer
mapfile=/usr/home/sergeev/osm_mapnik/osm.xml
spherical_mercator=true
tms_type=google
metatile=yes
extent_type=loose

and

var map, layer;

        function init(){
            var options = {
                    resolutions: [156543.0339, 78271.51695, 39135.758475, 19567.8792375, 9783.93961875, 4891.969809375, 2445.9849046875, 1222.99245234375, 611.496226171875, 305.7481130859375, 152.87405654296876, 76.43702827148438, 38.21851413574219, 19.109257067871095, 9.554628533935547, 4.777314266967774, 2.388657133483887, 1.1943285667419434, 0.5971642833709717, 0.29858214168548586],
                        numZoomLevels: 20,
                        maxExtent: new OpenLayers.Bounds(0.05917265625,0.1171263671875,0.0593009765625,0.11720234375),
                        projection: 'EPSG:900913'
            };

            map = new OpenLayers.Map( $('map'), options);
            layer = new OpenLayers.Layer.WMS( "VMap0", 
                    "tilecache.cgi?", {layers: 'osm-map', format: 'image/png' } );
            map.addLayer(layer);
            map.addControl(new OpenLayers.Control.Permalink());
            if (!map.getCenter()) map.zoomToMaxExtent();
        }

my osm.xml is here: http://pastebin.com/f5EWUsTy

My problem:

I see the map, but i cant't move it: each zoom level is fixed. And the center of the map is somewhere in Africa, but i thought my xml is describing north of Russia. The image below is what i see: enter image description here

So what should i do? (I'm totaly new to gis, so, please, be patient :)

share

2 Answers 2

up vote 2 down vote accepted

Your bounds are wrong (in fact they are so wrong I'm surprised that you see that much map).

Change

  maxExtent: new OpenLayers.Bounds(0.05917265625,0.1171263671875,0.0593009765625,0.11720234375),

to something like :

'maxExtent': new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)

You can also read this tutorial which discusses projections and how to convert lat/lon to spherical mercator coordinates.

share
    
thanks! that works and the tutorial is very helpful! –  k102 Feb 22 '12 at 5:36

I had a lot of problems with it and I found one way to setup it workingly:

page.html

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

   layer = new OpenLayers.Layer.WMS( "osm","tilecache/tilecache.cgi?",
      { layers:'osm',
        format: 'image/png',
        srs: 'EPSG:4326'
      } );  
   map.addLayer(layer);
}

tilecache.cfg

[cache]
type=Disk
base=/tmp/tilecache

[osm]
type=Mapnik
mapfile=/home/dmiadmin/bin/mapnik/osm.xml
spherical_mercator=true
bbox=-20037508.34,-20037508.34,20037508.34,20037508.34
resolutions=2445.984375,1222.9921875,611.49609375,305.748046875,152.874023438,76.4370117188,38.2185058594,19.1092529297,9.55462646484,4.77731323242,2.38865661621,1.19432830811,0.597164154053,0.298582077026,0149291039
metaTile=true
metaSize=8,8
metaBuffer=40
levels=20

The most important thing is to setup the maxResolution right, and then work on to the bounds. The bounds ymin-ymax and xmin-xmax are real numbers and have to be devidable by the maxResolution value giving a real-non-float number. This number is btw. the number of tiles generated per axis (x/y) the resolutions have to be devided by 2 or 4 or 8 from the initial number (156543 eg.)

I know all this is very conusing. I worked 3 days on that problem, until I fully understood how the things are connected together!

share
    
+1, i'm getting closer to understanding it, thanks! (never thought that i'll be told that the Earth is a sphere...) –  k102 Feb 22 '12 at 5:37

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .