[mapserver-users] define a layers size display in mapfile (mapscript) how???

Worth Lutz wal3 at mindspring.com
Fri May 20 06:40:19 PDT 2016


I answered this before on this list.

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 5/20/2016 3:05 AM, ankur chitranshi wrote:
> hello All,
>
>
> How to define a layer display scale in mapfile in mapscript 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/20160520/0acffec5/attachment-0001.html>


More information about the mapserver-users mailing list