[Mapbender-commits] r8713 - in branches/2.7: 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
Mon Oct 7 04:47:20 PDT 2013


Author: verenadiewald
Date: 2013-10-07 04:47:20 -0700 (Mon, 07 Oct 2013)
New Revision: 8713

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

Modified: branches/2.7/http/classes/class_weldMaps2PNG.php
===================================================================
--- branches/2.7/http/classes/class_weldMaps2PNG.php	2013-10-04 10:28:33 UTC (rev 8712)
+++ branches/2.7/http/classes/class_weldMaps2PNG.php	2013-10-07 11:47:20 UTC (rev 8713)
@@ -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: branches/2.7/http/classes/class_weldMaps2PNG_rotate.php
===================================================================
--- branches/2.7/http/classes/class_weldMaps2PNG_rotate.php	2013-10-04 10:28:33 UTC (rev 8712)
+++ branches/2.7/http/classes/class_weldMaps2PNG_rotate.php	2013-10-07 11:47:20 UTC (rev 8713)
@@ -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: branches/2.7/http/plugins/mb_print.php
===================================================================
--- branches/2.7/http/plugins/mb_print.php	2013-10-04 10:28:33 UTC (rev 8712)
+++ branches/2.7/http/plugins/mb_print.php	2013-10-07 11:47:20 UTC (rev 8713)
@@ -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: branches/2.7/http/print/classes/mbLegendDecorator.php
===================================================================
--- branches/2.7/http/print/classes/mbLegendDecorator.php	2013-10-04 10:28:33 UTC (rev 8712)
+++ branches/2.7/http/print/classes/mbLegendDecorator.php	2013-10-07 11:47:20 UTC (rev 8713)
@@ -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"]);
@@ -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: branches/2.7/http/print/classes/mbMapDecorator.php
===================================================================
--- branches/2.7/http/print/classes/mbMapDecorator.php	2013-10-04 10:28:33 UTC (rev 8712)
+++ branches/2.7/http/print/classes/mbMapDecorator.php	2013-10-07 11:47:20 UTC (rev 8713)
@@ -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
@@ -68,6 +69,9 @@
 			}
 		}
 		$array_urls = $newArray_urls;
+		//TODO: Exchange owsproxy urls with real urls cause we don't want owsproxy to allow grabbing sessions!
+		//delete urls from list, for which user don't have permission!
+		//get auth information to call authenticated services
 		$e = new mb_notice("print/classes/mbMapDecorator.php: array_urls[0]: ".$array_urls[0]);
 		$width = $this->conf->width;
 		$height = $this->conf->height;
@@ -95,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: branches/2.7/http/print/classes/mbTemplatePdf.php
===================================================================
--- branches/2.7/http/print/classes/mbTemplatePdf.php	2013-10-04 10:28:33 UTC (rev 8712)
+++ branches/2.7/http/print/classes/mbTemplatePdf.php	2013-10-07 11:47:20 UTC (rev 8713)
@@ -59,12 +59,20 @@
 	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);
+            
+            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) {
@@ -87,7 +95,9 @@
 						$err = new mbImageDecorator($this, $pageElementId, $pageElementConf, $controls);
 						break;																									
 					case "legend":
+						if($this->printLegend == 'true'){
 						$err = new mbLegendDecorator($this, $pageElementId, $pageElementConf, $controls);
+						}
 						break;
                                         case "permanentImage":
 						$err = new mbPermanentImgDecorator($this, $pageElementId, $pageElementConf, $controls);

Modified: branches/2.7/http/print/printFactory.php
===================================================================
--- branches/2.7/http/print/printFactory.php	2013-10-04 10:28:33 UTC (rev 8712)
+++ branches/2.7/http/print/printFactory.php	2013-10-07 11:47:20 UTC (rev 8713)
@@ -23,13 +23,25 @@
 $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->render();
 	$pdf->save();
 }
 catch (Exception $e) {
-	new mb_exception($e->getMessage());
-	die($e->getMessage());
+	new mb_exception($e->message);
+	die;
 }
 
 print $pdf->returnAbsoluteUrl();

Modified: branches/2.7/resources/db/pgsql/UTF-8/update/update_2.7.3_to_2.7.4_pgsql_UTF-8.sql
===================================================================
--- branches/2.7/resources/db/pgsql/UTF-8/update/update_2.7.3_to_2.7.4_pgsql_UTF-8.sql	2013-10-04 10:28:33 UTC (rev 8712)
+++ branches/2.7/resources/db/pgsql/UTF-8/update/update_2.7.3_to_2.7.4_pgsql_UTF-8.sql	2013-10-07 11:47:20 UTC (rev 8713)
@@ -8,3 +8,21 @@
 -- add new element vars for resizemapSize to gui2
 INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value, context, var_type) VALUES('gui2', 'resizeMapsize', 'max_height', '700', 'define a max mapframe width (units pixel) f.e. 700 or false' ,'var');
 INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value, context, var_type) VALUES('gui2', 'resizeMapsize', 'max_width', '700', 'define a max mapframe width (units pixel) f.e. 700 or false' ,'var');
+
+-- 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