[Mapbender-commits] r9318 - in trunk/mapbender/http: classes css php plugins print/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Nov 25 07:49:57 PST 2015


Author: armin11
Date: 2015-11-25 07:49:57 -0800 (Wed, 25 Nov 2015)
New Revision: 9318

Added:
   trunk/mapbender/http/print/classes/mbSvgDecorator.php
Modified:
   trunk/mapbender/http/classes/class_iso19139.php
   trunk/mapbender/http/classes/class_weldMaps2PNG_rotate.php
   trunk/mapbender/http/css/digitize_new.css
   trunk/mapbender/http/php/mod_GetPublishedData.php
   trunk/mapbender/http/plugins/mb_digitize_widget.php
   trunk/mapbender/http/plugins/mb_print.php
   trunk/mapbender/http/print/classes/mbTemplatePdf.php
   trunk/mapbender/http/print/classes/mbTemplatePdfDecorator.php
Log:
New possibility to print digitized objects in pdf - prototype - some things have to be done

Modified: trunk/mapbender/http/classes/class_iso19139.php
===================================================================
--- trunk/mapbender/http/classes/class_iso19139.php	2015-11-25 14:25:56 UTC (rev 9317)
+++ trunk/mapbender/http/classes/class_iso19139.php	2015-11-25 15:49:57 UTC (rev 9318)
@@ -59,6 +59,11 @@
 	var $updateFrequency;
 	var $dataFormat;
 	var $inspireCharset;
+	var $licenseSourceNote;
+	var $licenseJson;
+	var $termsOfUseRef;
+	var $accessConstraints;
+	var $fees;
 	//Following two attributes are needed for generating the inspire monitoring information. They are normally not part of the iso19139!
 	var $inspireWholeArea;
 	var $inspireActualCoverage;
@@ -114,6 +119,11 @@
 		$this->linkAlreadyInDB = false;
 		$this->fileIdentifierAlreadyInDB = false;
 		$this->transferSize = null;
+		$this->licenseSourceNote = null;
+		$this->termsOfUseRef = null;
+		$this->accessConstraints = null;
+		$this->fees = null;
+		$this->licenseJson = null;
 	}
 
 	public function removeGetRecordTag ($xml) {
@@ -379,7 +389,40 @@
 			//inspire_top_consistence
 			//responsible_party
 			//fees
-			//"constraints"	
+			//"constraints"
+			//extract standardized licenses from constraints (see http://www.geoportal.de/SharedDocs/Downloads/DE/GDI-DE/Architektur_GDI_DE-Konventionen_%20Metadaten.pdf?__blob=publicationFile)
+			$restrictionCodeAttributeValue = $iso19139Xml->xpath('//gmd:MD_Metadata/gmd:identificationInfo//gmd:resourceConstraints/gmd:MD_LegalConstraints/gmd:useConstraints/gmd:MD_RestrictionCode/@codeListValue');
+			$first = $restrictionCodeAttributeValue[0];
+			$second = $restrictionCodeAttributeValue[1];
+			if ($first == 'license' && $second == 'otherRestrictions') {
+				//search for json
+				$otherConstraints = $iso19139Xml->xpath('//gmd:MD_Metadata/gmd:identificationInfo//gmd:resourceConstraints/gmd:MD_LegalConstraints/gmd:otherConstraints/gco:CharacterString');
+				if (json_decode(stripslashes($otherConstraints[0])) === NULL) {
+					//no json found - use string as constraints text and look in second entry
+					$this->fees = $otherConstraints[0];
+					if (json_decode(stripslashes($otherConstraints[1])) === NULL) {
+						//no json found - end parsing
+					} else {
+						//parse json
+						$standardizedLicense = json_decode(stripslashes($otherConstraints[1]));
+						//Look for source
+						$this->licenseSourceNote = $standardizedLicense->quelle;
+						$this->licenseJson = stripslashes($otherConstraints[1]);
+						//$e = new mb_exception("class_iso19139.php: licenseSourceNote: ".$this->licenseSourceNote);
+					}
+				} else {
+					//parse json
+					$standardizedLicense = json_decode(stripslashes($otherConstraints[0]));
+					//Look for source
+					$this->licenseSourceNote = $standardizedLicense->quelle;
+					$this->licenseJson = stripslashes($otherConstraints[1]);
+					//search in the second entry for a freetxt object
+					if ($otherConstraints[1] != ''){
+						$this->fees = $otherConstraints[1];
+					}
+				}
+			}
+			$e = new mb_notice("class_iso19139.php: licenseSourceNote: ".$this->licenseSourceNote." - fees: ".$this->fees);		
 			//fill database with elements:
 			return $this;
 		} else {
@@ -1485,6 +1528,18 @@
 				}
 			}
 		}
