[Mapbender-commits] r4380 - in branches/2.6/http: classes javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Jul 16 11:20:05 EDT 2009


Author: christoph
Date: 2009-07-16 11:20:05 -0400 (Thu, 16 Jul 2009)
New Revision: 4380

Modified:
   branches/2.6/http/classes/class_wms.php
   branches/2.6/http/javascripts/map_obj.js
   branches/2.6/http/javascripts/mapnf.php
   branches/2.6/http/javascripts/mod_changeEPSG.php
   branches/2.6/http/javascripts/ovnf.php
Log:
optionally skip map request when SRS is not supported by WMS

Modified: branches/2.6/http/classes/class_wms.php
===================================================================
--- branches/2.6/http/classes/class_wms.php	2009-07-16 15:18:56 UTC (rev 4379)
+++ branches/2.6/http/classes/class_wms.php	2009-07-16 15:20:05 UTC (rev 4380)
@@ -35,6 +35,7 @@
 	var $wms_getfeatureinfo;
 	var $wms_getlegendurl;
 	var $wms_upload_url;
+	var $wms_srs = array();
 	  
 	var $fees;
 	var $accessconstraints;
@@ -622,9 +623,8 @@
 				}   
 				
 				if(mb_strtoupper($element[tag]) == "SRS"){
-	  				$this->objLayer[$cnt_layer]->wms_srs1 = $element[value];
 					// unique srs only, see http://www.mapbender.org/index.php/Arrays_with_unique_entries
-					$this->wms_srs = array_keys(array_flip(explode(" ", $this->objLayer[0]->wms_srs1)));  				
+					$this->wms_srs = array_keys(array_flip(array_merge($this->wms_srs, explode(" ", $element[value]))));  				
 				}						      
 				if(mb_strtoupper($element[tag]) == "LATLONBOUNDINGBOX"){
 					$cnt_epsg++;
@@ -815,7 +815,7 @@
 		echo "gui_wms_featureinfoformat: " . $this->gui_wms_featureinfoformat . " <br>";
 		echo "gui_wms_exceptionformat: " . $this->gui_wms_exceptionformat . " <br>";	
 		echo "gui_wms_epsg: " . $this->gui_wms_epsg . " <br>";
-		echo "wms_srs: " . $this->objLayer[0]->wms_srs1 . " <br>";		
+		echo "wms_srs: " . implode(", ", $this->wms_srs) . " <br>";		
 		echo "gui_wms_visible: " . $this->gui_wms_visible . " <br>";
 		echo "gui_wms_opacity: " . $this->gui_wms_opacity . " <br>";
 		echo "support_sld: " . $this->wms_supportsld . " <br>";
@@ -1032,6 +1032,13 @@
 					$this->objLayer[$i]->layer_epsg[$j]["maxx"] ."','". 
 					$this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');";
 			}
+			for($j=0; $i==0 && $j<count($this->wms_srs);$j++){
+					if($parent){
+					$str .= "parent.";
+					}
+					$str .= "wms_addSRS('". 
+						$this->wms_srs[$j] ."', null, null, null, null);\n";
+			}
 			for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
 				if($parent){
 				$str .= "parent.";
@@ -1845,6 +1852,16 @@
 				$count_wms++;
 			}
 	
+			### srs
+			$srs_sql = "SELECT * FROM wms_srs WHERE fkey_wms_id = $1 ";
+			$srs_v = array($wms_id);
+			$srs_t = array('i'); 
+			$srs_res = db_prep_query($srs_sql, $srs_v, $srs_t);
+			$this->wms_srs = array();
+			while($srs_row = db_fetch_array($srs_res)) {		
+				$this->wms_srs[]= $srs_row["wms_srs"];
+			}
+
 			### formats
 			$sql = "SELECT * FROM wms_format WHERE fkey_wms_id = $1 ";
 			$v = array($wms_id);

Modified: branches/2.6/http/javascripts/map_obj.js
===================================================================
--- branches/2.6/http/javascripts/map_obj.js	2009-07-16 15:18:56 UTC (rev 4379)
+++ branches/2.6/http/javascripts/map_obj.js	2009-07-16 15:20:05 UTC (rev 4380)
@@ -132,8 +132,69 @@
 		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 !== Extent) {
+			new Mb_exception("Mapbender.Map.setSrs: Extent is not an 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) {
+			new Mb_warning("The following WMS do not support the current SRS: " + ignoredWms.join(","));
+		}
+
+		// actually set the new values and return extent
+		this.epsg = options.srs;
+		return this.calculateExtent(options.extent);
+	};
+	
+	// private
 	this.width = width;
