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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Sep 28 09:15:03 EDT 2010


Author: christoph
Date: 2010-09-28 13:15:03 +0000 (Tue, 28 Sep 2010)
New Revision: 6955

Modified:
   trunk/mapbender/http/classes/class_bbox.php
   trunk/mapbender/http/classes/class_map.php
   trunk/mapbender/http/classes/class_wms_1_1_1_factory.php
   trunk/mapbender/http/javascripts/initWmcObj.php
Log:
http://trac.osgeo.org/mapbender/ticket/709

Modified: trunk/mapbender/http/classes/class_bbox.php
===================================================================
--- trunk/mapbender/http/classes/class_bbox.php	2010-09-28 13:14:26 UTC (rev 6954)
+++ trunk/mapbender/http/classes/class_bbox.php	2010-09-28 13:15:03 UTC (rev 6955)
@@ -92,7 +92,13 @@
 			
 		}
 	}
-	
+
+	public static function createFromLayerEpsg ($c) {
+		return new Mapbender_bbox(
+			$c["minx"], $c["miny"], $c["maxx"], $c["maxy"], $c["epsg"]
+		);
+	}
+
 	/**
 	 * Computes a new bounding box, bbox1 UNION bbox2
 	 */

Modified: trunk/mapbender/http/classes/class_map.php
===================================================================
--- trunk/mapbender/http/classes/class_map.php	2010-09-28 13:14:26 UTC (rev 6954)
+++ trunk/mapbender/http/classes/class_map.php	2010-09-28 13:15:03 UTC (rev 6955)
@@ -256,7 +256,103 @@
 	public function appendWmsArray ($wmsArray) {
 		$this->wmsArray = array_merge($this->wmsArray, $wmsArray);
 	}
