[ka-Map-users] MIscalculation of coordinates for a tile in debug mode (applies to cvs and 0.1.1 versions)

OSK oskosk at gmail.com
Mon Jul 31 02:08:57 EDT 2006


Synopsis
=======

In the file tile.php there is a miscalculation that ends up printing
the wrong coordinates for a tile in debug mode.

Background
=========

The tile.php file is used to get a tile by the ka-map's javascript code.
The config.php (configuration file) provides a flag ($bDebug) which if
set to true, tile.php will take in account and print debugging
information on the generated tile.

Affected Versions
==============

At least current CVS version (0.2.0) and 0.1.1

Description
=========

In tile.php , this line is used to 'draw' the coordinates of the
tile's top and left inside the tile image. (line 328 in CVS file
release number 1.39, line 231 in ka-map 0.1.1)

imagestring ( $oTile, 3, 10, 30, ($minx+$i*$geoWidth)." x ".($maxy -
$j*$geoHeight), $black );

, being ($minx+$i*$geoWidth) the calculation for the longitude and
($maxy - $j*$geoHeight) for the latitude of a tile's left and top
borders respectively.

- $minx and $maxy hold the values for the longitude and latitude,
respectively of the left and top borders of the metaTile that includes
the requested tile. ( the buffer in pixels used to request mapserver
the metaTile is also included when $minx and $maxy are calculated);
- $geoWidth holds the value for how many degrees a pixel represents
for the current map in the requested scale.
- $i  serves as an index for iteration from 0 to $metaWidth (the
number of tiles that compose the metaTile width).
-$j is used for the same purpose as $i but for the Height of the metaTile.
 $i and $j are used for iterating (being incremented by one in each
iteration) for cutting the tiles that belong to the same metaTile that
the requested tile belongs to, for precaching.

A couple of things are missing in both calculations:

First , for example,  when $i equals 1 in the second iteration, and
with the current calculation being ($minx+$i*$geoWidth) the code is
printing that the second tile from a metaTile is just one pixel away
from the first one, because in the calculation, the code does not take
in account the tile width for getting the final coordinates. The same
goes for the height.

The other issue is that in both calculations the buffer used for the
metaTile generation is not included in the sum that gets the final
coordinates for the tile.

Resolution
=========

The line should be replaced to take in account the width and height of
each tile as also should the buffer used to generate the meta Tile.

I think something like this will do:

imagestring ( $oTile, 3, 10, 30, ($minx+ ($metaBuffer * $geoWidth) +
($i * $tileWidth *$geoWidth)) ." x ". (  $maxy - (  ($metaBuffer *
$geoWidth) + ($j * $tileHeight * $geoHeight) )  ), $black );


Hope the explanation was useful, greetings
-- 
OSK


More information about the ka-Map-users mailing list