+	// private
 	this.height = height;
 	this.frameName = frameName;
 	this.type = (frameName !== "") ? "IFRAME" : "DIV";
@@ -144,10 +205,10 @@
 	this.geom = "";
 	this.gml = "";
 	this.wms = [];
-	
-	// 
+
+	//
 	// Add pointers to WMS objects which are in this map.
-	// If wms_index is set (=map is overview), only this 
+	// If wms_index is set (=map is overview), only this
 	// WMS is being pointed to.
 	//
 	var index = 0;
@@ -201,21 +262,27 @@
 		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]);
 		}
 	}
-	var wmsExtent = new Extent(bbox_minx, bbox_miny, bbox_maxx, bbox_maxy);
-	
-	this.calculateExtent(wmsExtent);
 
+	this.setSrs({
+		srs: wms[0].gui_wms_epsg,
+		extent: new Extent(
+			bbox_minx, 
+			bbox_miny, 
+			bbox_maxx, 
+			bbox_maxy
+		)
+	});
+
 	this.mapURL = [];
 	var domElement = this.getDomElement();
 	domElement.style.width = this.width;
@@ -378,7 +445,6 @@
 		var distx = extent.maxx - extent.minx;
 		var disty = extent.maxy - extent.miny;
 		
-		
 		if (x && y) {
 			var centerx = parseFloat(x);
 			var centery = parseFloat(y);
@@ -395,7 +461,6 @@
 		var maxx = centerx + new_distx / 2;
 		var maxy = centery + new_disty / 2;
 		this.setExtent(minx, miny, maxx, maxy);
-
 		this.setMapRequest();
 	};
 	
@@ -678,6 +743,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;
 			}
@@ -738,11 +812,17 @@
 		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;
 			}
 			myMapId.push(this.elementName + "_map_" + ii);
-			
 			newMapRequest += getLayerHtmlCode(ii);
 			
 		}

Modified: branches/2.6/http/javascripts/mapnf.php
===================================================================
--- branches/2.6/http/javascripts/mapnf.php	2009-07-16 15:18:56 UTC (rev 4379)
+++ branches/2.6/http/javascripts/mapnf.php	2009-07-16 15:20:05 UTC (rev 4380)
@@ -18,10 +18,23 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
+
 ?>
 
 (function () {
 
+<?php
+	include '../include/dyn_js.php';
+?>
+
+
+	try {
+		if (skipWmsIfSrsNotSupported) {}
+	}
+	catch (e) {
+		skipWmsIfSrsNotSupported = 0;
+	}
+
 	var mapTimeout;
 	var	sum_delta = 0;
 	var lastTimestamp;
@@ -34,6 +47,10 @@
 			
 		mapObject = mb_registerMapObj('', 'mapframe1', null,<?php echo $e_width; ?>, <?php echo $e_height; ?>);
 		
+		mapObject.skipWmsIfSrsNotSupported = 
+			skipWmsIfSrsNotSupported === 1 ? true : false;
+
+
 		$(document).mousewheel(function (e, delta) {
 			if (sum_delta == 0) {
 				mapTimeout = setTimeout(function () {
@@ -82,4 +99,4 @@
 			);
 		}
 	}
-})();
\ No newline at end of file
+})();

