map->scale
Tim Schaub
tim at COMMENSPACE.ORG
Thu Jan 5 11:15:59 PST 2006
> I'm trying to migrate a CGI application of map server to a
> PHPMapScript driven one, and in the former exists the scale
> environment variable but in the other, and according to the
> documentation, there isn't, and the app should set it.
If you have a reference to your map in PHP (say $theMap), you can get the map scale from $theMap->scale (see http://mapserver.gis.umn.edu/docs/reference/phpmapscript-class/classes/mapobj)
The map scale is updated after a drawMap() or preparequery().
If you really wanted to calculate it yourself, I'm guessing you can do something like this:
function getScale($theMap) {
if($theMap->units == MS_PIXELS) {
return 1;
}
$inchesPerMapUnit = array(
MS_INCHES => 1,
MS_FEET => 12,
MS_MILES => 63360,
MS_METERS => 39.370079,
MS_KILOMETERS => 39370.07874,
MS_DD => 4374720);
$mapUnitWidth = $theMap->extent->maxx - $theMap->extent->minx;
$mapPixelWidth = $theMap->width;
// assuming the map is wider than zero pixels
return $inchesPerMapUnit[$theMap->units] * $mapUnitWidth * $theMap->resolution / $mapPixelWidth;
}
No guarantees that that is how they do it (I didn't test it). But it seems to me like it should work.
Tim Schaub
http://www.commenspace.org
> Thanks in advance,
>
> Diego.
>
> P.S.: excuse my poor english
>
> __________________________________________________
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
> Regístrate ya - http://correo.espanol.yahoo.com/
>
More information about the MapServer-users
mailing list