How to use zoomscale function in PHP mapscript
Dylan Keon
keon at NACSE.ORG
Fri Feb 25 12:41:50 PST 2005
A. Sharif wrote:
> Hello,
>
> I am trying to create a map with a dynamic point, at a determined zoomscale.
>
> When i use the function $oMap->zoomscale, the coordinates I have to
> pass the function are the X,Y in pixels, whereas I have Longitude,
> Latitude coordinates.
>
> Is there a way to convert the Geographic coordinates to pixel
> coordinates, or is a different function that will the geogrphic
> coordinates and display the map at a determined scale ?
Abdul,
Here's the function I use to convert x,y in pixels to coordinates.
There are probably more examples in the list archives.
--Dylan
// Function to convert an x,y pair of pixel coords to geographic coords
// $extent array is (minx,miny,maxx,maxy)
function pix2geo($imgX, $imgY, $extent)
{
GLOBAL $map;
$imgWidth = $map->width;
$imgHeight = $map->height;
$mapX = (($imgX / $imgWidth) * ($extent[2] - $extent[0])) +
$extent[0];
$mapY = $extent[3] - (($imgY / $imgHeight) * ($extent[3] -
$extent[1]));
$coords = $mapX . ',' . $mapY;
return $coords;
}
More information about the MapServer-users
mailing list