[Mapbender-commits] r8687 - in trunk/mapbender: http/classes http/plugins http/print http/print/classes resources/db/pgsql/UTF-8/update

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Aug 16 07:07:44 PDT 2013


Author: verenadiewald
Date: 2013-08-16 07:07:43 -0700 (Fri, 16 Aug 2013)
New Revision: 8687

Modified:
   trunk/mapbender/http/classes/class_weldMaps2PNG.php
   trunk/mapbender/http/classes/class_weldMaps2PNG_rotate.php
   trunk/mapbender/http/plugins/mb_print.php
   trunk/mapbender/http/print/classes/mbLegendDecorator.php
   trunk/mapbender/http/print/classes/mbMapDecorator.php
   trunk/mapbender/http/print/classes/mbTemplatePdf.php
   trunk/mapbender/http/print/printFactory.php
   trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.3_to_2.7.4_pgsql_UTF-8.sql
Log:
http://trac.osgeo.org/mapbender/ticket/910
http://trac.osgeo.org/mapbender/ticket/911

Modified: trunk/mapbender/http/classes/class_weldMaps2PNG.php
===================================================================
--- trunk/mapbender/http/classes/class_weldMaps2PNG.php	2013-08-05 10:44:33 UTC (rev 8686)
+++ trunk/mapbender/http/classes/class_weldMaps2PNG.php	2013-08-16 14:07:43 UTC (rev 8687)
@@ -29,16 +29,18 @@
 
 class weldMaps2PNG{
 
-	function weldMaps2PNG($urls,$filename, $encode = true){
+	function weldMaps2PNG($urls,$filename, $encode = true, $opacities=""){
 		if(!$urls || $urls == ""){
 			$e = new mb_exception("weldMaps2PNG: no maprequests delivered");
 		}
 		$url = explode("___", $urls);
+		$opacities = explode("___",$opacities);
 		$obj1 = new stripRequest($url[0]);
 		$width = $obj1->get("width");
 		$height = $obj1->get("height");
 		
 		$image = imagecreatetruecolor($width, $height	);
+		imagealphablending($image,true);
 		$white = ImageColorAllocate($image,255,255,255); 
 		ImageFilledRectangle($image,0,0,$width,$height,$white); 
 
@@ -48,8 +50,16 @@
 			$url[$i] = $obj->setPNG();
 			$url[$i] = $obj->encodeGET($encode);
 			$img = $this->loadpng($url[$i]);
+			
+			$opacity = $opacities[$i] *100;
+			
 			if($img != false){
+				if(imagecolortransparent($img) > -1 ){
+					imagecopymerge($image, $img, 0, 0, 0, 0, $width, $height,$opacity);
+				}else{
+					$this->filter_opacity($img,$opacity);
 				imagecopy($image, $img, 0, 0, 0, 0, $width, $height);
+				}
 				@imagedestroy($img); 
 			}
 			else{
@@ -77,6 +87,51 @@
 		
 	}
 	
+	function filter_opacity( &$img, $opacity ) //params: image resource id, opacity in percentage (eg. 80)
+	{
+		if( !isset( $opacity ) )
+		{ return false; }
+		$opacity /= 100;
+		 
+		//get image width and height
+		$w = imagesx( $img );
+		$h = imagesy( $img );
+		 
+		//turn alpha blending off
+		imagealphablending( $img, false );
+		 
+		//find the most opaque pixel in the image (the one with the smallest alpha value)
+		$minalpha = 0;
+		for( $x = 0; $x < $w; $x++ )
+			for( $y = 0; $y < $h; $y++ )
+			{
+				$alpha = ( imagecolorat( $img, $x, $y ) >> 24 ) & 0xFF;
+				if( $alpha < $minalpha )
+				{ $minalpha = $alpha; }
+			}
+			 
+			//loop through image pixels and modify alpha for each
+			for( $x = 0; $x < $w; $x++ )
+			{
+				for( $y = 0; $y < $h; $y++ )
+				{
+					//get current alpha value (represents the TANSPARENCY!)
+					$colorxy = imagecolorat( $img, $x, $y );
+					$alpha = ( $colorxy >> 24 ) & 0xFF;
+					//calculate new alpha
+					if( $minalpha !== 127 )
+					{ $alpha = 127 + 127 * $opacity * ( $alpha - 127 ) / ( 127 - $minalpha ); }
+					else
+					{ $alpha += 127 * $opacity; }
+					//get the color index with new alpha
+					$alphacolorxy = imagecolorallocatealpha( $img, ( $colorxy >> 16 ) & 0xFF, ( $colorxy >> 8 ) & 0xFF, $colorxy & 0xFF, $alpha );
+					//set pixel with the new color + opacity
+					if( !imagesetpixel( $img, $x, $y, $alphacolorxy ) )
+					{ return false; }
+				}
+			}
+			return true;
+	}
 }
 
 ?>

Modified: trunk/mapbender/http/classes/class_weldMaps2PNG_rotate.php
===================================================================
--- trunk/mapbender/http/classes/class_weldMaps2PNG_rotate.php	2013-08-05 10:44:33 UTC (rev 8686)
+++ trunk/mapbender/http/classes/class_weldMaps2PNG_rotate.php	2013-08-16 14:07:43 UTC (rev 8687)
@@ -30,7 +30,7 @@
 
 class weldMaps2PNG_rotate extends weldMaps2PNG{
 
-    function weldMaps2PNG_rotate($urls,$filename, $angle, $encode = true){
+    function weldMaps2PNG_rotate($urls,$filename, $angle, $encode = true, $opacities = ""){
         if(!$urls || $urls == ""){
             $e = new mb_exception("weldMaps2PNG_rotate: no maprequests delivered");
         }
@@ -59,7 +59,7 @@
 
         //get image
         $urls = implode("___", $url);
-        $this->weldMaps2PNG($urls, $filename, $encode);
+        $this->weldMaps2PNG($urls, $filename, $encode, $opacities);
         
 
         //rotate image

Modified: trunk/mapbender/http/plugins/mb_print.php
===================================================================
--- trunk/mapbender/http/plugins/mb_print.php	2013-08-05 10:44:33 UTC (rev 8686)
+++ trunk/mapbender/http/plugins/mb_print.php	2013-08-16 14:07:43 UTC (rev 8687)
@@ -467,6 +467,7 @@
 		var ind = getMapObjIndexByName(myTarget);
 		var f = jqForm[0];
 		f.map_url.value = '';
+        f.opacity.value = "";
 		
 		var scale = f.scale.value || mb_mapObj[ind].getScale();
 		scale = parseInt(scale, 10);
@@ -480,10 +481,14 @@
 					if(f.map_url.value != ""){
 						f.map_url.value += '___';
 					}      
+					if(f.opacity.value != ""){
+						f.opacity.value += '___';
+					}   
 					var currentMapUrl = mb_mapObj[ind].getMapUrl(i, mb_mapObj[ind].getExtentInfos(), scale);
 					
 					currentMapUrl = replaceMapFileForHighQualityPrint(currentMapUrl, "map");
-					f.map_url.value += currentMapUrl
+					f.map_url.value += currentMapUrl;
+					f.opacity.value += mb_mapObj[ind].wms[i].gui_wms_mapopacity;
 
 					var wmsLegendObj = [];
 					
@@ -520,6 +525,7 @@
 		updateFormField(formData, "legend_url", legendUrlArrayJson);
 		updateFormField(formData, "map_url", f.map_url.value);
 		updateFormField(formData, "scale", scale);
+		updateFormField(formData, "opacity",f.opacity.value);		
 		
 		//overview_url
 		var ind_overview = getMapObjIndexByName('overview');

Modified: trunk/mapbender/http/print/classes/mbLegendDecorator.php
===================================================================
--- trunk/mapbender/http/print/classes/mbLegendDecorator.php	2013-08-05 10:44:33 UTC (rev 8686)
+++ trunk/mapbender/http/print/classes/mbLegendDecorator.php	2013-08-16 14:07:43 UTC (rev 8687)
@@ -24,6 +24,8 @@
 
 		$currentX = $this->conf->x_ul;
 		$currentY = $this->conf->y_ul;
+			$cols = $this->pdf->legendColumns;
+			$colWidth = $this->pdf->objPdf->w / $cols;
 
 		$json = new Mapbender_JSON();
 		$wmsLegendArray = $json->decode($_POST["legend_url"]);
@@ -46,7 +48,7 @@
 				$this->pdf->objPdf->Text($currentX, $currentY, html_entity_decode(utf8_decode($title)));
 //				$currentY += $mmPerPt * $this->conf->font_size;
 				$currentY += $titleFontSize;
-				
+
 				$this->pdf->objPdf->setFont($this->conf->font_family, "", $this->conf->font_size);
 				for ($j = 0; $j < count($layerLegendArray); $j++) {
 					// Legend
@@ -71,7 +73,7 @@
 					$this->pdf->objPdf->Image(
 						$legendFilename, 
 						$currentX, 
-						$currentY-3.5,
+						$currentY-7.5,
 						($width * $this->conf->scale)
 					);
 					}catch(Exception $E){
@@ -81,10 +83,33 @@
 
 					$currentY += ($height * $this->conf->scale) ;
 					
+					if($currentY > ($this->pdf->objPdf->h)-40 AND $j < count($layerLegendArray)-1){
+						//$currentX += 50;
+						$currentX += $colWidth;
+						$currentY = $this->conf->y_ul;
+						if($currentX > ($this->pdf->objPdf->w)-30){
+							$tplidx = $this->pdf->objPdf->importPage(2);
+							$this->pdf->objPdf->addPage();
+							$this->pdf->objPdf->useTemplate($tplidx);
+							$currentX = $this->conf->x_ul;
+							$currentY = $this->conf->y_ul;
+						}
+					}
 				}
 				$currentY += 5;
-
 			}
+			if($currentY > ($this->pdf->objPdf->h)-40 ){
+				//$currentX += 50;
+				$currentX += $colWidth;
+				$currentY = $this->conf->y_ul;
+				if($currentX > ($this->pdf->objPdf->w)-30 AND $i < count($wmsLegendArray)-1){
+					$tplidx = $this->pdf->objPdf->importPage(2);
+					$this->pdf->objPdf->addPage();
+					$this->pdf->objPdf->useTemplate($tplidx);                         
+					$currentX = $this->conf->x_ul;
+					$currentY = $this->conf->y_ul;                      
+				}
+			}
 		}
                 $this->pdf->unlink($legendFilename); 
 	}

Modified: trunk/mapbender/http/print/classes/mbMapDecorator.php
===================================================================
--- trunk/mapbender/http/print/classes/mbMapDecorator.php	2013-08-05 10:44:33 UTC (rev 8686)
+++ trunk/mapbender/http/print/classes/mbMapDecorator.php	2013-08-16 14:07:43 UTC (rev 8687)
@@ -58,6 +58,7 @@
 	
 	public function decorate() {
 		$urls = $_REQUEST["map_url"];
+        $opacity = $_REQUEST["opacity"];
 		$array_urls = explode("___", $urls);
 		//problem with false in some map_urls see http/plugins/mb_metadata_wmcPreview.php
 		//exchange array_urls with array_urls without false entries
@@ -98,13 +99,13 @@
 		
 		if ($this->angle != 0) {
 			if (class_exists('weldMaps2PNG_rotate')) {
-				$i = new weldMaps2PNG_rotate(implode("___",$array_urls), $this->filename, $this->angle, false);
+				$i = new weldMaps2PNG_rotate(implode("___",$array_urls), $this->filename, $this->angle, false,$opacity);
 			} else {
-				$i = new weldMaps2PNG(implode("___",$array_urls), $this->filename, false);
+				$i = new weldMaps2PNG(implode("___",$array_urls), $this->filename, false, $opacity);
 				$e = new mb_warning("mbMapDecorator: no rotation possible.");
 			}
 		} else {
-			$i = new weldMaps2PNG(implode("___",$array_urls), $this->filename, false);
+			$i = new weldMaps2PNG(implode("___",$array_urls), $this->filename, false,$opacity);
 		}
 		$this->pdf->objPdf->Image($this->filename, $this->conf->x_ul, $this->conf->y_ul, $width, $height,'png');
 		

Modified: trunk/mapbender/http/print/classes/mbTemplatePdf.php
===================================================================
--- trunk/mapbender/http/print/classes/mbTemplatePdf.php	2013-08-05 10:44:33 UTC (rev 8686)
+++ trunk/mapbender/http/print/classes/mbTemplatePdf.php	2013-08-16 14:07:43 UTC (rev 8687)
@@ -59,13 +59,21 @@
 	public function render() {
 		foreach ($this->confPdf->pages as $pageConf) {
 			/* apply the template to the pdf page */
-			$this->objPdf->addPage();
+			//$this->objPdf->addPage();
             $pagecount = $this->objPdf->setSourceFile(dirname(__FILE__)."/../".$pageConf->tpl);
             $tplidx = $this->objPdf->importPage($pageConf->useTplPage);
-            $controls = $this->confPdf->controls;
-            $this->objPdf->useTemplate($tplidx);
             
             foreach ($pageConf->elements as $pageElementId => $pageElementConf) {
+                $elementType = $pageElementConf->type;
+            }
+            if ($elementType == 'legend' && $this->printLegend == 'false'){
+                break;             
+            }else{
+                $this->objPdf->addPage();
+                $controls = $this->confPdf->controls;
+                $this->objPdf->useTemplate($tplidx);
+            }
+            foreach ($pageConf->elements as $pageElementId => $pageElementConf) {
 				
                                 switch ($pageElementConf->type) {
                                     	case "map":
@@ -87,9 +95,11 @@
 						$err = new mbImageDecorator($this, $pageElementId, $pageElementConf, $controls);
 						break;																									
 					case "legend":
-						$err = new mbLegendDecorator($this, $pageElementId, $pageElementConf, $controls);
+						if($this->printLegend == 'true'){
+							$err = new mbLegendDecorator($this, $pageElementId, $pageElementConf, $controls);
+						}
 						break;
-                                        case "permanentImage":
+					case "permanentImage":
 						$err = new mbPermanentImgDecorator($this, $pageElementId, $pageElementConf, $controls);
 						break;
 				}

Modified: trunk/mapbender/http/print/printFactory.php
===================================================================
--- trunk/mapbender/http/print/printFactory.php	2013-08-05 10:44:33 UTC (rev 8686)
+++ trunk/mapbender/http/print/printFactory.php	2013-08-16 14:07:43 UTC (rev 8687)
@@ -23,6 +23,18 @@
 $pdf->logRequests = $logRequests;
 $pdf->logType = $logType;
 
+if (isset($printLegend)){
+    $pdf->printLegend = $printLegend;
+}else{
+    $pdf->printLegend = 'true';
+}
+
+if (isset($legendColumns)){
+    $pdf->legendColumns = $legendColumns;
+}else{
+    $pdf->legendColumns = '1';
+}
+
 $pdf->render();
 try {
 	$pdf->save();

Modified: trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.3_to_2.7.4_pgsql_UTF-8.sql
===================================================================
--- trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.3_to_2.7.4_pgsql_UTF-8.sql	2013-08-05 10:44:33 UTC (rev 8686)
+++ trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.3_to_2.7.4_pgsql_UTF-8.sql	2013-08-16 14:07:43 UTC (rev 8687)
@@ -278,8 +278,27 @@
 
 ALTER TABLE mb_group ADD COLUMN mb_group_address_location geometry;
 
+-- printPDF: legend_url and opacity fields in e_content for printPDF template print
+UPDATE gui_element SET e_content = '<div id="printPDF_working_bg"></div><div id="printPDF_working"><img src="../img/indicator_wheel.gif" style="padding:10px 0 0 10px">Generating PDF</div><div id="printPDF_input"><form id="printPDF_form" action="../print/printFactory.php"><div id="printPDF_selector"></div><div class="print_option"><input type="hidden" id="map_url" name="map_url" value=""/><input type="hidden" id="legend_url" name="legend_url" value=""/><input type="hidden" id="opacity" name="opacity" value=""/> <input type="hidden" id="overview_url" name="overview_url" value=""/><input type="hidden" id="map_scale" name="map_scale" value=""/><input type="hidden" name="measured_x_values" /><input type="hidden" name="measured_y_values" /><br /></div><div class="print_option" id="printPDF_formsubmit"><input id="submit" type="submit" value="Print"><br /></div></form><div id="printPDF_result"></div></div>' 
+WHERE e_id = 'printPDF' and fkey_gui_id = 'template_print';
 
 
+-- printPDF: new element_var legendColumns for element printPDF
+INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value, context, var_type)
+SELECT gui_element.fkey_gui_id,
+'printPDF', 'legendColumns', '2', 'define number of columns on legendpage' ,'php_var' from gui_element
+WHERE
+gui_element.e_id = 'printPDF' AND
+gui_element.fkey_gui_id
+NOT IN (SELECT fkey_gui_id FROM gui_element_vars WHERE fkey_e_id = 'printPDF' AND var_name = 'legendColumns');
 
+-- printPDF: new element_var printLegend for element printPDF
+INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value, context, var_type)
+SELECT gui_element.fkey_gui_id, 'printPDF', 'printLegend', 'true', 'define whether the legend should be printed or not' ,'php_var' 
+from gui_element
+WHERE
+gui_element.e_id = 'printPDF' AND
+gui_element.fkey_gui_id
+NOT IN (SELECT fkey_gui_id FROM gui_element_vars WHERE fkey_e_id = 'printPDF' AND var_name = 'printLegend');
 
 



More information about the Mapbender_commits mailing list