<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#ffffff">
Hello everyone,<br>
<br>
I've spent the better part of the day trying to get things to play
nicely together, but I still failed miserably.<br>
Here's what works now:<br>
<br>
Mapserver:<br>
EXTENT 20.26 43.16 29.70 48.46 <br>
<br>
OpenLayers:<br>
var res =
[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.597164283];<br>
var lonlat = new OpenLayers.Projection("EPSG:4326");<br>
var sphericalMercator = new OpenLayers.Projection("EPSG:900913");<br>
function initStage1(){<br>
var options = { projection: sphericalMercator, displayProjection:
lonlat, units: "m", numZoomLevels: 12, maxResolution: 2445.9849046875,
maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,
20037508.34, 20037508.34), resolutions: res };<br>
...<br>
var rtc_base = new OpenLayers.Layer.WMS('RTC TileCache',
['<a class="moz-txt-link-freetext" href="http://server.romtelecom.ro/tilecache/tilecache.py">http://server.romtelecom.ro/tilecache/tilecache.py</a>'],{map:
'/var/www/html/map/rtc_base.map',transparent: 'false',format:
'image/png2', map_imagetype: 'agg', layers: 'rtc_base', maxExtent: new
OpenLayers.Bounds(20.26, 43.16, 29.70, 48.46),maxResolution: 156543,
units: 'm'}, {isBaseLayer:true, projection: sphericalMercator});<br>
<br>
TileCache:<br>
[rtc_base]<br>
type=WMS<br>
debug=no<br>
url=<a class="moz-txt-link-freetext" href="http://server.romtelecom.ro/fcgi-bin/mapserv?map=/var/www/html/map/rtc_base.map">http://server.romtelecom.ro/fcgi-bin/mapserv?map=/var/www/html/map/rtc_base.map</a><br>
layers=Judete,RuralSate,Rural,Urban,highway,sechighway,streets,buildings,GranitaJudete
<br>
bbox=20.26,43.16,29.70,48.46<br>
spherical_mercator=true<br>
levels=13<br>
srs=EPSG:900913<br>
size=256,256<br>
extension=png<br>
mime_type=image/png2<br>
maxResolution=2445.9849046875<br>
map_imagetype=agg<br>
<br>
In this setup, everything works as expected - but the problem I have is
that my Openlayers map has too permissive bounds - almost the whole
world:<br>
<div class="logRow logRow-command"><span role="presentation"
class="objectBox objectBox-text ">>>> new
OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34,
20037508.34).transform(sphericalMercator, lonlat);</span></div>
<div class="logRow"><a class="objectLink objectLink-object a11yFocus "><span
class="objectTitle ">left-bottom=(-180,-85.051128779807)
right-top=(180,85.051128779807)<br>
<br>
I would like to restrict these bounds to overlap with my original bbox:
</span>20.26,43.16,29.70,48.46.<br>
<br>
I've tried every trick in the book, but I still haven't managed. Here's
what I did (and didn't work):<br>
- set the map (and all layers) maxExtent to the new value:<br>
</a>
<div class="logRow logRow-command"><span role="presentation"
class="objectBox objectBox-text ">new OpenLayers.Bounds(20.26, 43.16,
29.70, 48.46).transform(lonlat, sphericalMercator);</span></div>
<div class="logRow"><a class="objectLink objectLink-object a11yFocus "><span
class="objectTitle ">left-bottom=(2255332.8831578,5336357.2739115)
right-top=(3306188.8761,6183726.4985628)<br>
- calculate the new resolution array using this formula:<br>
maxExtent = (</span></a><a
class="objectLink objectLink-object a11yFocus "><span
class="objectTitle ">3306188.8761 - </span></a><a
class="objectLink objectLink-object a11yFocus "><span
class="objectTitle ">2255332.8831578)/512 = 1050855.9929422/512 =
2052.453111215 <br>
subsequent resolutions are maxExtent/2, maxExtent/4, maxExtent/8...<br>
so, res becomes: var res =
[2052.453111215,1026.226555608,513.113277804,256.556638902,128.278319451,64.139159726,32.069579863,16.034789931,8.017394966,4.008697483,2.004348741,1.002174371,0.501087185];<br>
<br>
My current config is now:<br>
</span>Mapserver:<br>
EXTENT 20.26 43.16 29.70 48.46 <br>
<br>
</a></div>
<a class="objectLink objectLink-object a11yFocus ">OpenLayers:<br>
var res =
[2052.453111215,1026.226555608,513.113277804,256.556638902,128.278319451,64.139159726,32.069579863,16.034789931,8.017394966,4.008697483,2.004348741,1.002174371,0.501087185];<br>
var maxRes = 2052.453111215;<br>
<br>
var lonlat = new OpenLayers.Projection("EPSG:4326");<br>
var sphericalMercator = new OpenLayers.Projection("EPSG:900913");<br>
<br>
var romaniaBounds = new OpenLayers.Bounds();<br>
romaniaBounds.extend(new OpenLayers.LonLat(20.26, 43.16));<br>
romaniaBounds.extend(new OpenLayers.LonLat(29.70, 48.46));<br>
romaniaBounds = romaniaBounds.transform(lonlat, sphericalMercator);<br>
<br>
function initStage1(){<br>
var options = { projection: sphericalMercator, displayProjection:
lonlat, units: "m", numZoomLevels: 13, maxResolution: maxRes,
maxExtent: romaniaBounds, panMethod: null, restrictedExtent:
romaniaBounds, resolutions: res};<br>
...<br>
var rtc_base = new OpenLayers.Layer.WMS('RTC TileCache',
['http://server.romtelecom.ro/tilecache/tilecache.py'],{map:
'/var/www/html/map/rtc_base.map',transparent: 'false',format:
'image/png2', map_imagetype: 'agg', layers: 'rtc_base1', maxExtent: new
OpenLayers.Bounds(20.26, 43.16, 29.70, 48.46),maxResolution: maxRes,
units: 'm'}, {isBaseLayer:true, projection: sphericalMercator,
resolutions: res});<br>
<br>
TileCache:<br>
[rtc_base1]<br>
type=WMS<br>
debug=yes<br>
url=http://terra.romtelecom.ro/fcgi-bin/mapserv?map=/var/www/html/map/rtc_base.map<br>
layers=Judete,RuralSate,Rural,Urban,highway,sechighway,streets,buildings,GranitaJudete<br>
bbox=20.26,43.16,29.70,48.46<br>
spherical_mercator=true<br>
levels=13<br>
srs=EPSG:900913<br>
size=256,256<br>
extension=png<br>
mime_type=image/png2<br>
maxResolution=2052.453111215
<br>
map_imagetype=agg
<br>
resolutions=2052.453111215,1026.226555608,513.113277804,256.556638902,128.278319451,64.139159726,32.069579863,16.034789931,8.017394966,4.008697483,2.004348741,1.002174371,0.501087185<br>
extent_type=loose<br>
</a></div>
<br>
With these settings, my request looks like this:
<a class="moz-txt-link-freetext" href="http://server.romtelecom.ro/tilecache/tilecache.py?MAP=%2Fvar%2Fwww%2Fhtml%2Fmap%2Frtc_base.map&TRANSPARENT=false&FORMAT=image%2Fpng2&MAP_IMAGETYPE=agg&LAYERS=rtc_base1&MAXEXTENT=left-bottom%3D(20.26%2C43.16)%20right-top%3D(29.7%2C48.46)&MAXRESOLUTION=2052.453111215&UNITS=m&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A900913&BBOX=2255332.8831578,5861785.2703828,2518046.8813934,6124499.2686184&WIDTH=256&HEIGHT=256">http://server.romtelecom.ro/tilecache/tilecache.py?MAP=%2Fvar%2Fwww%2Fhtml%2Fmap%2Frtc_base.map&TRANSPARENT=false&FORMAT=image%2Fpng2&MAP_IMAGETYPE=agg&LAYERS=rtc_base1&MAXEXTENT=left-bottom%3D(20.26%2C43.16)%20right-top%3D(29.7%2C48.46)&MAXRESOLUTION=2052.453111215&UNITS=m&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_in
image&SRS=EPSG%3A900913&BBOX=2255332.8831578,5861785.2703828,2518046.8813934,6124499.2686184&WIDTH=256&HEIGHT=256</a><br>
<br>
... and the output is:<br>
<pre>An error occurred: Current x value 2255332.883158 is too far from tile corner x 2293181.510030
File "/usr/lib/python2.4/site-packages/TileCache-2.10-py2.4.egg/TileCache/Service.py", line 256, in modPythonHandler
host )
File "/usr/lib/python2.4/site-packages/TileCache-2.10-py2.4.egg/TileCache/Service.py", line 181, in dispatchRequest
tile = WMS(self).parse(params, path_info, host)
File "/usr/lib/python2.4/site-packages/TileCache-2.10-py2.4.egg/TileCache/Services/WMS.py", line 19, in parse
return self.getMap(param)
File "/usr/lib/python2.4/site-packages/TileCache-2.10-py2.4.egg/TileCache/Services/WMS.py", line 27, in getMap
tile = self.getLayer(name).getTile(bbox)
File "/usr/lib/python2.4/site-packages/TileCache-2.10-py2.4.egg/TileCache/Layer.py", line 311, in getTile
coord = self.getCell(bbox)
File "/usr/lib/python2.4/site-packages/TileCache-2.10-py2.4.egg/TileCache/Layer.py", line 286, in getCell
raise TileCacheException("Current x value %f is too far from tile corner x %f" % (minx, tilex))
</pre>
<br>
My guess is the problem appears because I mix lonlat coordinates with
sphericalMercator coordinates, but it seems I do the same thing in the
first case, and there I don't have any issues.<br>
<br>
By the way, I've tried it also the other way around - using bounds in
WGS84 format and recalculating everything, but I get the same general
result.<br>
<br>
Can anyone show me what I'm doing wrong or what else I can try to debug
this problem?<br>
Thank you for your time,<br>
Adrian<br>
<pre class="moz-signature" cols="72">
</pre>
</body>
</html>