+		//handle licenses as relations
+		//delete relations from database
+		//recreate relation to license
+		//relation is set via json id
+		if ($this->licenseJson != null) {
+			
+		}
+
+		if ($this->licenseJson != null) {
+
+		}
+		//relation is set via metadata editor
 	}
 
 	public function deleteCategoriesFromCoupledResource($metadataId,$resourceType,$resourceId) {
@@ -1597,7 +1652,7 @@
 		//insert an instance for iso19139 into mapbenders database
 		$e = new mb_exception("class_iso19139.php: insert metadata with title: ".$this->title);
 		$sql = <<<SQL
-INSERT INTO mb_metadata (lastchanged, link, origin, md_format, data, linktype, uuid, title, createdate, changedate, abstract, searchtext, type, tmp_reference_1, tmp_reference_2, export2csw, datasetid, datasetid_codespace, randomid, fkey_mb_user_id, harvestresult, harvestexception, lineage, inspire_top_consistence, spatial_res_type, spatial_res_value, update_frequency, format, inspire_charset, ref_system, the_geom, datalinks, inspire_whole_area, inspire_actual_coverage, inspire_download, bounding_geom, transfer_size)  VALUES(now(), $1, $18, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36)
+INSERT INTO mb_metadata (lastchanged, link, origin, md_format, data, linktype, uuid, title, createdate, changedate, abstract, searchtext, type, tmp_reference_1, tmp_reference_2, export2csw, datasetid, datasetid_codespace, randomid, fkey_mb_user_id, harvestresult, harvestexception, lineage, inspire_top_consistence, spatial_res_type, spatial_res_value, update_frequency, format, inspire_charset, ref_system, the_geom, datalinks, inspire_whole_area, inspire_actual_coverage, inspire_download, bounding_geom, transfer_size, fees, md_license_source_note)  VALUES(now(), $1, $18, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38)
 SQL;
 		$v = array(
 			$this->href,
@@ -1635,13 +1690,15 @@
 			$this->inspireActualCoverage,
 			$this->inspireDownload,
 			$this->createWktPolygonFromPointArray($this->polygonalExtentExterior),
-			$this->transferSize
+			$this->transferSize,
+			$this->fees,
+			$this->licenseSourceNote
 		);
-			$e = new mb_exception($this->tmpExtentBegin);
-			$e = new mb_exception($this->tmpExtentEnd);
-			$e = new mb_exception($this->createDate);
-			$e = new mb_exception($this->changeDate);
-			$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s','s','POLYGON','s','s','s','i','POLYGON','d');
+			//$e = new mb_exception($this->tmpExtentBegin);
+			//$e = new mb_exception($this->tmpExtentEnd);
+			//$e = new mb_exception($this->createDate);
+			//$e = new mb_exception($this->changeDate);
+			$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s','s','POLYGON','s','s','s','i','POLYGON','d','s','s');
 			$res = db_prep_query($sql,$v,$t);
 			return $res;
 	}
@@ -1684,7 +1741,7 @@
 		$sql .= "linktype = $4, uuid = $5, title = $6, createdate = $7, changedate = $8, lastchanged = now(), ";
 		$sql .= "abstract = $9, searchtext = $10, type = $11, tmp_reference_1 = $12, tmp_reference_2 = $13, export2csw = $14, datasetid = $15, ";
 		$sql .= "datasetid_codespace = $16, randomid = $17, harvestresult = $20, harvestexception = $21, lineage = $22, inspire_top_consistence = $23, ";
-		$sql .= "spatial_res_type = $24, spatial_res_value = $25, update_frequency = $26, format = $27, inspire_charset = $28, ref_system = $29, the_geom = $30, datalinks = $31, inspire_whole_area = $32, inspire_actual_coverage = $33, inspire_download = $34, bounding_geom = $35, transfer_size = $36 WHERE metadata_id = $19";
+		$sql .= "spatial_res_type = $24, spatial_res_value = $25, update_frequency = $26, format = $27, inspire_charset = $28, ref_system = $29, the_geom = $30, datalinks = $31, inspire_whole_area = $32, inspire_actual_coverage = $33, inspire_download = $34, bounding_geom = $35, transfer_size = $36, fees = $37, md_license_source_note = $38 WHERE metadata_id = $19";
 		//$e= new mb_exception("class_iso19139.php: downloadLinks json".$this->jsonEncodeDownloadLinks($this->downloadLinks));
 		//$e= new mb_exception("class_iso19139.php: downloadLinks[0]".$this->downloadLinks[0]);
 		$v = array(
@@ -1724,9 +1781,11 @@
 			$this->inspireActualCoverage,
 			$this->inspireDownload,
 			$this->createWktPolygonFromPointArray($this->polygonalExtentExterior),
-			$this->transferSize
+			$this->transferSize,
+			$this->fees,
+			$this->licenseSourceNote
 		);
-		$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s','s','POLYGON','s','s','s','i','POLYGON','d');
+		$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s','s','POLYGON','s','s','s','i','POLYGON','d','s','s');
 		$res = db_prep_query($sql,$v,$t);
 		return $res;
 	}

Modified: trunk/mapbender/http/classes/class_weldMaps2PNG_rotate.php
===================================================================
--- trunk/mapbender/http/classes/class_weldMaps2PNG_rotate.php	2015-11-25 14:25:56 UTC (rev 9317)
+++ trunk/mapbender/http/classes/class_weldMaps2PNG_rotate.php	2015-11-25 15:49:57 UTC (rev 9318)
@@ -38,21 +38,21 @@
         $obj1 = new stripRequest($url[0]);
         $width = $obj1->get("width");
         $height = $obj1->get("height");
-        	
+
         //calculate rotated dimensions
         $neededWidth = round(abs(sin(deg2rad($angle))*$height)+abs(cos(deg2rad($angle))*$width));
         $neededHeight = round(abs(sin(deg2rad($angle))*$width)+abs(cos(deg2rad($angle))*$height));
