[Mapbender-commits] r5814 - in trunk/mapbender/http: classes javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Mar 19 10:39:05 EDT 2010


Author: christoph
Date: 2010-03-19 10:39:04 -0400 (Fri, 19 Mar 2010)
New Revision: 5814

Modified:
   trunk/mapbender/http/classes/class_map.php
   trunk/mapbender/http/classes/class_wmc.php
   trunk/mapbender/http/classes/class_wmcToXml.php
   trunk/mapbender/http/classes/class_wms.php
   trunk/mapbender/http/javascripts/mod_loadwmc.js
   trunk/mapbender/http/php/mod_loadwmc_server.php
Log:
store layer extents in WMC to allow zoom full

Modified: trunk/mapbender/http/classes/class_map.php
===================================================================
--- trunk/mapbender/http/classes/class_map.php	2010-03-19 14:37:29 UTC (rev 5813)
+++ trunk/mapbender/http/classes/class_map.php	2010-03-19 14:39:04 UTC (rev 5814)
@@ -425,6 +425,7 @@
 			$wms->wms_getfeatureinfo = $currentWms->wms_getfeatureinfo;
 			$wms->wms_getlegendurl = $currentWms->wms_getlegendurl;
 			$wms->wms_filter = $currentWms->wms_filter;
+			$wms->wms_srs = $currentWms->wms_srs;
 			$wms->gui_epsg = $currentWms->gui_epsg;
 			$wms->gui_minx = $currentWms->gui_minx;
 			$wms->gui_miny = $currentWms->gui_miny;

Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2010-03-19 14:37:29 UTC (rev 5813)
+++ trunk/mapbender/http/classes/class_wmc.php	2010-03-19 14:39:04 UTC (rev 5814)
@@ -165,15 +165,16 @@
         
         $res = db_prep_query($sql,$v,$t);
         if(db_error()) { return false; }
-        if($row = db_fetch_row($res))
-        {
+        if($row = db_fetch_row($res)) {
           $this->wmc_Id = $wmcId;
           $this->timestamp = $row[0];
           $this->title = $row[1];
           $this->public = $row[2];
         
         }
-
+		else {
+			return false;
+		}
 		return true;
 	}
 
