[OpenLayers-Users] [Mapnik-users] Reference to use mapnik.load_map function

Christopher Schmidt crschmidt at metacarta.com
Wed Dec 6 11:51:17 EST 2006


On Wed, Dec 06, 2006 at 02:30:05PM -0200, Luiz Vital wrote:
> Thanks Cristopher,
> 
> Helped a lot :-)
> I got a question regarding TileCache with OpenLayers, but not
> especifically with the MapnikLayer.
> 
> When instantiating OpenLayers.Map with no options everything works
> fine. But when i tried to limit the extent of a map with the
> 'maxExtent' option in OpenLayers.Map object, like this:
> 
> map = new OpenLayers.Map('map',
>                   {maxExtent: new OpenLayers.Bounds(-75,-35,-31,7)});

OpenLayers is treating the maxExtent as the corner of the WMS-C grid.
This is because OpenLayers does not have explicit support for WMS-C:
instead, it simply requests tiles on a grid in the way that WMS-C was
originally designed. (That is, OpenLayers was a WMS-C client before
WMS-C existed ;)) So, OpenLayers can't be told "The bounds of the WMS-C
layer are *this*", and it treats maxExtent as those bounds at the
moment.

> with an OpenLayers.Layer.WMS pointing to a TileCached data. I get this
> error on a specific tile request:
> ------------------------
> An error occurred: couldn't calculate tile index for layer Brasil from
> ([-75.0, -12.5, -52.5, 10.0])
>  File "/usr/lib/cgi-bin/sos_atlas/TileCache/Service.py", line 425, in
> cgiHandler
>    format, image = service.dispatchRequest( params, path_info, host )
> ...
>  File "/usr/lib/cgi-bin/sos_atlas/TileCache/Service.py", line 125, in getMap
>    raise Exception(
> -------
> And on apache log:
> TileCache/Layer.py:139: UserWarning: x (4.000000) - x0 (4.666667) = 0.666667
> 
> Value 0.666667 (x-x0) should be <= 0.001 (threshold)

Yep. This is letting you know that your request was offset from the
bounds TileCache expected, and is related to what I described above.

> So i noticed the bbox param in tilecache.cfg and set to the same as in
> OpenLayers:
> [Brasil]
> type=MapServerLayer
> layers=Brasil,Dominio,Estados,Rema
> mapfile=/home/nando/projetos/sos/atlas/atlas.map
> bbox=-75,-35,-31,7
> metaTile=true
> 
> The error in Apache log now is:
> TileCache/Layer.py:105: UserWarning: can't find resolution index for 
> 0.087891

Yep: You got closer, but missed the last step:

> It seems that the requests of OpenLayers are not matching with what
> TileCache expects.
> 
> So the question is: How can I configure OpenLayers and TileCache to
> work together specifying a maxExtent param in OpenLayers.Map options?

Good question! And one no one has asked yet :)

OpenLayers assumes a grid based on the map maxExtent. TileCache does as
well, but TileCache *also* resets the resolutions array (which
determines the 'scales' or 'zooms' your map is at) based on the full
size of your map / 512. 

Currently, we don't have a way to override this by setting a
maxResolution (like OpenLayers does) -- instead, you need to create a
resolutions array for yourself. For a resolutions array which matches
the default TileCache (and therefore OpenLayers) values, I would
personally do this in Python:

>>> [.70625. / 2 ** i for i in range(16)]
[0.70625000000000004, 0.35312500000000002, 0.17656250000000001,
0.088281250000000006, 0.044140625000000003, 0.022070312500000001,
0.011035156250000001, 0.0055175781250000003, 0.0027587890625000002,
0.0013793945312500001, 0.00068969726562500004, 0.00034484863281250002,
0.00017242431640625001, 8.6212158203125005e-05, 4.3106079101562503e-05,
2.1553039550781251e-05]

I would then copy the resolutions array, and set resolutions on my
layer:

[Brasil]
type=MapServerLayer
layers=Brasil,Dominio,Estados,Rema
mapfile=/home/nando/projetos/sos/atlas/atlas.map
bbox=-75,-35,-31,7
metaTile=true
resolutions=0.70625,0.353125,0.1765625,0.08828125,0.044140625,0.0220703125,0.01103515625,0.005517578125,0.0027587890625,0.00137939453125,0.000689697265625,0.000344848632813,0.000172424316406,8.62121582031e-05,4.31060791016e-05,2.15530395508e-05

Once you do this, your TileCache layer should work as you expect.

In the next version of TileCache (which is not real soon, but will come
out eventually ;)), we'll add a 'maxRes', so you can just say
'maxRes=.70625', as you do in OpenLayers.

Once you do that, you should be able to use TileCache as the data source
for your OpenLayers map. 

Since I see that you're using metaTiling, I recommend upgrading to
TileCache 1.3, which fixes a couple bugs in the metaTiling support.

If you have any further questions, please feel free to bring them to the
OpenLayers list.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list