[Mapbender-commits] r5314 - branches/2.6/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jan 13 06:06:02 EST 2010


Author: christoph
Date: 2010-01-13 06:06:02 -0500 (Wed, 13 Jan 2010)
New Revision: 5314

Modified:
   branches/2.6/http/classes/class_map.php
Log:


Modified: branches/2.6/http/classes/class_map.php
===================================================================
--- branches/2.6/http/classes/class_map.php	2010-01-13 11:05:38 UTC (rev 5313)
+++ branches/2.6/http/classes/class_map.php	2010-01-13 11:06:02 UTC (rev 5314)
@@ -237,6 +237,118 @@
 	 * @return 
 	 */
 	public function mergeWmsArray ($wmsArray) {
+		if (func_num_args() > 1 
+			&& is_array($wmsArray) 
+			&& count($wmsArray) > 0) {
+			
+			$options = func_get_arg(1);
+			if ($options["zoom"]) {
+				$ext = $this->getExtent();
+				$srs = $ext->epsg;
+				$currentWms = $wmsArray[0];
+
+				$bboxExists = false;
+				$wgs84Index = null;
+				// check if SRS of root layer matches WMC SRS
+				for ($i = 0; $i < count($currentWms->objLayer[0]->layer_epsg); $i++) {
+					$currentLayerEpsg = $currentWms->objLayer[0]->layer_epsg[$i];
+					if ($currentLayerEpsg["epsg"] !== $srs) {
+						if ($currentLayerEpsg["epsg"] = "EPSG:4326") {
+							$wgs84Index = $i;
+						}
+						continue;
+					}
+
+					// calculate WMC bbox from root layer bbox
+					$bboxExists = true;
+					$this->calculateExtent(new Mapbender_bbox(
+						$currentLayerEpsg["minx"], 
+						$currentLayerEpsg["miny"], 
+						$currentLayerEpsg["maxx"], 
+						$currentLayerEpsg["maxy"], 
+						$srs
+					));
+				}
+				
+				if (!$bboxExists && !is_null($wgs84Index)) {
+					$currentLayerEpsg = $currentWms->objLayer[0]->layer_epsg[$wgs84Index];
+					$extArray = array(
+						$currentLayerEpsg["minx"],
+						$currentLayerEpsg["miny"],
+						$currentLayerEpsg["maxx"],
+						$currentLayerEpsg["maxy"],
+					);
+					$oldEPSG = "4326";
+					$newEPSG = preg_replace("/EPSG:/","", $srs);
+
+					// calculate bbox via PostGIS
+					if(SYS_DBTYPE=='pgsql'){
+						$con = db_connect($DBSERVER,$OWNER,$PW);
+						$sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as minx";
+						$resMinx = db_query($sqlMinx);
+						$minx = floatval(db_result($resMinx,0,"minx"));
+						
+						$sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as miny";
+						$resMiny = db_query($sqlMiny);
+						$miny = floatval(db_result($resMiny,0,"miny"));
+						
+						$sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxx";
+						$resMaxx = db_query($sqlMaxx);
+						$maxx = floatval(db_result($resMaxx,0,"maxx"));
+						
+						$sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxy";
+						$resMaxy = db_query($sqlMaxy);
+						$maxy = floatval(db_result($resMaxy,0,"maxy"));
+					}
+					else{
+						$con_string = "host=$GEOS_DBSERVER port=$GEOS_PORT dbname=$GEOS_DB user=$GEOS_OWNER password=$GEOS_PW";
+						$con = pg_connect($con_string) or die ("Error while connecting database");
+						
+						$sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as minx";
+						$resMinx = pg_query($con,$sqlMinx);
+						$minx = floatval(pg_fetch_result($resMinx,0,"minx"));
+						
+						$sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as miny";
+						$resMiny = pg_query($con,$sqlMiny);
+						$miny = floatval(pg_fetch_result($resMiny,0,"miny"));
+						
+						$sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxx";
+						$resMaxx = pg_query($con,$sqlMaxx);
+						$maxx = floatval(pg_fetch_result($resMaxx,0,"maxx"));
+						
+						$sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxy";
+						$resMaxy = pg_query($con,$sqlMaxy);
+						$maxy = floatval(pg_fetch_result($resMaxy,0,"maxy"));
+					}
+					$bboxExists = true;
+					$this->calculateExtent(new Mapbender_bbox(
+						$minx, 
+						$miny, 
+						$maxx, 
+						$maxy, 
+						$srs
+					));
+				}
+				if (!$bboxExists) {
+					$e = new mb_exception(__FILE__ . ": mergeWmsArray: Could not determine bounding box of WMS in SRS " . $srs);
+				}
+			}
+			if ($options["show"] && is_numeric($options["show"])) {
+				// set all layers of WMS to visible
+				for ($i = 0; $i < count($wmsArray); $i++) {
+					$numLayers = count($wmsArray[$i]->objLayer);
+
+					// do not display if layer count is too big
+					if ($numLayers > intval($options["show"])) {
+						continue;
+					}
+					
+					for ($j = 0; $j < $numLayers; $j++) {
+						$wmsArray[$i]->objLayer[$j]->gui_layer_visible = 1;
+					}
+				}
+			}
+		}
 		$this->wmsArray = wms::merge(array_merge($this->wmsArray, $wmsArray));
 	}
 
@@ -472,12 +584,22 @@
 			// reset the WMS array
 			// BEWARE, SUPER UGLY CODE AHEAD!!
 			// (BUT THERE IS NO OTHER WAY TO DO IT)
-			if (strpos($row["e_src"], "mod_mapOV.php?wms") !== false) {
+			if (strpos($row["e_js_file"], "ovnf.php") !== false) {
 //				$e = new mb_exception("guess this is the OV");
-				$pattern = "/[\.\/a-zA-Z_]*\?wms=([0-9]*)[^0-9]*/";
-				$ovIndex = preg_replace($pattern, "\$1", $row["e_src"]);
+
+				$ov_sql = "SELECT var_value FROM gui_element_vars WHERE " . 
+					"var_name = 'overview_wms' AND fkey_e_id = $1 AND " . 
+					"fkey_gui_id = $2";
+				$ov_v = array($frameName, $appId);
+				$ov_t = array('s', 's');
+				$ov_res = db_prep_query($ov_sql, $ov_v, $ov_t);
+				$ov_row = db_fetch_array($ov_res);
+				if ($ov_row) {
+					$ov_index = intval($ov_row["var_value"]);
+				}
+				
 //				$e = new mb_exception("OV index: " . $ovIndex);
-				if (!$ovIndex) {
+				if (!isset($ovIndex)) {
 					$ovIndex = 0;
 				}
 				$wmsArray = array($wmsArray[$ovIndex]);	



More information about the Mapbender_commits mailing list