-    
+
         //modify requests
         for($i=0; $i<count($url); $i++){
             $obj = new stripRequest($url[$i]);
             $obj->set("width", $neededWidth);
             $obj->set("height", $neededHeight);
-                
+
             $map_extent = $obj->get("BBOX");
             $coord = explode(",",$map_extent);
             $coord = $this->enlargeExtent($coord, $width, $height, $neededWidth, $neededHeight);
-            
+
             $obj->set("BBOX", implode(",", $coord));
             $url[$i] = $obj->url;
         }
@@ -60,26 +60,24 @@
         //get image
         $urls = implode("___", $url);
         $this->weldMaps2PNG($urls, $filename, $encode, $opacities);
-        
 
+
         //rotate image
         $imagick = new Imagick();
         $imagick->readImage($filename);
-        $imagick->rotateImage(new ImagickPixel(), $angle);
-        
-        //get the new dimensions
-        $imgWidth = $imagick->getImageWidth();
-        $imgHeight = $imagick->getImageHeight();
-            
-        //crop empty areas
-        $imagick->cropImage($width, $height, ($imgWidth-$width)/2, ($imgHeight-$height)/2);
-        
+        $imagick->rotateImage(new ImagickPixel('transparent'), $angle);
+//        //get the new dimensions
+//        $imgWidth = $imagick->getImageWidth();
+//        $imgHeight = $imagick->getImageHeight();
+//        //crop empty areas
+//        $imagick->cropImage($width, $height, ($imgWidth-$width)/2, ($imgHeight-$height)/2); orig imagick bug?
+        $imagick->cropImage($width, $height, ($neededWidth-$width)/2, ($neededHeight-$height)/2);
         //write modified image
         $imagick->writeImage($filename);
         $image = imagecreatefrompng($filename);
         imagepng($image,$filename);
     }
- 
+
     function enlargeExtent($coordArray, $oldWidth, $oldHeight, $newWidth, $newHeight){
          $extentx = ($coordArray[2] - $coordArray[0]);
          $extenty = ($coordArray[3] - $coordArray[1]);
@@ -89,7 +87,7 @@
          $coordArray[3]+=($extenty/$oldHeight)*($newHeight-$oldHeight)/2;
         return $coordArray;
     }
-    
+
 }
 
 ?>

Modified: trunk/mapbender/http/css/digitize_new.css
===================================================================
--- trunk/mapbender/http/css/digitize_new.css	2015-11-25 14:25:56 UTC (rev 9317)
+++ trunk/mapbender/http/css/digitize_new.css	2015-11-25 15:49:57 UTC (rev 9318)
@@ -16,6 +16,10 @@
     background-image: url('../img/pencil.png');
 }
 
+.digitize-copy {
+    background-image: url('../img/gnome/edit-copy.png');
+}
+
 .digitize-cursor {
     background-image: url('../img/osgeo_graphics/geosilk/cursor.png');
 }

Modified: trunk/mapbender/http/php/mod_GetPublishedData.php
===================================================================
--- trunk/mapbender/http/php/mod_GetPublishedData.php	2015-11-25 14:25:56 UTC (rev 9317)
+++ trunk/mapbender/http/php/mod_GetPublishedData.php	2015-11-25 15:49:57 UTC (rev 9318)
@@ -5,48 +5,68 @@
  * @author    Raphael.Syed <raphael.syed at WhereGroup.com> http://WhereGroup.com
  */
 
-
 //import classes
+require_once(dirname(__FILE__) . "/../../core/globalSettings.php");
 require_once(dirname(__FILE__) . "/../classes/class_wmc.php");
 require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
+require_once(dirname(__FILE__)."/../classes/class_Uuid.php");
 
-
 /**
  * publish the choosed data
  */
 
-// get data from session and request
+//get data from session and request
 $user_id = Mapbender::session()->get("mb_user_id");
-$wmc_serial_id = $_GET["wmc_id"];
-$outputFormat = $_GET['outputFormat'];
 
+//validate outputFormat
+if (isset($_REQUEST["outputFormat"]) & $_REQUEST["outputFormat"] != "") {
+	//validate to de, en, fr
+	$testMatch = $_REQUEST["outputFormat"];	
+ 	if (!($testMatch == 'kml' or $testMatch == 'gpx' or $testMatch == 'geojson')){ 
+		echo 'Parameter <b>outputFormat</b> is not valid (kml, gpx, geojson).<br/>'; 
+		die(); 		
+ 	}
+	$outputFormat = $testMatch;
+	$testMatch = NULL;
+}
+//validate wmc_id
+if (isset($_REQUEST["wmc_id"]) & $_REQUEST["wmc_id"] != "") {
+        $testMatch = $_REQUEST["wmc_id"];
+        $pattern = '/^[0-9]*$/';  
+        if (!preg_match($pattern,$testMatch)){
+                echo 'Parameter <b>wmc_id</b> is not valid (integer).<br/>';
+                die();
+        }
+        $wmc_serial_id = $testMatch;
+        $testMatch = NULL;
+}
+$e = new mb_exception("php/mod_GetPublishedData.php: outputFormat: ".$outputFormat);
 //create a WMC object from a WMC in the database
 $xml = wmc::getDocument($wmc_serial_id);
 $myWmc = new wmc();
 $myWmc->createFromXml($xml);
 
