[Mapbender-commits] r4449 - trunk/mapbender/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jul 29 09:36:42 EDT 2009


Author: christoph
Date: 2009-07-29 09:36:42 -0400 (Wed, 29 Jul 2009)
New Revision: 4449

Modified:
   trunk/mapbender/http/javascripts/map_obj.js
Log:


Modified: trunk/mapbender/http/javascripts/map_obj.js
===================================================================
--- trunk/mapbender/http/javascripts/map_obj.js	2009-07-29 13:36:03 UTC (rev 4448)
+++ trunk/mapbender/http/javascripts/map_obj.js	2009-07-29 13:36:42 UTC (rev 4449)
@@ -3,7 +3,7 @@
 * COPYRIGHT: (C) 2001 by ccgis. This program is free software under the GNU General Public
 * License (>=v2). Read the file gpl.txt that comes with Mapbender for details. 
 */
-
+ 
 /**
  * Package: Map
  * 
@@ -196,7 +196,77 @@
 		this.setExtent(ext.minx, ext.miny, ext.maxx, ext.maxy);
 		return ext;
 	};
+ 
+	var ignoredWms = [];
 
+	var undoIgnoreWms = function () {
+		ignoredWms = [];
+	};
+	
+	var ignoreWms = function (wms) {
+		ignoredWms.push(wms.wms_id);
+	};
+	
+	var isIgnoredWms = function (wms) {
+		for (var j = 0; j < ignoredWms.length; j++) {
+			if (ignoredWms[j] === wms.wms_id) {
+				return true;
+			}
+		}
+		return false;
+	};
+	
+	var getIgnoredWms = function () {
+		return ignoredWms;
+	};
+	
+	this.setSrs = function (options) {
+		if (typeof options.srs !== "string") {
+			new Mb_exception("Mapbender.Map.setSrs: SRS is not a string: " + options.srs);
+			return null;
+		}
+		if (!options.extent || options.extent.constructor !== Mapbender.Extent) {
+			new Mb_exception("Mapbender.Map.setSrs: Extent is not a Mapbender.Extent: " + options.extent);
+			return null;
+		}
+		
+		// check which WMS support the new SRS
+		undoIgnoreWms();
+		for (var i = 0; i < this.wms.length; i++) {
+			var found = false;
+			for (var j = 0; j < this.wms[i].gui_epsg.length; j++) {
+				if (options.srs === this.wms[i].gui_epsg[j]) {
+					found = true;
+					break;
+				}
+			}
+			if (!found) {
+				ignoreWms(this.wms[i]);
+			}
+		}
+		var ignoredWms = getIgnoredWms();
+
+		// ...and optionally display a message
+		if (options.displayWarning && ignoredWms.length > 0) {
+			var msg = "The following WMS do not support the current SRS: " + 
+				ignoredWms.join(",");
+			try {
+				Mapbender.modules.dialogManager.openDialog({
+					content: msg,
+					modal: false,
+					effectShow: 'puff'
+				});
+			}
+			catch (e) {
+				new Mb_warning(e.message + " " + msg);
+			}
+		}
+
+		// actually set the new values and return extent
+		this.epsg = options.srs;
+		return this.calculateExtent(options.extent);
+	};
+	
 	// private
 	this.width = width;
 	// private
@@ -267,20 +337,28 @@
 		this.querylayers[i] = querylayers;
 	}
 	
-	this.epsg = wms[0].gui_wms_epsg;
 	var bbox_minx, bbox_miny, bbox_maxx, bbox_maxy;
 	
 	for (var i = 0; i < wms[0].gui_epsg.length; i++) {
-		if (this.epsg == wms[0].gui_epsg[i]) {
+		if (wms[0].gui_wms_epsg == wms[0].gui_epsg[i]) {
 			bbox_minx = parseFloat(wms[0].gui_minx[i]);
 			bbox_miny = parseFloat(wms[0].gui_miny[i]);
 			bbox_maxx = parseFloat(wms[0].gui_maxx[i]);
 			bbox_maxy = parseFloat(wms[0].gui_maxy[i]);
+			break;
 		}
 	}
-	var wmsExtent = new Mapbender.Extent(bbox_minx, bbox_miny, bbox_maxx, bbox_maxy);
-	this.calculateExtent(wmsExtent);
 
+	this.setSrs({
+		srs: wms[0].gui_wms_epsg,
+		extent: new Mapbender.Extent(
+			bbox_minx, 
+			bbox_miny, 
+			bbox_maxx, 
+			bbox_maxy
+		)
+	});
+
 	this.mapURL = [];
 	var domElement = this.getDomElement();
 	domElement.style.width = this.width;
@@ -415,8 +493,8 @@
 	this.zoomFull = function () {
 		
 		if (this.restrictedExtent) {
-			var newExtent = this.calculateExtent(this.restrictedExtent);
-			this.repaint(new Point(newExtent.minx, newExtent.miny), new Point(newExtent.maxx, newExtent.maxy));
+			this.calculateExtent(this.restrictedExtent);
+			this.setMapRequest();
 		}
 		else {
 			for (var i = 0; i < this.wms[0].gui_epsg.length; i++) {
@@ -427,8 +505,8 @@
 					var bbox_maxy = parseFloat(this.wms[0].gui_maxy[i]);
 	
 					var wmsExtent = new Mapbender.Extent(bbox_minx, bbox_miny, bbox_maxx, bbox_maxy);
-					var newExtent = this.calculateExtent(wmsExtent);
-					this.repaint(newExtent.min, newExtent.max);
+					this.calculateExtent(wmsExtent);
+					this.setMapRequest();
 					break;
 				}
 			}
@@ -631,7 +709,7 @@
 		}
 		
 		url += "EXCEPTIONS=" + currentWms.gui_wms_exceptionformat + "&";
-		
+	 	
 		// add vendor-specific
 		for (var v = 0; v < mb_vendorSpecific.length; v++) {
 			var functionName = 'setMapRequest';
@@ -777,7 +855,7 @@
 	
 	this.repaint = function(min, max){
 		if (typeof min !== "undefined" && typeof max !== "undefined") {
-			this.extent = new Mapbender.Extent(min, max);
+			this.extent = this.calculateExtent(new Extent(min, max));
 		}
 		this.setMapRequest();
 	};
@@ -789,6 +867,15 @@
 	
 		for (var ii = 0; ii < this.wms.length; ii++){ 
 			var currentWms = this.wms[ii];
+
+			try {
+				if (!this.requestMapIfSrsNotSupported && isIgnoredWms(currentWms)) {
+					continue;
+				};
+			}
+			catch (e) {
+			}
+
 			if (currentWms.wms_id != wms_id) {
 				continue;
 			}
@@ -855,6 +942,13 @@
 		for (var ii = 0; ii < this.wms.length; ii++) {
 			var currentWms = this.wms[ii];
 		
+			try {
+				if (this.skipWmsIfSrsNotSupported && isIgnoredWms(currentWms)) {
+					continue;
+				};
+			}
+			catch (e) {
+			}
 			if (!(currentWms.gui_wms_visible > 0)) {
 				continue;
 			}



More information about the Mapbender_commits mailing list