[Mapbender-commits] r8152 - in trunk/mapbender/http: extensions/fpdf javascripts plugins print/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Sep 16 07:18:40 EDT 2011


Author: verenadiewald
Date: 2011-09-16 04:18:40 -0700 (Fri, 16 Sep 2011)
New Revision: 8152

Added:
   trunk/mapbender/http/print/classes/mbPermanentImgDecorator.php
Modified:
   trunk/mapbender/http/extensions/fpdf/mb_fpdi.php
   trunk/mapbender/http/javascripts/geometry.js
   trunk/mapbender/http/plugins/mb_print.php
   trunk/mapbender/http/print/classes/mbTemplatePdf.php
Log:
http://trac.osgeo.org/mapbender/ticket/825

Modified: trunk/mapbender/http/extensions/fpdf/mb_fpdi.php
===================================================================
--- trunk/mapbender/http/extensions/fpdf/mb_fpdi.php	2011-09-16 10:54:55 UTC (rev 8151)
+++ trunk/mapbender/http/extensions/fpdf/mb_fpdi.php	2011-09-16 11:18:40 UTC (rev 8152)
@@ -63,15 +63,15 @@
 	    else
 	        $info=$this->images[$file];
 	    //Automatic width and height calculation if needed
-	    if($w==0 && $h==0)
+	    if($w===0 && $h===0)
 	    {
 	        //Put image at 72 dpi
 	        $w=$info['w']/$this->k;
 	        $h=$info['h']/$this->k;
 	    }
-	    if($w==0)
+	    if($w===0)
 	        $w=$h*$info['w']/$info['h'];
-	    if($h==0)
+	    if($h===0)
 	        $h=$w*$info['h']/$info['w'];
 	        
 	    $x_rot = $x;
@@ -168,7 +168,7 @@
 	    imagedestroy($plain_img);
 	    
 	    //first embed mask image (w, h, x, will be ignored)
-	    $maskImg = $this->Image($tmp_alpha, 0,0,0,0, 'PNG', '', true);
+	    $maskImg = $this->Image($tmp_alpha, 0,0,0,-$h*10, 'PNG', '', true);
 	    
 	    //embed image, masked with previously embedded mask
 	    $this->Image($tmp_plain,$x,$y,$w,$h,'PNG',$link, false, $maskImg);