-#  Decode from JSON to array
+//  Decode from JSON to array
 foreach ($myWmc->generalExtensionArray as $key => &$value) {
     $value = json_decode($value, true);
 }
 // create and numerically indexed array
 $kmls = array_values($myWmc->generalExtensionArray["KMLS"]);
 
+$fileUuid = new Uuid();
 //create the fileName
+$file = "myDataCollection-".$fileUuid.".".$outputFormat;
 
-$file = "myDataCollection.".$outputFormat;
-
 if (isset($kmls[0]["data"]['@context'])) {
-    $file = rawurldecode($kmls[0]["data"]['@context']['title']).'.'.$outputFormat;
-
+    $file = rawurldecode($kmls[0]["data"]['@context']['title'])."-".$fileUuid.'.'.$outputFormat;
 }
 
 if (sizeof($kmls) > 1) {
-    # create a file for each featureCollection and push them in a zip
+    // create a file for each featureCollection and push them in a zip
 
     $zip = new ZipArchive;
-    $zipName = '../tmp/myDataCollection.zip';
-    $fileName = "myDataCollection.zip";
+    $zipName = TMPDIR.'/myDataCollection-'.$fileUuid.'.zip';
+    $fileName = "myDataCollection-'.$fileUuid.'.zip";
 
     if ($zip->open($zipName, ZIPARCHIVE::CREATE) === true) {
         // counting filenames
@@ -54,13 +74,11 @@
         // loop over every featureCollection
         foreach ($kmls as $key => $value) {
             $geoJson = $kmls[$fileCounter-1]["data"];
-            $dataFile = createFile($outputFormat, $geoJson);
+            $dataFile = createFile($outputFormat, $geoJson, $fileUuid);
             $zip->addFromString('myFeatureCollection_'.$fileCounter.'.'.$outputFormat, $dataFile);
             // increment the counter
             $fileCounter +=1;
-
         }
-
         $zip->close();
     }
     // set the headers to return a zip to the client
@@ -71,7 +89,7 @@
     readfile($zipName);
 
     //remove zip from harddisk
-    exec(escapeshellcmd('rm ../tmp/myDataCollection.zip'));
+    exec(escapeshellcmd('rm '.TMPDIR.'/myDataCollection-'.$fileUuid.'.zip'));
     die;
 
 } else {
@@ -82,12 +100,10 @@
     header("Content-Type: application/download");
     //parse the geojson from the array
     $geoJson = $kmls[0]["data"];
-    $dataFile = createFile($outputFormat, $geoJson);
+    $dataFile = createFile($outputFormat, $geoJson, $fileUuid);
     echo $dataFile;
-
 }
 
