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

Jeff McKenna jmckenna at gatewaygeomatics.com
Fri May 20 06:51:13 PDT 2016


Hi Worth, how about adding your code onto a new wiki page, so it isn't 
lost and forgotten?  Maybe add a page in the "Tricks, Tips, and HowTos" 
section at: https://github.com/mapserver/mapserver/wiki

Thanks,

-jeff


-- 
Jeff McKenna
MapServer Consulting and Training Services
http://www.gatewaygeomatics.com/



On 2016-05-20 10:40 AM, Worth Lutz wrote:
> 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*
>




More information about the mapserver-users mailing list