[mapserver-users] I have a question about the GMapPix2Geo function (listed below).

Debbie Pagurek pagurekd at agr.gc.ca
Wed Oct 23 08:14:32 PDT 2002


I have a question about the GMapPix2Geo function (listed below).
I have a map of the world showing in lat long.  The below function only seems to work if I am zoomed IN really far and it doesn't work if I am at the full extent of the map (minx=-180, maxx=180, miny=-90, maxy=90)

Can anyone comment on this?  I wanted to build a mouseover function that will show the coordinates of the mouse position in the windows status bar.

Thanks,
D. Pagurek


/************************************************************************/
/*function GMapPix2Geo($nPixPos, $dfPixMin, $dfPixMax, $dfGeoMin,dfGeoMax, $nInversePix)                              */
/*      Utility function to convert a pixel position to geocoded            position.                                                       */
/*                                                                      */
/*       The parameter $nInversePix could be set to 1 for Y pixel coordinates where the UL > LR. Else set to 0.                   */
/************************************************************************/
function GMapPix2Geo($nPixPos, $dfPixMin, $dfPixMax, $dfGeoMin, $dfGeoMax, $nInversePix) 
{
   // $nPixPos : pixel position (X or Y)
   // $dfPixMin, $dfPixMax : Pixel minimum and maximum (X or Y) of your map on the screen (should be 0 to xxx)
  //  $dfGeoMin, $dfGeoMax : Geographic coordinate min max (X or Y) of your map on the screen 

    $dfWidthGeo = $dfGeoMax - $dfGeoMin;
    $dfWidthPix = $dfPixMax - $dfPixMin;
   
    
    $dfPixToGeo = $dfWidthGeo / $dfWidthPix;

    if (!$nInversePix)
        $dfDeltaPix = $nPixPos - $dfPixMin;
    else
        $dfDeltaPix = $dfPixMax - $nPixPos;

    $dfDeltaGeo = $dfDeltaPix * $dfPixToGeo;


    $dfPosGeo = $dfGeoMin + $dfDeltaGeo;

    return ($dfPosGeo);
}






More information about the MapServer-users mailing list