[mapserver-users] mapserver(ms4w) map script mode
Worth Lutz
wal3 at mindspring.com
Thu May 19 06:19:59 PDT 2016
Here is an extraction of some of my code. I get PDF maps to an accurate
scale when printed.
All steps are necessary and must be in the order described.
$map = new mapObj($mapfile);
$map->selectOutputFormat('PDF'); // defined in mapfile
// set mapsize using pdfMapDef paper sizes
// $map->resolution defaults to 72 pixels/inch
$w = $width_inches * $map->resolution;
$h = $height_inches * $map->resolution;
$map->setSize($w, $h); //in pixels
// set to actual sizes set by 'setSize'
$w = $map->width;
$h = $map->height;
$map->setExtent($bounds[0], $bounds[1], $bounds[2], $bounds[3]);
// calculate center point in pixels
// this center will not be very accurate as it is a pixel value??
$x = $w * ($center->x - $map->extent->minx) / ($map->extent->maxx -
$map->extent->minx);
$y = $h - ($h * ($center->y - $map->extent->miny) /
($map->extent->maxy - $map->extent->miny));
$center_pixel = new pointObj();
$center_pixel->setXY($x, $y);
// this zooms the map to scale given in $scaleDemon
// but the center value is not accurate enough for small scale maps
$scaleDenom = 4000;
$success = $map->zoomScale($scaleDenom, $center_pixel, $w, $h,
$map->extent);
if ($success == MS_FAILURE) echo "\n FAILURE OF zoomScale";
// set the desired center in map units to get a better map
$x_mapunits = <your value here>;
$y_mapunits = <your value here>;
// here setCenter will set the center point of the map based upon
// the center value in map units not pixels
$center_mapunits = new pointObj();
$center_mapunits->setXY($x_mapunits, $y_mapunits);
$success = $map->setCenter($center_mapunits);
if ($success == MS_FAILURE) echo "\n FAILURE OF setCenter";
// ** turn on desired layers here **
$img = $map->draw();
$outfile = $img->saveWebimage();
*Worth Lutz*
On 05/18/2016 07:10 AM, ankur chitranshi wrote:
> hello all,
>
> can any body help me out in how touser-define map scale manually in
> mapserver(ms4w) map script mode
>
> --
> thanks & regards
> Ankur Chitranshi
>
>
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20160519/f3f6d04c/attachment.htm>
More information about the MapServer-users
mailing list