-
 /**
  * converts a kml-file into a gpx-file
  * @param  string $u the file location
@@ -296,10 +312,8 @@
         header("Content-Type: text/xml");
         return $dom_gpx->saveXML();
     }
-
 }
 
-
 /**
  * create a utcdate
  * @return utcdate objekt]
@@ -309,63 +323,59 @@
         return gmdate("Y-m-d\Th:i:s\Z");
 }
 
-function createFile($outputFormat, $geoJson)
+function createFile($outputFormat, $geoJson, $fileUuid)
 {
-
     // handle the different outputformat
     if ($outputFormat == 'geojson') {
         // create the json-file
-        $geoJsonFile = '../tmp/myDataCollection.geojson';
+        $geoJsonFile = TMPDIR.'/myDataCollection-'.$fileUuid.'.geojson';
         // put the contents to the created file
         file_put_contents($geoJsonFile, json_encode($geoJson));
         // create a string from the created file
-        $fileString = file_get_contents('../tmp/myDataCollection.geojson');
+        $fileString = file_get_contents(TMPDIR.'/myDataCollection-'.$fileUuid.'.geojson');
         // return the string
         return $fileString;
         die;
 
     } elseif ($outputFormat == 'gpx') {
         //convert geojson to kml
-
         //create the geojson-file temporary
-        $temp_geojson = '../tmp/myDataCollection.geojson';
+        $temp_geojson = TMPDIR.'/myDataCollection-'.$fileUuid.'.geojson';
         // write the file
         file_put_contents($temp_geojson, json_encode($geoJson));
         //transform the geojson to kml
-        $unique = '../tmp/myDataCollection';
+        $unique = TMPDIR.'/myDataCollection-'.$fileUuid;
         $fGeojson = $unique.".geojson";
         $fKml = $unique.".kml";
+	//TODO: Define this in mapbender.conf or other configuration file!
         $pathOgr = '/usr/bin/ogr2ogr';
         // execute ogr2ogr
         $exec = $pathOgr.' -f KML '.$fKml.' '.$fGeojson;
         exec(escapeshellcmd($exec));
         //enter location of KML file here
-        $kml = "../tmp/myDataCollection.kml";
+        $kml = TMPDIR."/myDataCollection-".$fileUuid.".kml";
         // create gpx from kml
         return kml_to_gpx($kml);
         die;
-
     } elseif ($outputFormat == 'kml') {
         //convert geojson to kml
-
         //create the geojson-file temporary
-        $temp_geojson = '../tmp/myDataCollection.geojson';
+        $temp_geojson = TMPDIR.'/myDataCollection-'.$fileUuid.'.geojson';
         // write the file
         file_put_contents($temp_geojson, json_encode($geoJson));
         //transform the file to kml
-        $unique = '../tmp/myDataCollection';
+        $unique = TMPDIR.'/myDataCollection-'.$fileUuid;
         $fGeojson = $unique.".geojson";
         $fKml = $unique.".kml";
+	//TODO: Define this in mapbender.conf or other configuration file!
         $pathOgr = '/usr/bin/ogr2ogr';
         //execute ogr2ogr to transfrom json to kml
         $exec = $pathOgr.' -f KML '.$fKml.' '.$fGeojson;
         exec(escapeshellcmd($exec));
         // create string from kml-file
-        $fileString = file_get_contents('../tmp/myDataCollection.kml');
+        $fileString = file_get_contents(TMPDIR.'/myDataCollection-'.$fileUuid.'.kml');
         //return the string
-
         return $fileString;
         die;
     }
-
 }

Modified: trunk/mapbender/http/plugins/mb_digitize_widget.php
===================================================================
--- trunk/mapbender/http/plugins/mb_digitize_widget.php	2015-11-25 14:25:56 UTC (rev 9317)
+++ trunk/mapbender/http/plugins/mb_digitize_widget.php	2015-11-25 15:49:57 UTC (rev 9318)
@@ -152,6 +152,7 @@
         '<li><div class="digitize-image digitize-pencil"></div><?php echo _mb("Edit");?></li>' +
         '<li><div class="digitize-image digitize-zoomto"></div><?php echo _mb("Zoom to");?></li>' +
         // '<li><div class="digitize-image digitize-add"></div><?php echo _mb("New");?></li>' +
+        '<li><div class="digitize-image digitize-copy"></div><?php echo _mb("Kopieren");?></li>' +
         '<li><div class="digitize-image digitize-export"></div><?php echo _mb("Export");?></li>' +
         '<li><div class="digitize-image digitize-remove"></div><?php echo _mb("Delete");?></li>' +
         '<li><div class="digitize-image digitize-style"></div><?php echo _mb("Styling");?></li>' +

Modified: trunk/mapbender/http/plugins/mb_print.php
===================================================================
--- trunk/mapbender/http/plugins/mb_print.php	2015-11-25 14:25:56 UTC (rev 9317)
+++ trunk/mapbender/http/plugins/mb_print.php	2015-11-25 15:49:57 UTC (rev 9318)
@@ -17,7 +17,7 @@
  * > e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, 
  * > e_mb_mod, e_target, e_requires, e_url) VALUES('<appId>','printPDF',
  * > 2,1,'pdf print','Print','div','','',1,1,2,2,5,'',
- * > '<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="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>',
+ * > '<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="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" /><input type="hidden" name="map_svg_kml" /><input type="hidden" name="svg_extent" /><input type="hidden" name="map_svg_measures" /><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>',
  * > 'div','../plugins/mb_print.php',
  * > '../../lib/printbox.js,../extensions/jquery-ui-1.7.2.custom/development-bundle/external/bgiframe/jquery.bgiframe.js,../extensions/jquery.form.min.js',
  * > 'mapframe1','','http://www.mapbender.org/index.php/Print');
@@ -647,6 +647,28 @@
                     updateFormField(formData, "mypermanentImage", permanentImage);
 
                 }
+                var $jqForm = $(jqForm);
+                if($jqForm.find('[name="svg_extent"]').length){
+                    var ext = $("#mapframe1:maps").mapbender().extent;
+                    updateFormField(formData, "svg_extent", ext.min.x + ',' + ext.min.y + ',' + ext.max.x + ',' + ext.max.y);
+                    if($jqForm.find('[name="map_svg_kml"]').length){
+                        var kml = $('#mapframe1').data('kml');
+                        updateFormField(formData, "map_svg_kml", "");
+                        if(kml._kmls && $('#kml-rendering-pane svg:first').length){
+                            for(var key in kml._kmls){ // object exists -> add svg
+                                updateFormField(formData, "map_svg_kml", '<?xml version="1.0" encoding="UTF-8"?>\n' + $($('#kml-rendering-pane').get(0)).html());
+                                break;
+                            }
+                        }
+                    }
+                    if($jqForm.find('[name="map_svg_measures"]').length){
+                        if($('#measure_canvas svg:first').length){
+                                updateFormField(formData, "map_svg_measures", '<?xml version="1.0" encoding="UTF-8"?>\n' + $($('#measure_canvas').get(0)).html());
+                        } else {
+                                updateFormField(formData, "map_svg_measures", '');
+                        }
+                    }
+                }
 		if (f.map_url.value!="" && typeof f.map_url.value != 'undefined' && f.map_url.value != false && f.map_url.value != 'false') {
 			//all fields are ok wait for pdf
 		} else {

Added: trunk/mapbender/http/print/classes/mbSvgDecorator.php
===================================================================
--- trunk/mapbender/http/print/classes/mbSvgDecorator.php	                        (rev 0)
+++ trunk/mapbender/http/print/classes/mbSvgDecorator.php	2015-11-25 15:49:57 UTC (rev 9318)
@@ -0,0 +1,118 @@
+<?php
+
+class mbSvgDecorator extends mbTemplatePdfDecorator
+{
+//    protected $pageElementType = "svg";
+//    protected $elementId;
+
+    protected $pageElementType            = "map";
+    protected $elementId;
+    protected $filename;
+    /* a decorator should declare which parameters could be overwritten through the request object */
+    protected $overrideMembersFromRequest = array("res_dpi", "angle");
+    protected $res_dpi;
+    protected $angle                      = 0;
+
+    public function __construct($pdfObj, $elementId, $mapConf, $controls, $svgParam)
+    {
+        parent::__construct($pdfObj, $mapConf, $controls);
+        $this->elementId = $elementId;
+        $this->filename  = TMPDIR . "/" . parent::generateOutputFileName($svgParam, "png");
+        $this->svgParam  = $svgParam;
+        $this->override();
+        $this->decorate();
+    }
+
+    public function override()
+    {
+
+    }
+
+    public function decorate()
+    {
+        require_once (dirname(__FILE__) . "/../print_functions.php");
+
+        global $mapOffset_left, $mapOffset_bottom, $map_height, $map_width, $coord;
+        global $yAxisOrientation;
+        $yAxisOrientation = 1;
+        $doc              = new \DOMDocument();
+        if (isset($_REQUEST[$this->svgParam]) && $_REQUEST[$this->svgParam] != "" && @$doc->loadXML($_REQUEST[$this->svgParam])) {
+            $e = new mb_notice("mbSvgDecorator: svg: " . $_REQUEST[$this->svgParam]);
+        } else {
+            return "No svg found.";
+        }
+        $xpath   = new \DOMXPath($doc);
+        $xpath->registerNamespace("xlink", "http://www.w3.org/1999/xlink");
+        $xpath->registerNamespace("svg", "http://www.w3.org/2000/svg");
+        $coord   = mb_split(",", $this->pdf->getMapExtent());
+        $mapInfo = $this->pdf->getMapInfo();
+        foreach ($mapInfo as $k => $v) {
+            $e = new mb_notice("mbSvgDecorator: mapInfo: " . $k . "=" . $v);
+        }
+        $mapOffset_left   = $mapInfo["x_ul"];
+        $mapOffset_bottom = $mapInfo["y_ul"];
+        $map_height       = $mapInfo["height"];
+        $map_width        = $mapInfo["width"];
+        $map_extent       = explode(',', $mapInfo["extent"]);
+
+        $oext          = explode(',', $_REQUEST["svg_extent"]);
+        $angle         = isset($_REQUEST['angle']) && $_REQUEST['angle'] != "" ? floatval($_REQUEST['angle']) : 0;
+        $svg_w         = intval(preg_replace('[^0-9]', '', $doc->documentElement->getAttribute("width")));
+        $svg_h         = intval(preg_replace('[^0-9]', '', $doc->documentElement->getAttribute("height")));
+        $res           = $this->pdf->objPdf->k * ($this->conf->res_dpi / 72);
+        $map_width_px  = intval(round($map_width * $res));
+        $map_height_px = intval(round($map_height * $res));
+
+        // calculate factors for x and y
+        $k_svg_x         = ($oext[2] - $oext[0]) / $svg_w;
+        $k_svg_y         = ($oext[3] - $oext[1]) / $svg_h;
+        // calculate offsets for x and y
+        $offset_svg_x_px = ($oext[0] - $map_extent[0]) / $k_svg_x;
+        $offset_svg_y_px = ($oext[3] - $map_extent[3]) / $k_svg_y;
+        $svg_bbox_w      = ($map_extent[2] - $map_extent[0]) / $k_svg_x;
+        $svg_bbox_h      = ($map_extent[3] - $map_extent[1]) / $k_svg_y;
+
+        $scale   = 1;
+        $padding = 2;
+        if ($svg_bbox_w > $svg_bbox_h) {
+            $scale = ($map_width_px - $padding) / $svg_bbox_w;
+        } else {
+            $scale = ($map_height_px - $padding) / $svg_bbox_h;
+        }
+        if ($angle != 0) {
+            $neededHeight = round(abs(sin(deg2rad($angle)) * $map_width_px) + abs(cos(deg2rad($angle)) * $map_width_px));
+            $neededWidth  = round(abs(sin(deg2rad($angle)) * $map_height_px) + abs(cos(deg2rad($angle)) * $map_height_px));
+            $x            = $offset_svg_x_px * $scale + ($neededWidth - $map_width_px) / 2;
+            $y            = (-$offset_svg_y_px * $scale) + ($neededHeight - $map_height_px) / 2;
+            $doc->documentElement->setAttribute("height", $neededHeight);
+            $doc->documentElement->setAttribute("width", $neededWidth);
+        } else {
+            $x = $offset_svg_x_px * $scale;
+            $y = -$offset_svg_y_px * $scale;
+            $doc->documentElement->setAttribute("height", $map_height_px);
+            $doc->documentElement->setAttribute("width", $map_width_px);
+        }
+        foreach ($xpath->query("//*[@d]", $doc->documentElement) as $elm) {
+            $elm->setAttribute('transform', "translate($x,$y) scale($scale,$scale)"); #rotate($angle, $rx0, $ry0)
+        }
+
+        foreach ($xpath->query("//*[@style]", $doc->documentElement) as $elm) {
+            $elm->removeAttribute('style');
+        }
+        $imagick = new \Imagick();
+        $imagick->setBackgroundColor(new \ImagickPixel('transparent'));
+        $imagick->readImageBlob($doc->saveXML());
+        $imagick->setImageFormat("png32");
+        if ($angle != 0) {
+            $imagick->rotateImage(new ImagickPixel('transparent'), $angle);
+//            $imgWidth = $imagick->getImageWidth();
+//            $imgHeight = $imagick->getImageHeight();
+//            $imagick->cropImage($map_width_px, $map_height_px, ($imgWidth-$map_width_px)/2, ($imgHeight-$map_height_px)/2); orig, imagick bug?
+            $imagick->cropImage($map_width_px, $map_height_px, ($neededWidth - $map_width_px) / 2,
+                ($neededHeight - $map_height_px) / 2);
+        }
+        file_put_contents($this->filename, $imagick->getImageBlob());
+        $this->pdf->objPdf->Image($this->filename, $mapOffset_left, $mapOffset_bottom, $map_width, $map_height, 'png');
+        $this->pdf->unlink($this->filename);
+    }
+}