@@ -486,7 +487,6 @@
 
 	public function updateUrlsFromDb () {
 		$query_mbWMSId = "/wmc:ViewContext/wmc:LayerList/wmc:Layer/wmc:Extension/mapbender:wms_id";
-		
 		try {
 			$WMCDoc = DOMDocument::loadXML($this->toXml());
 		} 
@@ -1391,7 +1391,7 @@
 							$extension = false;
 						}
 						if ($extension == true){
-							if ($value !== "") {
+//							if ($value !== "") {
 								if (isset($currentLayer["extension"][$tag])) {
 									if (!is_array($currentLayer["extension"][$tag])) {
 										$firstValue = $currentLayer["extension"][$tag];
@@ -1403,7 +1403,7 @@
 								else {
 									$currentLayer["extension"][$tag] = $value;									
 								}
-							}
+//							}
 						}
 						if ($tag == "EXTENSION" && $type == "open") {
 							$currentLayer["extension"] = array();
@@ -1434,21 +1434,6 @@
 			$this->setLayerData($layerlistCompleteArray[$i]);
 		}
 
-		// set zoom full extent for root layer of first WMS
-		$firstWms = $this->mainMap->getWms(0);
-		$firstWms->objLayer[0]->layer_epsg = array();
-		$boxList = $this->mainMap->getZoomFullExtentArray();
-		for ($i = 0; $i < count($boxList); $i++) {
-			$currentBox = $boxList[$i];
-			array_push($firstWms->objLayer[0]->layer_epsg, array(
-				"epsg" => $currentBox->epsg,
-				"minx" => $currentBox->min->x,
-				"miny" => $currentBox->min->y,
-				"maxx" => $currentBox->max->x,
-				"maxy" => $currentBox->max->y
-			));
-		}
-		
 		$wmsArr = $this->mainMap->getWmsArray();
 		for ($i = 0; $i < count($wmsArr); $i++) {
 			$wmsArr[$i]->updateAllOwsProxyUrls();
@@ -1570,7 +1555,7 @@
 			$wms->gui_wms_visible = $currentLayer["extension"]["WMS_VISIBLE"];
 			$wms->gui_wms_opacity = 100; // TODO : Add correct data
 			$wms->gui_wms_sldurl = $currentLayer["style"][$styleIndex]["sld_url"];
-
+			$wms->wms_srs = $currentLayer["epsg"];
 			$wms->gui_epsg = $currentLayer["epsg"];
 			//
 			// set data formats
@@ -1623,14 +1608,27 @@
 				for ($i=0; $i < count($layerEpsgArray); $i++) {
 					$currentLayerEpsg = array();
 					$currentLayerEpsg["epsg"] = $layerEpsgArray[$i];
-					$currentLayerEpsg["minx"] = floatval($layerMinXArray[$i]);
-					$currentLayerEpsg["miny"] = floatval($layerMinYArray[$i]); 
-					$currentLayerEpsg["maxx"] = floatval($layerMaxXArray[$i]);
-					$currentLayerEpsg["maxy"] = floatval($layerMaxYArray[$i]);
+
+
+					if ($layerMinXArray[$i] == 0
+						&& $layerMinYArray[$i] == 0
+						&& $layerMaxXArray[$i] == 0
+						&& $layerMaxYArray[$i] == 0
+						) {
+						$currentLayerEpsg["minx"] = null;
+						$currentLayerEpsg["miny"] = null; 
+						$currentLayerEpsg["maxx"] = null;
+						$currentLayerEpsg["maxy"] = null;
+					}
+					else {
+						$currentLayerEpsg["minx"] = floatval($layerMinXArray[$i]);
+						$currentLayerEpsg["miny"] = floatval($layerMinYArray[$i]); 
+						$currentLayerEpsg["maxx"] = floatval($layerMaxXArray[$i]);
+						$currentLayerEpsg["maxy"] = floatval($layerMaxYArray[$i]);
+					}
 					array_push($wms->objLayer[0]->layer_epsg, $currentLayerEpsg);
 				}
 			}			
-
 			// add WMS
 			array_push($wmsArray, $wms);
 

Modified: trunk/mapbender/http/classes/class_wmcToXml.php
===================================================================
--- trunk/mapbender/http/classes/class_wmcToXml.php	2010-03-19 14:37:29 UTC (rev 5813)
+++ trunk/mapbender/http/classes/class_wmcToXml.php	2010-03-19 14:39:04 UTC (rev 5814)
@@ -370,9 +370,9 @@
 			$wms_epsg[1] = $currentWms->gui_wms_epsg;
 		}
 
-		for ($j = 0; $j < count($currentWms->gui_wms_epsg); $j++) {
-			if (!in_array($currentWms->gui_wms_epsg[$j], $wms_epsg)){
-				array_push($wms_epsg, $currentWms->gui_wms_epsg[$j]);
+		for ($j = 0; $j < count($currentWms->gui_epsg); $j++) {
+			if (!in_array($currentWms->gui_epsg[$j], $wms_epsg)){
+				array_push($wms_epsg, $currentWms->gui_epsg[$j]);
 			}
 		}
 
@@ -425,6 +425,24 @@
 		$layerExtensionData["gui_queryable"] = $currentLayer->gui_layer_queryable;
 		$layerExtensionData["gui_status"] = $currentLayer->gui_layer_status;
 		$layerExtensionData["layer_epsg"] = $currentLayer->layer_epsg;
+		for ($i = 0; $i < count($currentWms->gui_epsg); $i++) {
+			$found = false;
+			for ($j = 0; $j < count($layerExtensionData["layer_epsg"]); $j++) {
+				if ($layerExtensionData["layer_epsg"][$j]["epsg"] == $currentWms->gui_epsg[$i]) {
+					$found = true;
+					break;
+				}
+			}
+			if (!$found) {
+				$layerExtensionData["layer_epsg"][]= array(
+					"epsg" => $currentWms->gui_epsg[$i],
+					"minx" => $currentWms->gui_minx[$i],
+					"miny" => $currentWms->gui_miny[$i],
+					"maxx" => $currentWms->gui_maxx[$i],
+					"maxy" => $currentWms->gui_maxy[$i]
+				);
+			}
+		}
 
 		if ($currentLayer->gui_layer_wfs_featuretype !== "") {
 			$layerExtensionData["wfsFeatureType"] = $currentLayer->gui_layer_wfs_featuretype;

Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php	2010-03-19 14:37:29 UTC (rev 5813)
+++ trunk/mapbender/http/classes/class_wms.php	2010-03-19 14:39:04 UTC (rev 5814)
@@ -1054,6 +1054,7 @@
 		//
 		// set layer epsg
 		//
+		$tmpEpsgArray= array();
 		$newLayer->layer_epsg = array();
 		if ($currentLayer["extension"]["EPSG"]) {
 			$layerEpsgArray = array();
@@ -1079,15 +1080,38 @@
 			for ($i=0; $i < count($layerEpsgArray); $i++) {
 				$currentLayerEpsg = array();
 				$currentLayerEpsg["epsg"] = $layerEpsgArray[$i];
-				$currentLayerEpsg["minx"] = floatval($layerMinXArray[$i]);
-				$currentLayerEpsg["miny"] = floatval($layerMinYArray[$i]); 
-				$currentLayerEpsg["maxx"] = floatval($layerMaxXArray[$i]);
-				$currentLayerEpsg["maxy"] = floatval($layerMaxYArray[$i]);
+				$tmpEpsgArray[]= $layerEpsgArray[$i];
+				if ($layerMinXArray[$i] == 0
+					&& $layerMinYArray[$i] == 0
+					&& $layerMaxXArray[$i] == 0
+					&& $layerMaxYArray[$i] == 0
+					) {
+					$currentLayerEpsg["minx"] = null;
+					$currentLayerEpsg["miny"] = null; 
+					$currentLayerEpsg["maxx"] = null;
+					$currentLayerEpsg["maxy"] = null;
+				}
+				else {
+					$currentLayerEpsg["minx"] = floatval($layerMinXArray[$i]);
+					$currentLayerEpsg["miny"] = floatval($layerMinYArray[$i]); 
+					$currentLayerEpsg["maxx"] = floatval($layerMaxXArray[$i]);
+					$currentLayerEpsg["maxy"] = floatval($layerMaxYArray[$i]);
+				}
 				array_push($newLayer->layer_epsg, $currentLayerEpsg);
 			}
 		}
+		for ($i = 0; $i < count($currentLayer["epsg"]); $i++) {
+			if (!in_array($currentLayer["epsg"][$i], $tmpEpsgArray)) {
+				$newLayer->layer_epsg[]= array(
+					"epsg" => $currentLayer["epsg"][$i],
+					"minx" => null,
+					"miny" => null,
+					"maxx" => null,
+					"maxy" => null
+				);
+			}
+		}
 
-
 		//
 		// set layer style
 		//
@@ -1102,7 +1126,8 @@
 	}
 	
 	  function createJsObjFromWMS_($parent=0){
-	  	$str = "";
+
+		$str = "";
 	  	if(!$this->wms_title || $this->wms_title == ""){
 			$str .= "alert('Error: no valid capabilities-document !!');";
 			die; exit;
@@ -1138,7 +1163,6 @@
 			}		
 			$str .= "wms_add_data_type_format('". $this->data_type[$i] ."','". $this->data_format[$i] ."');";		
 		}
-		
 		for($i=0; $i<count($this->objLayer); $i++){
 			if($parent){
 				$str .= "parent.";
@@ -1166,26 +1190,29 @@
 				$this->objLayer[$i]->gui_layer_wfs_featuretype ."');";
 				
 			for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
+				$currentEpsg = $this->objLayer[$i]->layer_epsg[$j];
 				if($i==0){
 					if($parent){
 						$str .= "parent.";
 					}
 					$str .= "wms_addSRS('". 
-						$this->objLayer[$i]->layer_epsg[$j]["epsg"] ."',". 
-						$this->objLayer[$i]->layer_epsg[$j]["minx"] .",". 
-						$this->objLayer[$i]->layer_epsg[$j]["miny"] .",". 
-						$this->objLayer[$i]->layer_epsg[$j]["maxx"] .",". 
-						$this->objLayer[$i]->layer_epsg[$j]["maxy"] .");";
+						$currentEpsg["epsg"] ."',". 
+						(is_null($currentEpsg["minx"]) ? "null" : $currentEpsg["minx"]) .",". 
+						(is_null($currentEpsg["miny"]) ? "null" : $currentEpsg["miny"]) .",". 
+						(is_null($currentEpsg["maxx"]) ? "null" : $currentEpsg["maxx"]) .",". 
+						(is_null($currentEpsg["maxy"]) ? "null" : $currentEpsg["maxy"]) .");";
 				}
-				if($parent){
-					$str .=  "parent.";
+				if (!is_null($currentEpsg["epsg"])) {
+					if($parent){
+						$str .=  "parent.";
+					}
+					$str .= "layer_addEpsg('". 
+						$currentEpsg["epsg"] ."',". 
+						(is_null($currentEpsg["minx"]) ? "null" : $currentEpsg["minx"]) .",". 
+						(is_null($currentEpsg["miny"]) ? "null" : $currentEpsg["miny"]) .",". 
+						(is_null($currentEpsg["maxx"]) ? "null" : $currentEpsg["maxx"]) .",". 
+						(is_null($currentEpsg["maxy"]) ? "null" : $currentEpsg["maxy"]) .");";
 				}
-				$str .= "layer_addEpsg('". 
-					$this->objLayer[$i]->layer_epsg[$j]["epsg"] ."',". 
-					$this->objLayer[$i]->layer_epsg[$j]["minx"] .",". 
-					$this->objLayer[$i]->layer_epsg[$j]["miny"] .",". 
-					$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++){
 				$found = false;

Modified: trunk/mapbender/http/javascripts/mod_loadwmc.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_loadwmc.js	2010-03-19 14:37:29 UTC (rev 5813)
+++ trunk/mapbender/http/javascripts/mod_loadwmc.js	2010-03-19 14:39:04 UTC (rev 5814)
@@ -625,15 +625,21 @@
 		that.show();
 	}	
 	
-	// checks if element var loadFromSession exists
-	if (loadFromSession === undefined) {
-		loadFromSession = 0;
+	try {
+		
+		// checks if element var loadFromSession exists
+		if (loadFromSession === undefined) {
+			loadFromSession = 0;
+		}
+		
+		if (loadFromSession) {
+			Mapbender.events.init.register(function () {
+				load_wmc_session();
+			});
+		}
 	}
-	
-	if (loadFromSession) {
-		Mapbender.events.init.register(function () {
-			load_wmc_session();
-		});
+	catch (exc) {
+		new Mapbender.Exception(exc);
 	}
 };
 

Modified: trunk/mapbender/http/php/mod_loadwmc_server.php
===================================================================
--- trunk/mapbender/http/php/mod_loadwmc_server.php	2010-03-19 14:37:29 UTC (rev 5813)
+++ trunk/mapbender/http/php/mod_loadwmc_server.php	2010-03-19 14:39:04 UTC (rev 5814)
@@ -55,23 +55,22 @@
 	// loads a WMC (returns array of JS code)
 	case 'loadWmc':
 		$wmcId = $ajaxResponse->getParameter("id");
-		$wmc->createFromDb($wmcId);
-
-		// FIXME: maybe wrap in if condition (configurable by element vars)
-		$updatedWMC = $wmc->updateUrlsFromDb();
-        $wmc->createFromXml($updatedWMC);
-		
-		$skipWms = $ajaxResponse->getParameter("skipWms");
-        $jsArray = $wmc->toJavaScript($skipWms);
-		if ($jsArray) {
-			$resultObj["javascript"] = $jsArray;
-			$ajaxResponse->setResult($resultObj); 
-			$ajaxResponse->setSuccess(true);
+		;
+		if ($wmc->createFromDb($wmcId)) {
+			$updatedWMC = $wmc->updateUrlsFromDb();
+	        $wmc->createFromXml($updatedWMC);
+			
+			$skipWms = $ajaxResponse->getParameter("skipWms");
+	        $jsArray = $wmc->toJavaScript($skipWms);
+			if ($jsArray) {
+				$resultObj["javascript"] = $jsArray;
+				$ajaxResponse->setResult($resultObj); 
+				$ajaxResponse->setSuccess(true);
+				break;
+			}
 		}
-		else {
-			$ajaxResponse->setMessage(_mb("WMC could not be loaded."));
-			$ajaxResponse->setSuccess(false);
-		}
+		$ajaxResponse->setMessage(_mb("WMC could not be loaded."));
+		$ajaxResponse->setSuccess(false);
 	break;
 
 	case 'loadWmcFromFile':



More information about the Mapbender_commits mailing list