Lorenzo,<br><br>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.<br>
<br>I am throwing the php code below used for printing in the mapping application (non-ka-map) that I have running at <a href="http://maps.macnoise.com/interactive/">http://maps.macnoise.com/interactive/</a><br><br>The things that you might want to take a look at are:
<br>- increasing the resolution of the jpeg images used for the map and used in the legend<br>- use vector text for the legend<br>- variable height map image and legend area -- map gets smaller, legend gets bigger as more objects get added to the legend
<br> try adding/removing layers from the application above to see what I mean<br><br>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).
<br><br>I hope that some of this can help you!<br><br>Ciao,<br>bit<br><br><br><?php<br>dl("php_mapscript.so");<br>$mapfile=$_REQUEST['map'];<br>$map = ms_newMapObj($mapfile);<br>$map->selectOutputFormat('jpeg'); //fpdf seems to play better with jpeg
<br><br>//get map extent<br>if ($_REQUEST['mapext']) { <br> $mapext = $_REQUEST['mapext'];<br> $extent = explode(" ", $mapext);<br> $map->setExtent($extent[0], $extent[1],$extent[2], $extent[3]);
<br>}<br><br>//get list of layers and cycle through to turn them on<br>if (isset($_REQUEST['layers'])) {<br> $layerlist = rtrim($_REQUEST['layers']);<br> $layers = explode(" ", $layerlist);<br> $numLayers = $map->numlayers;
<br> for ($i = 0; $i < $numLayers; $i++) {<br> $activeLayer = $map->getlayer($i);<br> if ($activeLayer->status != 2) $activeLayer->set("status", 0);<br> }<br> foreach ($layers as $l) {
<br> $activeLayer = $map->getlayerbyname($l);<br> $activeLayer->set("status", 1);<br> }<br>}<br><br>// this is used to allow cgi substitutions in data strings<br>for ($i = 0; $i < $map->numlayers; $i++) {
<br> $activeLayer = $map->getlayer($i);<br> $datastring=$activeLayer->data;<br> if (preg_match_all("/%([\w].+?)%/",$datastring,$matches,PREG_SET_ORDER)>0){<br> foreach ($matches as $match){
<br> $search=$match[0];<br> $replace=$match[1];<br> if (isset($_REQUEST[$replace])){<br> $replaceval=$_REQUEST[$replace];<br> $datastring=str_replace($search,$replaceval,$datastring);
<br> $activeLayer->set("data",$datastring);<br> } else {<br> $activeLayer->set("status", 0);<br> }<br> }<br> <br> } <br>}<br>
$headerstring='';<br><br>//conditionals used to only display certain messages when certain layers are turned on<br>$ft=$map->getlayerbyname('FlightTracks');<br>$ftstat=$ft->status;<br>$add=$map->getlayerbyname('house');
<br>$addstat=$add->status;<br>if ($ftstat==1) $headerstring=$headerstring.'Time Period: '.$_REQUEST['sDate'].'-'.$_REQUEST['eDate'];<br>if ($addstat==1) $headerstring=$headerstring.' Address Shown: '.$_REQUEST['add'];<br>
<br><br>$resolution=isset($_REQUEST['resolution'])?$_REQUEST['resolution']:150; //allows to set resolution or defaults to 150dpi<br>$mapfile_resolution=$map->resolution;<br>$scalefactor=$resolution/$mapfile_resolution; //how much everything needs to be multiplied by
<br>$map->set('resolution',$resolution); // set new resolution for min/max scale renderings<br><br><br>// loop through layers to extract class images and names and to resize styles and truetype symbols<br>$numLayers = $map->numlayers;
<br>$classimages=array();<br>$classnames=array();<br>for ($i=0; $i < $numLayers; $i++) {<br> $layer = $map->getlayer($i);<br> if ($layer->status == 1 ){<br> for ($j=0; $j < $layer->numclasses; $j++) {
<br> $class = $layer->getClass($j);<br> $label = $class->label;<br> if ($layer->type !=4){<br> $classimageobj=$class->createLegendIcon(60,60);<br> $classimages[]=$classimageobj->saveWebImage();
<br> $classnames[]=$class->name;<br> }<br> if ($label->mindistance>1){<br> $md=$label->mindistance;<br> $newmd=$md*$scalefactor;<br> $label->set('mindistance',$newmd);
<br> }<br> if ($label->type == 'TRUETYPE') {<br> $labelsize=$label->size;<br> $newlabelsize=$labelsize*$scalefactor;<br> $label->set('size',$newlabelsize);<br> }
<br> for ($k=0; $k < $class->numstyles; $k++) {<br> $style = $class->getStyle($k);<br> $style->set("size", $style->size * $scalefactor);<br> $style->set("offsetx", $style->offsetx * $scalefactor);
<br> $style->set("offsety", $style->offsety * $scalefactor);<br> }<br> }<br> }<br>}<br>$nrows=ceil(count($classnames)/4); // make 4 columns to display legend<br>$legheight=$nrows*.25; // determine height of legend
<br>$mapheight=9.3-$legheight; // determine area left to draw map<br>$legstart=$mapheight+1.05; // determine where to start the legend<br><br>$map->set("width", 7.6*$resolution);<br>$map->set("height", $resolution*$mapheight); // make map rectangle fit page
<br>//echo $mapheight*$resolution;<br>//draw map<br>$imgMap = $map->draw();<br>$urlMap = $imgMap->saveWebImage();<br><br>require('fpdf.php');<br>class PDF extends FPDF<br>{<br>//Page header<br>function Header()<br>{
<br> <br>}<br><br>//Page footer<br>function Footer()<br>{<br> $this->SetY(-1);<br> $this->SetFont('Arial','I',7);<br>}<br>function draw_legend($textarray,$imgarray,$startx,$starty,$nr){ // function draws the 4 column table
<br> $this->SetFont('Times','',12);<br> $y=$starty-.25;<br> $x=$startx;<br> $first=true;<br> <br> for ($i=0;$i<count($textarray);$i++){<br> if ($i==$nr or $i==2*$nr or $i==3*$nr) {<br> $y=$starty-.25;
<br> $x=$x+1.9;<br> $first=false;<br> }<br> $y=$y+.25;<br> $imgurl=$imgarray[$i];<br> $text=$textarray[$i];<br> $this->Image($imgurl,$x,$y,.20,.20);<br> $this->Text($x+.25,$y+.15,$text);
<br> }<br>}<br>}<br><br>//Instanciation of inherited class<br>$pdf=new PDF('P','in','letter');<br><br>$pdf->SetDisplayMode('fullpage');<br>$pdf->SetMargins(.25,.25);<br><br>$pdf->AddPage();<br><br><br>$pdf->SetFont('Arial','B',14);
<br>$pdf->Cell(0,.50,'MACNOISE Interactive Map',0,1,'C');<br>$pdf->SetFont('Arial','',10);<br>$pdf->Cell(0,.02,$headerstring,0,1,'C');<br><br><br>$pdf->SetLineWidth(.1);<br>$pdf->SetDrawColor(0,0,150);<br>$pdf->Rect(.25,.25,8,
10.5);<br><br>$pdf->Image($urlMap,.45,.9,7.6,$mapheight);<br>$pdf->Image("/var/apache/htdocs/graphics/MACnorth.png",.45,.9,1,1);<br><br>$pdf->SetLineWidth(.01);<br>$pdf->SetDrawColor(0,0,200);<br>$pdf->Rect(.40,.85,
7.7,$mapheight+.1);<br>$pdf->Rect(.40,$legstart,7.7,$legheight+.1);<br><br>$date=date('M j, Y g:i');<br>$datemessage="Map created by <a href="http://maps.macnoise.com/interactive/">http://maps.macnoise.com/interactive/
</a> on $date. This information is to be used for reference purposes only.";<br>$disclaimer="The Metropolitan Airports Commission does not guarantee accuracy of the material contained herein and is not responsible for misuse or misinterpretation.";
<br>$pdf->SetFont('Arial','I',7);<br>$pdf->Text(.45,10.55,$datemessage);<br>$pdf->Text(.45,10.65,$disclaimer);<br>$pdf->SetTitle('MACNoise Interactive Map');<br>$pdf->draw_legend($classnames,$classimages,.45,$legstart+.05,$nrows);
<br><br>$pdf->Output();<br>//$pdf->Output('macnoise.pdf','D');<br>?>