Modified: trunk/mapbender/http/print/classes/mbTemplatePdf.php
===================================================================
--- trunk/mapbender/http/print/classes/mbTemplatePdf.php	2015-11-25 14:25:56 UTC (rev 9317)
+++ trunk/mapbender/http/print/classes/mbTemplatePdf.php	2015-11-25 15:49:57 UTC (rev 9318)
@@ -1,134 +1,144 @@
 <?php
+require_once(dirname(__FILE__) . "/../../extensions/fpdf/mb_fpdi.php");
 
-require_once(dirname(__FILE__)."/../../extensions/fpdf/mb_fpdi.php");
+class mbTemplatePdf extends mbPdf
+{
+    /* it seems several decorators are going to need this information */
+    public $mapInfo     = array();
+    public $unlinkFiles = false;
+    public $logRequests = false;
+    public $logType     = "file";
 
-class mbTemplatePdf extends mbPdf {
+    public function __construct($jsonConf)
+    {
+        $this->confPdf = $jsonConf;
+        if (!$this->confPdf->orientation || !$this->confPdf->units || !$this->confPdf->format) {
+            die("no valid config");
+        }
+        $this->objPdf         = new mb_fpdi($this->confPdf->orientation, $this->confPdf->units, $this->confPdf->format);
+        $this->outputFileName = $this->generateOutputFileName("map", "pdf");
+    }
 
-	/* it seems several decorators are going to need this information */
-	public $mapInfo = array();
-        public $unlinkFiles = false;
-        public $logRequests = false;
-        public $logType = "file";
+    public function setMapInfo($x_ul, $y_ul, $width, $height, $aBboxString)
+    {
+        $this->mapinfo["x_ul"]   = $x_ul;
+        $this->mapinfo["y_ul"]   = $y_ul;
+        $this->mapinfo["width"]  = $width;
+        $this->mapinfo["height"] = $height;
+        $this->mapinfo["extent"] = $aBboxString;
+        $e                       = new mb_notice("mbTemplatePdf: setting mapInfo ...");
+    }
 
-	public function __construct($jsonConf) {
-		$this->confPdf = $jsonConf;
-		if (!$this->confPdf->orientation ||	!$this->confPdf->units || !$this->confPdf->format) {
-			die("no valid config");
-		}	
-		$this->objPdf = new mb_fpdi($this->confPdf->orientation,
-									$this->confPdf->units,
-									$this->confPdf->format);
-		$this->outputFileName = $this->generateOutputFileName("map","pdf");
-	}
+    public function getMapInfo()
+    {
+        $e = new mb_notice("mbTemplatePdf: getting mapInfo ..");
+        return $this->mapinfo;
+    }
 
-	public function setMapInfo($x_ul, $y_ul, $width, $height, $aBboxString) {
-		$this->mapinfo["x_ul"] = $x_ul;
-		$this->mapinfo["y_ul"] = $y_ul;
-		$this->mapinfo["width"] = $width;
-		$this->mapinfo["height"] = $height;
-		$this->mapinfo["extent"] = $aBboxString;
-		$e = new mb_notice("mbTemplatePdf: setting mapInfo ...");
-	}
+    public function setMapExtent($aBboxString)
+    {
+        $this->mapinfo["extent"] = $aBboxString;
+        $e                       = new mb_notice("mbTemplatePdf: setting mapExtent to " . $this->mapinfo["extent"]);
+    }
 
-	public function getMapInfo() {
-		$e = new mb_notice("mbTemplatePdf: getting mapInfo ..");
-		return $this->mapinfo;
-	}
-	
-	public function setMapExtent($aBboxString) {
-		$this->mapinfo["extent"] = $aBboxString;
-		$e = new mb_notice("mbTemplatePdf: setting mapExtent to ".$this->mapinfo["extent"]);
-	}
-		
-	public function getMapExtent() {
-		$e = new mb_notice("mbTemplatePdf: getting mapExtent as ".$this->mapinfo["extent"]);
-		return $this->mapinfo["extent"];
-	}	
+    public function getMapExtent()
+    {
+        $e = new mb_notice("mbTemplatePdf: getting mapExtent as " . $this->mapinfo["extent"]);
+        return $this->mapinfo["extent"];
+    }
 
-	public function adjustBbox($elementConf, $aBboxArray, $aSrsString) {
-		$aMbBbox = new Mapbender_bbox($aBboxArray[0],$aBboxArray[1],$aBboxArray[2],$aBboxArray[3],$aSrsString);
-		$aMap = new Map();
-		$aMap->setWidth($elementConf->width);
-		$aMap->setHeight($elementConf->height);
-		$aMap->calculateExtent($aMbBbox);
-		$this->mapinfo["scale"] = isset($_REQUEST["scale"]) ? $_REQUEST["scale"] : $aMap->getScale($elementConf->res_dpi);
-		$adjustedMapExt = $aMap->getExtentInfo();
-		return implode(",",$adjustedMapExt);
-	}	
-	
-	public function render() {
-		foreach ($this->confPdf->pages as $pageConf) {
-			/* apply the template to the pdf page */
-			//$this->objPdf->addPage();
-            $pagecount = $this->objPdf->setSourceFile(dirname(__FILE__)."/../".$pageConf->tpl);
-            $tplidx = $this->objPdf->importPage($pageConf->useTplPage);
-            
+    public function adjustBbox($elementConf, $aBboxArray, $aSrsString)
+    {
+        $aMbBbox                = new Mapbender_bbox($aBboxArray[0], $aBboxArray[1], $aBboxArray[2], $aBboxArray[3],
+            $aSrsString);
+        $aMap                   = new Map();
+        $aMap->setWidth($elementConf->width);
+        $aMap->setHeight($elementConf->height);
+        $aMap->calculateExtent($aMbBbox);
+        $this->mapinfo["scale"] = isset($_REQUEST["scale"]) ? $_REQUEST["scale"] : $aMap->getScale($elementConf->res_dpi);
+        $adjustedMapExt         = $aMap->getExtentInfo();
+        return implode(",", $adjustedMapExt);
+    }
+
+    public function render()
+    {
+        foreach ($this->confPdf->pages as $pageConf) {
+            /* apply the template to the pdf page */
+            //$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{
+            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":
-						$err = new mbMapDecorator($this, $pageElementId, $pageElementConf, $controls);
-						break;
-					case "overview":
-						$err = new mbOverviewDecorator($this, $pageElementId, $pageElementConf, $controls);
-						break;
-					case "text":
-						$err = new mbTextDecorator($this, $pageElementId, $pageElementConf, $controls);
-						break;		
-					case "para":
-						$err = new mbParagraphDecorator($this, $pageElementId, $pageElementConf, $controls);
-						break;	
-					case "measure":
-						$err = new mbMeasureDecorator($this, $pageElementId, $pageElementConf, $controls);
-						break;		
-					case "image":
-						$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);
-						break;
-				}
+
+                switch ($pageElementConf->type) {
+                    case "map":
+                        $err = new mbMapDecorator($this, $pageElementId, $pageElementConf, $controls);
+                        $err = new mbSvgDecorator($this, $pageElementId, $pageElementConf, $controls, "map_svg_kml");
+                        $err = new mbSvgDecorator($this, $pageElementId, $pageElementConf, $controls, "map_svg_measures");
+                        break;
+                    case "overview":
+                        $err = new mbOverviewDecorator($this, $pageElementId, $pageElementConf, $controls);
+                        break;
+                    case "text":
+                        $err = new mbTextDecorator($this, $pageElementId, $pageElementConf, $controls);
+                        break;
+                    case "para":
+                        $err = new mbParagraphDecorator($this, $pageElementId, $pageElementConf, $controls);
+                        break;
+//                    case "measure": ignored, s. case "map":
+//                        $err = new mbSvgDecorator($this, $pageElementId, $pageElementConf, $controls, "map_svg_measures");
+//                        $err = new mbMeasureDecorator($this, $pageElementId, $pageElementConf, $controls);
+//                        break;
+                    case "image":
+                        $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);
+                        break;
+                }
             }
-            
+
             $this->isRendered = true;
-		}
-	}
-	
-	public function save() {
-		if ($this->isRendered) {
-			$this->objPdf->Output(TMPDIR."/".$this->outputFileName, "F");
-			$this->isSaved = true;
-		}
-	}
+        }
+    }
 