Modified: branches/2.6/http/javascripts/mod_changeEPSG.php
===================================================================
--- branches/2.6/http/javascripts/mod_changeEPSG.php	2009-07-16 15:18:56 UTC (rev 4379)
+++ branches/2.6/http/javascripts/mod_changeEPSG.php	2009-07-16 15:20:05 UTC (rev 4380)
@@ -84,24 +84,43 @@
 				}
 
 				if (goback) {
-					mb_mapObj[ind].epsg = newExtent[i].newSrs;
-					mb_mapObj[ind].extent = mb_mapObj[ind].mb_MapHistoryObj[exists].extent;
-					setMapRequest(newExtent[i].frameName);
+					var extArray = mb_mapObj[ind].mb_MapHistoryObj[exists].extent.split(",");
+					var newExt = new Extent(
+						parseFloat(extArray[0]),
+						parseFloat(extArray[1]),
+						parseFloat(extArray[2]),
+						parseFloat(extArray[3])
+					);
+					mb_mapObj[ind].setSrs({
+						srs: newExtent[i].newSrs,
+						extent: newExt
+					});
 				}
 				else{
-					mb_mapObj[ind].epsg = newExtent[i].newSrs;
-					mb_mapObj[ind].extent = parseFloat(newExtent[i].minx) + "," + parseFloat(newExtent[i].miny) + "," + 
-						parseFloat(newExtent[i].maxx) + "," + parseFloat(newExtent[i].maxy);
-				setMapRequest(newExtent[i].frameName);
+					mb_mapObj[ind].setSrs({
+						srs: newExtent[i].newSrs,
+						extent: new Extent(
+							parseFloat(newExtent[i].minx),
+							parseFloat(newExtent[i].miny),
+							parseFloat(newExtent[i].maxx),
+							parseFloat(newExtent[i].maxy)
+						)
+					});
 				}
 			}
 			else {
 				var ind = getMapObjIndexByName(newExtent[i].frameName);
-				mb_mapObj[ind].epsg = newExtent[i].newSrs;
-				mb_mapObj[ind].extent = parseFloat(newExtent[i].minx) + "," + parseFloat(newExtent[i].miny) + "," + 
-					parseFloat(newExtent[i].maxx) + "," + parseFloat(newExtent[i].maxy);
-				setMapRequest(newExtent[i].frameName);
+				mb_mapObj[ind].setSrs({
+					srs: newExtent[i].newSrs,
+					extent: new Extent(
+						parseFloat(newExtent[i].minx),
+						parseFloat(newExtent[i].miny),
+						parseFloat(newExtent[i].maxx),
+						parseFloat(newExtent[i].maxy)
+					)
+				});
 			}
+			setMapRequest(newExtent[i].frameName);
 		}
 
 

Modified: branches/2.6/http/javascripts/ovnf.php
===================================================================
--- branches/2.6/http/javascripts/ovnf.php	2009-07-16 15:18:56 UTC (rev 4379)
+++ branches/2.6/http/javascripts/ovnf.php	2009-07-16 15:20:05 UTC (rev 4380)
@@ -20,6 +20,13 @@
 require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
 include '../include/dyn_js.php';
 ?>
+try {
+	if (skipWmsIfSrsNotSupported) {}
+}
+catch (e) {
+	skipWmsIfSrsNotSupported = 0;
+}
+
 var mod_overview_target = "<?php echo $e_target[0]; ?>";
 if (typeof(overview_wms) === 'undefined')overview_wms = 0;
 overview_wms = parseInt(overview_wms);
@@ -29,16 +36,20 @@
 
 mb_registerMapObj('', 'overview', overview_wms ,<?php echo $e_width; ?>, <?php echo $e_height; ?>);
 parent.eventInitMap.register(function init_overview(){
-		var ind = getMapObjIndexByName('overview');
-		
-		var el = mb_mapObj[ind].getDomElement();
-		el.onmouseover = mod_ovSetHandler;
-		el.onmousedown = mod_box_start;
-		el.onmouseup = mod_ovGetExtent;
-		el.onmousemove = mod_box_run;
-		
-		var ov_extent = mb_mapObj[ind].getExtentInfos();
-		mb_mapObj[ind].isOverview = true;
+	var ind = getMapObjIndexByName('overview');
+	
+	var el = mb_mapObj[ind].getDomElement();
+	el.onmouseover = mod_ovSetHandler;
+	el.onmousedown = mod_box_start;
+	el.onmouseup = mod_ovGetExtent;
+	el.onmousemove = mod_box_run;
+	
+	var ov_extent = mb_mapObj[ind].getExtentInfos();
+	mb_mapObj[ind].isOverview = true;
+	
+	mb_mapObj[ind].skipWmsIfSrsNotSupported = 
+		skipWmsIfSrsNotSupported === 1 ? true : false;
+
 });
 
 function mod_ovSetHandler(e){



More information about the Mapbender_commits mailing list