[Mapbender-commits] r6948 - trunk/mapbender/http/plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Sep 27 08:44:46 EDT 2010


Author: christoph
Date: 2010-09-27 12:44:46 +0000 (Mon, 27 Sep 2010)
New Revision: 6948

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

overview URL is also requested in hq

Modified: trunk/mapbender/http/plugins/mb_print.js
===================================================================
--- trunk/mapbender/http/plugins/mb_print.js	2010-09-27 11:38:42 UTC (rev 6947)
+++ trunk/mapbender/http/plugins/mb_print.js	2010-09-27 12:44:46 UTC (rev 6948)
@@ -271,13 +271,29 @@
 			}
 		}	
 	};
-	
-	var replaceMapFileForHighQualityPrint = function (currentMapUrl) {
+
+	var getCurrentResolution = function (type) {
+
+		// default resolution is 72 dpi
+		var dpi = 72;
+
+		// set resolution according to map configuration in template
+		for (var i in actualConfig.pages) {
+			var page = actualConfig.pages[i];
+			for (var j in page.elements) {
+				var el = page.elements[j];
+				if (type === el.type && typeof el.res_dpi === "number") {
+					dpi = el.res_dpi;
+				}
+			}
+		}
+		// set resolution according to resolution select box (if present)
+
 		// check if hq print is requested
 		var resolutionControl = null;
 		for (var i in actualConfig.controls) {
 			var c = actualConfig.controls[i];
-			if ($.isPlainObject(c.pageElementsLink)) {
+			try {
 				for (var j in c.pageElementsLink) {
 					if (c.pageElementsLink[j] === "res_dpi") {
 						resolutionControl = typeof c.id === "string" &&
@@ -285,34 +301,39 @@
 					}
 				}
 			}
+			catch (e) {
+			}
 		}
 		if (resolutionControl !== null && resolutionControl.size() === 1) {
-			var dpi = resolutionControl.val();
+			dpi = resolutionControl.val();
+		}
+		return parseInt(dpi, 10);
+	};
 
-			// 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;
-						}
+	var replaceMapFileForHighQualityPrint = function (currentMapUrl, type) {
+		var dpi = getCurrentResolution(type);
+		// 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 (parseInt(r, 10) === dpi) {
+						resolutionExists = true;
 					}
-					if (resolutionExists) {
-						// replace with hqmapfile
-						var hqmapfile = resolutions[dpi];
-						currentMapUrl = currentMapUrl.replace(exp, hqmapfile);
-					}
 				}
+				if (resolutionExists) {
+					// replace with hqmapfile
+					var hqmapfile = resolutions[dpi];
+					currentMapUrl = currentMapUrl.replace(exp, hqmapfile);
+				}
 			}
 		}
 		return currentMapUrl;
-		
 	};
 
 	/**
@@ -343,7 +364,7 @@
 					}      
 					var currentMapUrl = mb_mapObj[ind].getMapUrl(i, mb_mapObj[ind].getExtentInfos(), scale);
 					
-					currentMapUrl = replaceMapFileForHighQualityPrint(currentMapUrl);
+					currentMapUrl = replaceMapFileForHighQualityPrint(currentMapUrl, "map");
 					f.map_url.value += currentMapUrl
 
 					var wmsLegendObj = [];
@@ -386,7 +407,7 @@
 		    var overviewUrl = mb_mapObj[ind_overview].mapURL;
 			overviewUrl = $.isArray(overviewUrl) ? overviewUrl[0] : overviewUrl;
 
-		    f.overview_url.value = replaceMapFileForHighQualityPrint(overviewUrl);
+		    f.overview_url.value = replaceMapFileForHighQualityPrint(overviewUrl, "overview");
 
 			updateFormField(formData, "overview_url", f.overview_url.value);
 		}



More information about the Mapbender_commits mailing list