[ka-Map-users] print system pdf

David William Bitner bitner at gyttja.org
Mon Jun 19 16:39:50 EDT 2006


I just went through and tried to add some comments to the print system that
I use based on FPDF.  I think that we can mesh together what you are doing
with some additional things that I have implemented.

I am throwing the php code below used for printing in the mapping
application (non-ka-map) that I have running at

The things that you might want to take a look at are:
- increasing the resolution of the jpeg images used for the map and used in
the legend
- use vector text for the legend
- variable height map image and legend area -- map gets smaller, legend gets
bigger as more objects get added to the legend
    try adding/removing layers from the application above to see what I mean

An additional thing that I haven't yet had time to implement would be a
vector scalebar using the rectangle draw tools in fpdf. (Currently my in
image scalebar is rather pathetic as you can see especially if you make a
pdf then throw an extra paramater &resolution=300 on the end).

I hope that some of this can help you!


$map = ms_newMapObj($mapfile);
$map->selectOutputFormat('jpeg'); //fpdf seems to play better with jpeg

//get map extent
if ($_REQUEST['mapext']) {
       $mapext = $_REQUEST['mapext'];
       $extent = explode(" ", $mapext);
       $map->setExtent($extent[0], $extent[1],$extent[2], $extent[3]);

//get list of layers and cycle through to turn them on
if (isset($_REQUEST['layers'])) {
       $layerlist = rtrim($_REQUEST['layers']);
       $layers = explode(" ", $layerlist);
       $numLayers = $map->numlayers;
       for ($i = 0; $i < $numLayers; $i++) {
               $activeLayer = $map->getlayer($i);
               if ($activeLayer->status != 2) $activeLayer->set("status",
       foreach ($layers as $l) {
               $activeLayer = $map->getlayerbyname($l);
               $activeLayer->set("status", 1);

// this is used to allow cgi substitutions in data strings
for ($i = 0; $i < $map->numlayers; $i++) {
    $activeLayer = $map->getlayer($i);
        foreach ($matches as $match){
            if (isset($_REQUEST[$replace])){
            } else {
            $activeLayer->set("status", 0);


//conditionals used to only display certain messages when certain layers are
turned on
if ($ftstat==1) $headerstring=$headerstring.'Time Period:
if ($addstat==1) $headerstring=$headerstring.' Address Shown:

//allows to set resolution or defaults to 150dpi
$scalefactor=$resolution/$mapfile_resolution; //how much everything needs to
be multiplied by
$map->set('resolution',$resolution); // set new resolution for min/max scale

// loop through layers to extract class images and names and to resize
styles and truetype symbols
$numLayers = $map->numlayers;
for ($i=0; $i < $numLayers; $i++) {
    $layer = $map->getlayer($i);
    if ($layer->status == 1 ){
    for ($j=0; $j < $layer->numclasses; $j++) {
        $class = $layer->getClass($j);
        $label = $class->label;
        if ($layer->type !=4){
        if ($label->mindistance>1){
        if ($label->type == 'TRUETYPE') {
        for ($k=0; $k < $class->numstyles; $k++) {
            $style = $class->getStyle($k);
            $style->set("size", $style->size * $scalefactor);
            $style->set("offsetx", $style->offsetx * $scalefactor);
            $style->set("offsety", $style->offsety * $scalefactor);
$nrows=ceil(count($classnames)/4); // make 4 columns to display legend
$legheight=$nrows*.25; // determine height of legend
$mapheight=9.3-$legheight; // determine area left to draw map
$legstart=$mapheight+1.05; // determine where to start the legend

$map->set("width", 7.6*$resolution);
$map->set("height", $resolution*$mapheight); // make map rectangle fit page
//echo $mapheight*$resolution;
//draw map
$imgMap = $map->draw();
$urlMap = $imgMap->saveWebImage();

class PDF extends FPDF
//Page header
function Header()


//Page footer
function Footer()
function draw_legend($textarray,$imgarray,$startx,$starty,$nr){ // function
draws the 4 column table

    for ($i=0;$i<count($textarray);$i++){
        if ($i==$nr or $i==2*$nr or $i==3*$nr) {

//Instanciation of inherited class
$pdf=new PDF('P','in','letter');



$pdf->Cell(0,.50,'MACNOISE Interactive Map',0,1,'C');




$date=date('M j, Y g:i');
$datemessage="Map created by http://maps.macnoise.com/interactive/ on $date.
This information is to be used for reference purposes only.";
$disclaimer="The Metropolitan Airports Commission does not guarantee
accuracy of the material contained herein and is not responsible for misuse
or misinterpretation.";
$pdf->SetTitle('MACNoise Interactive Map');

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/ka-map-users/attachments/20060619/78f31e04/attachment.html

More information about the ka-Map-users mailing list