[Mapbender-commits] r6946 - in trunk/mapbender/http: plugins print

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Sep 27 07:25:23 EDT 2010


Author: christoph
Date: 2010-09-27 11:25:23 +0000 (Mon, 27 Sep 2010)
New Revision: 6946

Modified:
   trunk/mapbender/http/plugins/mb_print.js
   trunk/mapbender/http/print/printFactory.php
Log:
http://trac.osgeo.org/mapbender/ticket/708

Modified: trunk/mapbender/http/plugins/mb_print.js
===================================================================
--- trunk/mapbender/http/plugins/mb_print.js	2010-09-24 15:14:18 UTC (rev 6945)
+++ trunk/mapbender/http/plugins/mb_print.js	2010-09-27 11:25:23 UTC (rev 6946)
@@ -235,14 +235,14 @@
 	 * utility method to connect the form plugin to the print form.
 	 */	
 	var hookForm = function () {
-		var options = { 
+		var o = {
 	   		url:			'../print/printFactory.php', 
 	   		type:			'post',
 	   		dataType:		'json',
 	   		beforeSubmit: 	validate,
 	   		success:    	showResult
 		};
-		$("#"+myId+"_form").ajaxForm(options);	
+		$("#"+myId+"_form").ajaxForm(o);
 	};
 	
 	/**
@@ -272,14 +272,56 @@
 		}	
 	};
 	
-	
+	var replaceMapFileForHighQualityPrint = function (currentMapUrl) {
+		// check if hq print is requested
+		var resolutionControl = null;
+		for (var i in actualConfig.controls) {
+			var c = actualConfig.controls[i];
+			if ($.isPlainObject(c.pageElementsLink)) {
+				for (var j in c.pageElementsLink) {
+					if (c.pageElementsLink[j] === "res_dpi") {
+						resolutionControl = typeof c.id === "string" &&
+							c.id.length > 0 ? $("#" + c.id) : null;
+					}
+				}
+			}
+		}
+		if (resolutionControl !== null && resolutionControl.size() === 1) {
+			var dpi = resolutionControl.val();
+
+			// replace map file with hq map file (if configured)
+			var hqmapfiles = $.isArray(options.highqualitymapfiles) ?
+				options.highqualitymapfiles : [];
+			for (var i = 0; i < hqmapfiles.length; i++) {
+				var exp = new RegExp(hqmapfiles[i].pattern);
+				if (hqmapfiles[i].pattern && typeof currentMapUrl === "string" && currentMapUrl.match(exp)) {
+					// check if mapping in current resolution exists
+					var resolutions = hqmapfiles[i].replacement;
+					var resolutionExists = false;
+					for (var r in resolutions) {
+						if (r === dpi) {
+							resolutionExists = true;
+						}
+					}
+					if (resolutionExists) {
+						// replace with hqmapfile
+						var hqmapfile = resolutions[dpi];
+						currentMapUrl = currentMapUrl.replace(exp, hqmapfile);
+					}
+				}
+			}
+		}
+		return currentMapUrl;
+		
+	};
+
 	/**
 	 * Validates and updates form data values.
 	 * Adds the elements before the submit button.
 	 *
 	 * @see jquery.forms#beforeSubmitHandler
 	 */
-	var validate = function (formData, jqForm, options) {
+	var validate = function (formData, jqForm, params) {
 		showHideWorking("show");
 		
 		// map urls
@@ -299,7 +341,10 @@
 					if(f.map_url.value != ""){
 						f.map_url.value += '___';
 					}      
-					f.map_url.value += mb_mapObj[ind].getMapUrl(i, mb_mapObj[ind].getExtentInfos(), scale);
+					var currentMapUrl = mb_mapObj[ind].getMapUrl(i, mb_mapObj[ind].getExtentInfos(), scale);
+					
+					currentMapUrl = replaceMapFileForHighQualityPrint(currentMapUrl);
+					f.map_url.value += currentMapUrl
 
 					var wmsLegendObj = [];
 					
@@ -338,7 +383,8 @@
 		//overview_url
 		var ind_overview = getMapObjIndexByName('overview');
 		if(mb_mapObj[ind_overview].mapURL != false ){
-		    f.overview_url.value = mb_mapObj[ind_overview].mapURL;
+		    f.overview_url.value = replaceMapFileForHighQualityPrint(mb_mapObj[ind_overview].mapURL);
+
 			updateFormField(formData, "overview_url", f.overview_url.value);
 		}
 		
@@ -492,4 +538,4 @@
 
 };
 
-var printObj = new PrintPDF();
+var printObj = new PrintPDF(options);

Modified: trunk/mapbender/http/print/printFactory.php
===================================================================
--- trunk/mapbender/http/print/printFactory.php	2010-09-24 15:14:18 UTC (rev 6945)
+++ trunk/mapbender/http/print/printFactory.php	2010-09-27 11:25:23 UTC (rev 6946)
@@ -19,7 +19,13 @@
 $pdf = $pf->create($_REQUEST["printPDF_template"]);
 
 $pdf->render();
-$pdf->save();
+try {
+	$pdf->save();
+}
+catch (Exception $e) {
+	new mb_exception($e->message);
+	die;
+}
 
 print $pdf->returnAbsoluteUrl();
 ?>
\ No newline at end of file



More information about the Mapbender_commits mailing list