Modified: trunk/mapbender/http/javascripts/geometry.js
===================================================================
--- trunk/mapbender/http/javascripts/geometry.js	2011-09-16 10:54:55 UTC (rev 8151)
+++ trunk/mapbender/http/javascripts/geometry.js	2011-09-16 11:18:40 UTC (rev 8152)
@@ -2031,7 +2031,7 @@
 				node = img.node;
 			}
 			else {
-				//append tmp img to body to get img width and height for IE
+                                //append tmp img to body to get img width and height for IE
                                 var $tmpImg = $("body").append('<img style="visibility:hidden;" id="tmpImg" src="'+url+'" />');
                                 var $img = $('<img src="'+url+'" />');
                                 var width = $("#tmpImg").attr('width')||19;

Modified: trunk/mapbender/http/plugins/mb_print.php
===================================================================
--- trunk/mapbender/http/plugins/mb_print.php	2011-09-16 10:54:55 UTC (rev 8151)
+++ trunk/mapbender/http/plugins/mb_print.php	2011-09-16 11:18:40 UTC (rev 8152)
@@ -145,14 +145,13 @@
 		var $scaleInput = $("#scale");
 
 		if (printBox !== null) {
-			printBox.destroy();
-			printBox = null;
+                	destroyPrintBox();
 			jqForm[0].scale.value = "";
 			jqForm[0].coordinates.value = "";
 			jqForm[0].angle.value = "";
 		}
 		else {
-			printBox = new Mapbender.PrintBox({
+                	printBox = new Mapbender.PrintBox({
 				target : myTarget,
 				printWidth : getPDFMapSize("width")/10,
 				printHeight : getPDFMapSize("height")/10,
@@ -212,6 +211,7 @@
 	var destroyPrintBox = function () {
 		if (printBox) {
 			printBox.destroy();
+                        printBox = null;
 		}
 	};
 
@@ -228,6 +228,11 @@
 		/* than we need the translation of the print button */
 		$("#submit").val("<?php echo htmlentities(_mb("print"), ENT_QUOTES, "UTF-8");?>");
 
+                //show printBox for first entry in printTemplate selectbox
+                $("."+myId+"-dialog").bind("dialogopen", function () {
+                    printObj.createPrintBox();
+                });
+
                 //destroy printBox if printDialog is closed
                 $("."+myId+"-dialog").bind("dialogclose", function () {
                     destroyPrintBox();
@@ -240,7 +245,7 @@
 	 * GETs the config, build corresponding form, remove an existing printBox
 	 */
 	this.loadConfig = function (configFilename, callback) {
-		// the dataType to $.get is given explicitely, because there were instances of Mapbender that were returning
+        	// the dataType to $.get is given explicitely, because there were instances of Mapbender that were returning
 		// either json or a string, which trips up $.parseJSON which was being used in the callback
 		$.get(mbPrintConfigPath + configFilename, function(json, status){
 		    actualConfig = json;
@@ -248,10 +253,11 @@
 		    hookForm();
 			if (typeof callback === "function") {
 				printBox = null;
-				callback();
-			}
+                                callback();
+                        }
 		},"json");
 		destroyPrintBox();
+
 	};
 
 	/**
@@ -465,7 +471,34 @@
 			updateFormField(formData, "measured_y_values", tmp_y);
 		}
 
+                //write the permanent highlight image, if defined
 
+                var markers = [];
+                var pixelpos= null;
+                var realpos= [null,null];
+                var feature = null;
+
+                if(typeof GlobalPrintableGeometries != "undefined"){
+
+                    for(var idx = 0; idx < GlobalPrintableGeometries.count(); idx++ ) {
+                        feature = GlobalPrintableGeometries.get(idx);
+                        realpos = feature.get(0).get(0);
+                        path =  feature.e.getElementValueByName("Mapbender:icon");
+                        // The offsets are set to 40, meaning that images will need to be 80 x 80 with the tip of the marker- pixel being in the middle
+                        markers.push({
+                            position: [realpos.x,realpos.y],
+                            path: path,
+                            width: 40 * 2,
+                            height: 40 * 2,
+                            offset_x: 40,
+                            offset_y: 40,
+                        });
+                    }
+                    var permanentImage = JSON.stringify(markers);
+                    updateFormField(formData, "mypermanentImage", permanentImage);
+
+                }
+
 		if (f.map_url.value!="") {
 			//return true;
 		} else {
@@ -604,9 +637,10 @@
 		if (str) {
 			$("#printPDF_selector").append(str).find("#printPDF_template").change(function () {
 				printObj.loadConfig(mbPrintConfigFilenames[this.selectedIndex], function () {
-					printObj.createPrintBox()
+				    printObj.createPrintBox()
 				});
 			});
+
 			$("#printPDF_handle").click(function () {
 				printObj.createPrintBox();
 			});

Added: trunk/mapbender/http/print/classes/mbPermanentImgDecorator.php
===================================================================
--- trunk/mapbender/http/print/classes/mbPermanentImgDecorator.php	                        (rev 0)
+++ trunk/mapbender/http/print/classes/mbPermanentImgDecorator.php	2011-09-16 11:18:40 UTC (rev 8152)
@@ -0,0 +1,132 @@
+<?php
+class mbPermanentImgDecorator extends mbTemplatePdfDecorator {
+
+	protected $pageElementType = "permanentImage";
+	protected $elementId;
+	
+	public function __construct($pdfObj, $elementId, $mapConf, $controls) {
+		parent::__construct($pdfObj, $mapConf, $controls);
+		$this->elementId = $elementId;
+		$this->override();		
+		$this->decorate();
+	}
+	
+	public function override() {}
+	
+	public function decorate() {
+		global $mapOffset_left, $mapOffset_bottom, $map_height, $map_width, $coord;
+		global $yAxisOrientation;
+		$yAxisOrientation = 1;
+        $coord = mb_split(",",$this->pdf->getMapExtent());
+		$mapInfo = $this->pdf->getMapInfo();
+        $mapOffset_left = $mapInfo["x_ul"];
+		$mapOffset_bottom = $mapInfo["y_ul"];
+		$map_height = $mapInfo["height"];
+		$map_width = $mapInfo["width"];
+
+		
+		if (isset($_REQUEST["mypermanentImage"]) && $_REQUEST["mypermanentImage"] != "") {
+			$permanentImage = $_REQUEST["mypermanentImage"];
+		}
+		else {
+			return "No mypermanentImage values found.";
+		}
+
+        $markers = json_decode($permanentImage);
+
+        //only works if dpi is set to 72
+        $_REQUEST['dpi'] = 72;
+
+        foreach( $markers as $marker){
+
+
+            // left edge of the map on pdf 
+            $pdf_map_x1 = $mapInfo["x_ul"]; // unit: mm
+
+            // width of the map on the pdf
+            $pdf_map_dx =$mapInfo["width"]; //unit mm
+            
+
+            // left edge of the map on the map
+            $map_x1 = $coord[0]; // unit: coord
+            // right edge of the map on the map
+            $map_x2 = $coord[2]; // unit: coord
+            
+            // width of map in on map
+            $map_dx = $map_x2 - $map_x1; //unit: coord
+            
+
+
+            // left edge of the image on map
+            $img_x1 = $marker->position[0]; //unit: coord
+            
+            // the distance between the left edge of the map and the image on the map
+            $img_off_x =  $img_x1 - $map_x1; //unit: coord 
+
+
+            // add the marker offset to the left 
+            $pdf_marker_off_x = ($marker->offset_x * 25.4)/$_REQUEST['dpi']; //unit: mm
+            
+            // left edge of the image on the pdf
+            $pdf_img_off_x = ($pdf_map_x1 +  $img_off_x * ($pdf_map_dx/$map_dx)) - $pdf_marker_off_x ;  //unit: mm
+
+            // width of the image on the pdf
+            $pdf_img_dx = ($marker->width * 25.4)/$_REQUEST['dpi']; //unit: mm
+            
+
+            // top edge of the map on pdf 
+            $pdf_map_y1 = $mapInfo["y_ul"]; // unit: mm
+
+            // height of the map on the pdf
+            $pdf_map_dy =$mapInfo["height"]; //unit mm
+            
+
+            // top edge of the map on the map
+            $map_y1 = $coord[1]; // unit: coord
+            // bottom edge of the map on the map
+            $map_y2 = $coord[3]; // unit: coord
+            
+            // height of map in on map
+            $map_dy = $map_y2 - $map_y1; //unit: coord
+            
+
+            // top edge of the image on map
+            $img_y1 = $marker->position[1]; //unit: coord
+            
+            // the distance between the top edge of the map and the image on the map
+            $img_off_y =  $img_y1 - $map_y1; //unit: coord 
+
+
+            // add the marker offset to the top 
+            $pdf_marker_off_y = ($marker->offset_y * 25.4)/$_REQUEST['dpi']; //unit: mm
+            
+            // top edge of the image on the pdf
+            $pdf_img_off_y = $pdf_map_dy - ($pdf_map_y1 +  $img_off_y * ($pdf_map_dy/$map_dy)) + $pdf_marker_off_y;  //unit: mm
+
+            // width of the image on the pdf
+            $pdf_img_dy = ($marker->width * 25.4)/$_REQUEST['dpi']; //unit: mm
+
+            
+            $left = $pdf_img_off_x;
+            $top = $pdf_img_off_y;
+            $width = $pdf_img_dx;
+            $height = $pdf_img_dy;
+            $path = dirname(__FILE__)."/../../frames/".$marker->path;
+
+            $e = new mb_notice("mbPermanentImgDecorator: img left: ".$left);
+            $e = new mb_notice("mbPermanentImgDecorator: img top: ".$top);
+            $e = new mb_notice("mbPermanentImgDecorator: img width: ".$width);
+            $e = new mb_notice("mbPermanentImgDecorator: img height: ".$height);
+            $e = new mb_notice("mbPermanentImgDecorator: img path: ".$path);
+
+            $this->pdf->objPdf->Image($path, $left, $top, $width, $height, 'png');
+
+
+        }
+		
+    }
+	
+
+}
+
+?>

Modified: trunk/mapbender/http/print/classes/mbTemplatePdf.php
===================================================================
--- trunk/mapbender/http/print/classes/mbTemplatePdf.php	2011-09-16 10:54:55 UTC (rev 8151)
+++ trunk/mapbender/http/print/classes/mbTemplatePdf.php	2011-09-16 11:18:40 UTC (rev 8152)
@@ -66,8 +66,9 @@
             $this->objPdf->useTemplate($tplidx);
             
             foreach ($pageConf->elements as $pageElementId => $pageElementConf) {
-				switch ($pageElementConf->type) {
-					case "map":
+				
+                                switch ($pageElementConf->type) {
+                                    	case "map":
 						$err = new mbMapDecorator($this, $pageElementId, $pageElementConf, $controls);
 						break;
 					case "overview":
@@ -87,7 +88,10 @@
 						break;																									
 					case "legend":
 						$err = new mbLegendDecorator($this, $pageElementId, $pageElementConf, $controls);
-						break;																									
+						break;
+                                        case "permanentImage":
+						$err = new mbPermanentImgDecorator($this, $pageElementId, $pageElementConf, $controls);
+						break;
 				}
             }
             



More information about the Mapbender_commits mailing list