-	
+
+	private function reprojectExtent ($bbox) {
+		if (!is_a($bbox, "Mapbender_bbox")) {
+			throw new Exception("Input must be a Mapbender bounding box.");
+		}
+		if (preg_replace("/EPSG:/","", $bbox->epsg) !== "4326") {
+			throw new Exception("Input must be a WGS84 bounding box.");
+		}
+		$ext = $this->getExtent();
+		$srs = $ext->epsg;
+
+		$extArray = array(
+			$bbox->min->x,
+			$bbox->min->y,
+			$bbox->max->x,
+			$bbox->max->y
+		);
+		$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"));
+		}
+
+		if ($minx && $miny && $maxx && $maxy) {
+			return new Mapbender_bbox(
+				$minx,
+				$miny,
+				$maxx,
+				$maxy,
+				$srs
+			);
+		}
+		throw new Exception("Bounding box reprojection failed.");
+	}
+
+	public function mergeExtent ($input) {
+		$ext = $this->getExtent();
+		$srs = $ext->epsg;
+
+		$bboxArray = $input;
+
+		if (is_a($input, "Mapbender_bbox")) {
+			$bboxArray = array($input);
+		}
+
+		// assume bbox array
+		if (is_array($input)) {
+
+			$wgs84Index = null;
+
+			// check if SRS matches WMC SRS
+			for ($i = 0; $i < count($bboxArray); $i++) {
+				$c = $bboxArray[$i];
+				if ($c->epsg !== $srs) {
+					if ($c->epsg === "EPSG:4326") {
+						$wgs84Index = $i;
+					}
+					continue;
+				}
+
+				// recalculate WMC bbox
+				$this->calculateExtent($c);
+				return;
+			}
+
+			if (!is_null($wgs84Index)) {
+				try {
+					$c = $bboxArray[$wgs84Index];
+					$reprojectedBbox = $this->reprojectExtent($c);
+					$this->calculateExtent($reprojectedBbox);
+				}
+				catch (Exception $e) {
+					new mb_exception("Could not merge extent.");
+				}
+				return;
+			}
+		}
+		$e = new mb_exception(__FILE__ . ": mergeWmsArray: Could not determine bounding box of WMS in SRS " . $srs);
+	}
+
 	/**
 	 * Merge WMS into this map
 	 * 
@@ -269,98 +365,14 @@
 			$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
+				$bboxArray = array();
 				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"],
+					$bboxArray[]= Mapbender_bbox::createFromLayerEpsg(
+						$currentWms->objLayer[0]->layer_epsg[$i]
 					);
-					$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"));
-					}
-					if ($minx && $miny && $maxx && $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);
-				}
+				$this->mergeExtent($bboxArray);
 			}
 			
 			// visibility of WMS

Modified: trunk/mapbender/http/classes/class_wms_1_1_1_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wms_1_1_1_factory.php	2010-09-28 13:14:26 UTC (rev 6954)
+++ trunk/mapbender/http/classes/class_wms_1_1_1_factory.php	2010-09-28 13:15:03 UTC (rev 6955)
@@ -85,19 +85,9 @@
 		// 2. delete layers not for keeping
 		//
 		$i = 0;
-		$isParent = true;
 		while ($i < count($myWms->objLayer)) {
 			$l = $myWms->objLayer[$i];
 			if (in_array($l->layer_uid, $keep)) {
-				if ($isParent) {
-					if ($l->layer_uid === $currentLayer->layer_uid) {
-						$isParent = false;
-					}
-					else {
-						// use extent of the requested layers, overwrite parent extent
-						$l->layer_epsg = $currentLayer->layer_epsg;
-					}
-				}
 				$i++;
 				continue;
 			}

Modified: trunk/mapbender/http/javascripts/initWmcObj.php
===================================================================
--- trunk/mapbender/http/javascripts/initWmcObj.php	2010-09-28 13:14:26 UTC (rev 6954)
+++ trunk/mapbender/http/javascripts/initWmcObj.php	2010-09-28 13:15:03 UTC (rev 6955)
@@ -25,7 +25,8 @@
 try {
 	$loadFromSession = new ElementVar($app, "loadwmc", "loadFromSession");
 	if ($loadFromSession->value === "1") {
-		//check if session contains a wmc, otherwise create a new wmc from application
+		//check if session contains a wmc,
+		//otherwise create a new wmc from application
 		$e = new mb_notice("trying to load session WMC...");
 		if (!$wmc->createFromXml($wmcDocSession)) {
 			$e = new mb_notice("loading session WMC failed.");
@@ -171,7 +172,9 @@
 		// just make it work for a single layer id
 		$wmsFactory = new UniversalWmsFactory();
 		if (isset($input["application"])) {
-			$wms = $wmsFactory->createLayerFromDb($input["id"], $input["application"]);
+			$wms = $wmsFactory->createLayerFromDb(
+				$input["id"], $input["application"]
+			);
 		}
 		else {
 			$wms = $wmsFactory->createLayerFromDb($input["id"]);
@@ -182,13 +185,29 @@
 			// make WMS visible if it has less than 100000 layers
 			$options["show"] = 100000;
 		}
-		if ($input["zoom"]) {
-			$options["zoom"] = $input["zoom"];
-		}
 		if (isset($input["querylayer"])) {
 			$options["querylayer"] = $input["querylayer"];
 		}
 		$wmc->mergeWmsArray(array($wms), $options);
+
+		// do not use "zoom" attribute of mergeWmsArray,
+		// as this would zoom to the entre WMS.
+		// Here we set extent to the layer extent only.
+		if ($input["zoom"]) {
+				$bboxArray = array();
+				try {
+					$layer = $wms->getLayerById(intval($input["id"]));
+					for ($i = 0; $i < count($layer->layer_epsg); $i++) {
+						$bboxArray[]= Mapbender_bbox::createFromLayerEpsg(
+							$layer->layer_epsg[$i]
+						);
+					}
+					$wmc->mainMap->mergeExtent($bboxArray);
+				}
+				catch (Exception $e) {
+					
+				}
+		}
 	}
 }
 



More information about the Mapbender_commits mailing list