-        public function unlink($filename) {
-            if($this->unlinkFiles && $this->unlinkFiles == 'true') {
-               unlink($filename);
-            }
+    public function save()
+    {
+        if ($this->isRendered) {
+            $this->objPdf->Output(TMPDIR . "/" . $this->outputFileName, "F");
+            $this->isSaved = true;
         }
+    }
 
-        public function logWmsRequests($requestType, $wmsRequest) {
-            if($this->logRequests && $this->logRequests == 'true') {
-                include_once (dirname(__FILE__)."/../../classes/class_log.php");
-        	$logMessage = new log("printPDF_".$requestType,$wmsRequest,"",$this->logType);
-	    }
+    public function unlink($filename)
+    {
+        if ($this->unlinkFiles && $this->unlinkFiles == 'true') {
+            unlink($filename);
         }
+    }
+
+    public function logWmsRequests($requestType, $wmsRequest)
+    {
+        if ($this->logRequests && $this->logRequests == 'true') {
+            include_once (dirname(__FILE__) . "/../../classes/class_log.php");
+            $logMessage = new log("printPDF_" . $requestType, $wmsRequest, "", $this->logType);
+        }
+    }
 }
 
-
 ?>

Modified: trunk/mapbender/http/print/classes/mbTemplatePdfDecorator.php
===================================================================
--- trunk/mapbender/http/print/classes/mbTemplatePdfDecorator.php	2015-11-25 14:25:56 UTC (rev 9317)
+++ trunk/mapbender/http/print/classes/mbTemplatePdfDecorator.php	2015-11-25 15:49:57 UTC (rev 9318)
@@ -37,4 +37,4 @@
 
 }
 
-?>
\ No newline at end of file
+?>



More information about the Mapbender_commits mailing list