[Mapbender-commits] r5518 - trunk/mapbender/http/print/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Feb 19 05:22:53 EST 2010


Author: christoph
Date: 2010-02-19 05:22:52 -0500 (Fri, 19 Feb 2010)
New Revision: 5518

Added:
   trunk/mapbender/http/print/classes/mbLegendDecorator.php
Modified:
   trunk/mapbender/http/print/classes/mbTemplatePdf.php
Log:


Added: trunk/mapbender/http/print/classes/mbLegendDecorator.php
===================================================================
--- trunk/mapbender/http/print/classes/mbLegendDecorator.php	                        (rev 0)
+++ trunk/mapbender/http/print/classes/mbLegendDecorator.php	2010-02-19 10:22:52 UTC (rev 5518)
@@ -0,0 +1,83 @@
+<?php
+require_once dirname(__FILE__)."/../../classes/class_SaveLegend.php";
+
+class mbLegendDecorator extends mbTemplatePdfDecorator {
+
+	protected $pageElementType = "legend";
+	protected $elementId;
+	
+	public function __construct($pdfObj, $elementId, $mapConf, $controls) {
+		parent::__construct($pdfObj, $mapConf, $controls);
+		$this->elementId = $elementId;
+		$this->decorate();	
+	}
+	
+	public function override () {
+		return null;
+	}
+	
+	public function decorate() {
+		$mmPerPt = 0.3527;
+
+		$this->pdf->objPdf->setTextColor(0, 0, 0);
+		$this->pdf->objPdf->setFont($this->conf->font_family, "", $this->conf->font_size);
+
+		$currentX = $this->conf->x_ul;
+		$currentY = $this->conf->y_ul;
+
+		$json = new Mapbender_JSON();
+		$wmsLegendArray = $json->decode($_POST["legend_url"]);
+		if (!is_array($wmsLegendArray)) {
+			//TODO: error message
+			return;
+		}
+		for ($i = 0; $i < count($wmsLegendArray); $i ++) {
+			$layerLegendObj = $wmsLegendArray[$i];
+			if (!is_object($layerLegendObj)) {
+				continue;
+			}
+			foreach ($layerLegendObj as $title => $layerLegendArray) {
+				if (!is_array($layerLegendArray)) {
+					continue;
+				}
+				// Title
+				$this->pdf->objPdf->Text($currentX, $currentY, $title);
+				$currentY += $mmPerPt * $this->conf->font_size;
+//				$currentY += $this->conf->font_size;
+				
+				for ($j = 0; $j < count($layerLegendArray); $j++) {
+					// Legend
+					$currentLegendObj = $layerLegendArray[$j];
+					
+					// store current legend image temporarily
+					$legendFilename = TMPDIR . "/legend_" . 
+						substr(md5(uniqid(rand())),0,7).".png";
+					$saveLegend = new SaveLegend(
+						$currentLegendObj->legendUrl,
+						$legendFilename
+					);
+					list($width, $height) = getimagesize($legendFilename);
+					$width = $width/$this->pdf->objPdf->k;
+					$height = $height/$this->pdf->objPdf->k;
+
+					$this->pdf->objPdf->Image(
+						$legendFilename, 
+						$currentX, 
+						$currentY-3.5,
+						$width,
+						$height
+					);
+
+
+					$currentY += $height;
+					
+				}
+				$currentY += 5;
+
+			}
+		}
+	}
+}
+
+
+?>

Modified: trunk/mapbender/http/print/classes/mbTemplatePdf.php
===================================================================
--- trunk/mapbender/http/print/classes/mbTemplatePdf.php	2010-02-19 10:22:27 UTC (rev 5517)
+++ trunk/mapbender/http/print/classes/mbTemplatePdf.php	2010-02-19 10:22:52 UTC (rev 5518)
@@ -82,6 +82,9 @@
 					case "image":
 						$err = new mbImageDecorator($this, $pageElementId, $pageElementConf, $controls);
 						break;																									
+					case "legend":
+						$err = new mbLegendDecorator($this, $pageElementId, $pageElementConf, $controls);
+						break;																									
 				}
             }
             



More information about the Mapbender_commits mailing list