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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Oct 4 10:23:02 EDT 2010


Author: christoph
Date: 2010-10-04 14:23:01 +0000 (Mon, 04 Oct 2010)
New Revision: 7019

Modified:
   trunk/mapbender/http/classes/class_bbox.php
   trunk/mapbender/http/classes/class_map.php
   trunk/mapbender/http/classes/class_universal_wms_factory.php
   trunk/mapbender/http/classes/class_wmc.php
   trunk/mapbender/http/classes/class_wms.php
   trunk/mapbender/http/javascripts/initWmcObj.php
   trunk/mapbender/http/plugins/mb_sessionWmc.js
Log:
GET API 
* zoom to layer
* authorisation

Modified: trunk/mapbender/http/classes/class_bbox.php
===================================================================
--- trunk/mapbender/http/classes/class_bbox.php	2010-10-04 14:08:49 UTC (rev 7018)
+++ trunk/mapbender/http/classes/class_bbox.php	2010-10-04 14:23:01 UTC (rev 7019)
@@ -180,5 +180,15 @@
 	function toJson() {
 		return (string) "[" . $this->min->x . ",". $this->min->y . "," . $this->max->x . "," . $this->max->y . "]";
 	}
+
+	function toJavaScript () {
+		return (string) "{" .
+			"srs: '" . $this->epsg . "'," .
+			"extent: new Mapbender.Extent(" .
+			$this->min->x . ", " .
+			$this->min->y . ", " .
+			$this->max->x . ", " .
+			$this->max->y . ")}";
+	}
 }
 ?>

Modified: trunk/mapbender/http/classes/class_map.php
===================================================================
--- trunk/mapbender/http/classes/class_map.php	2010-10-04 14:08:49 UTC (rev 7018)
+++ trunk/mapbender/http/classes/class_map.php	2010-10-04 14:23:01 UTC (rev 7019)
@@ -638,13 +638,9 @@
 		}
 
 		// calculate extent
-		$calcExtentString = "currentWmcMap.setSrs({" . 
-			"srs: '" . $this->extent->epsg . "'," . 
-			"extent: new Mapbender.Extent(" . 
-			$this->extent->min->x . ", " . 
-			$this->extent->min->y . ", " . 
-			$this->extent->max->x . ", " . 
-			$this->extent->max->y . ")});"; 
+		$calcExtentString = "currentWmcMap.setSrs(" . 
+			$this->extent->toJavaScript() .
+			");";
 		array_push($jsCodeArray, $calcExtentString);
 		
 		$setWmsString = "currentWmcMap.setWms(" . $wmsJson . ");";
@@ -653,10 +649,13 @@
 		$initWmsString = "currentWmcMap.initializeWms();";
 		array_push($jsCodeArray, $initWmsString);
 
-
 		return $jsCodeArray;
 	}
 
+	function extentToJavaScript () {
+		return "$('#" . $this->frameName . "').mapbender().setSrs(" .
+			$this->extent->toJavaScript() . ")";
+	}
 
 	// ------------------------------------------------------------------------
 	// PRIVATE FUNCTIONS

Modified: trunk/mapbender/http/classes/class_universal_wms_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_universal_wms_factory.php	2010-10-04 14:08:49 UTC (rev 7018)
+++ trunk/mapbender/http/classes/class_universal_wms_factory.php	2010-10-04 14:23:01 UTC (rev 7019)
@@ -123,23 +123,17 @@
 	}
 	
 	public function createLayerFromDb ($id, $appId = null) {
-		try {
-			$wmsId = intval(wms::getWmsIdByLayerId($id));
-			$version = $this->getVersionByWmsId($wmsId);
-			if (!is_null($version)) {
+		$wmsId = intval(wms::getWmsIdByLayerId($id));
+		$version = $this->getVersionByWmsId($wmsId);
+		if (!is_null($version)) {
 
-				$factory = $this->getFactory($version);
-				if (!is_null($factory)) {
-					if (!is_null($appId)) {
-						return $factory->createLayerFromDb($id, $wmsId, $appId);
-					}
-					return $factory->createLayerFromDb($id, $wmsId);
+			$factory = $this->getFactory($version);
+			if (!is_null($factory)) {
+				if (!is_null($appId)) {
+					return $factory->createLayerFromDb($id, $wmsId, $appId);
 				}
-				return null;
+				return $factory->createLayerFromDb($id, $wmsId);
 			}
-		}
-		catch (Exception $e) {
-			new mb_exception($e);
 			return null;
 		}
 	}

Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2010-10-04 14:08:49 UTC (rev 7018)
+++ trunk/mapbender/http/classes/class_wmc.php	2010-10-04 14:23:01 UTC (rev 7019)
@@ -897,6 +897,10 @@
 		}
 	}
 
+	public function extentToJavaScript() {
+		return $this->mainMap->extentToJavaScript();
+	}
+
 	public function wmsToJavaScript() {
 		$wmsArray = $this->mainMap->getWmsArray();
 

Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php	2010-10-04 14:08:49 UTC (rev 7018)
+++ trunk/mapbender/http/classes/class_wms.php	2010-10-04 14:23:01 UTC (rev 7019)
@@ -228,7 +228,7 @@
 					return $this->objLayer[$i];
 				}
 				else {
-					throw new Exception ("Access to layer denied.");
+					throw new AccessDeniedException ($id);
 				}
 			}
 		}
@@ -2872,4 +2872,15 @@
 		return $parents;
 	}
 }
+
+class AccessDeniedException extends Exception {
+	public function errorMessage() {
+		//error message
+		$errorMsg = 'Error on line ' . $this->getLine() . ' in ' .
+			$this->getFile() .
+			': You are not allowed to access layer with ID: ' .
+			$this->getMessage();
+		return $errorMsg;
+	}
+}
 ?>
\ No newline at end of file

Modified: trunk/mapbender/http/javascripts/initWmcObj.php
===================================================================
--- trunk/mapbender/http/javascripts/initWmcObj.php	2010-10-04 14:08:49 UTC (rev 7018)
+++ trunk/mapbender/http/javascripts/initWmcObj.php	2010-10-04 14:23:01 UTC (rev 7019)
@@ -18,6 +18,39 @@
 	return $_GET[$key];
 }
 
+$admin = new administration();
+
+$resultObj = array(
+	"noPermission" => array(
+		"message" => "Sie als Nutzer '" .
+			Mapbender::session()->get("mb_user_name") . "' " .
+			"haben keine Berechtigung auf folgende Layer zuzugreifen.",
+		"wms" => array()
+	),
+	"withoutId" => array(
+		"message" => "Folgende Layer stammen aus einer dem " .
+			"Geoportal.rlp unbekannten Quelle. Es kann daher nicht " .
+			"überprüft werden, ob die Links verwaist sind oder ob " .
+			"die Dienste überhaupt Daten liefern.",
+		"wms" => array(),
+	),
+	"unavailable" => array(
+		"message" => "Bei folgenden Diensten kam es während " .
+			"des letzten Monitorings zu Problemen. Es ist möglich, dass " .
+			"diese Dienste derzeit keine Informationen zur Verfügung stellen " .
+			"können.",
+		"wms" => array()
+	),
+	"invalidId" => array(
+		"message" => "Folgende Dienste/Layer sind aus der " .
+			"Registrierungsstelle gelöscht worden. Es kann daher nicht " .
+			"überprüft werden, ob die Links verwaist sind oder ob " .
+			"die Dienste überhaupt Daten liefern.",
+		"wms" => array()
+	)
+);
+
+
 //
 // Load WMC from session or application
 //
@@ -206,42 +239,54 @@
 	foreach ($inputLayerArray as $input) {
 	// just make it work for a single layer id
 		$wmsFactory = new UniversalWmsFactory();
-		if (isset($input["application"])) {
-			$wms = $wmsFactory->createLayerFromDb(
-				$input["id"], $input["application"]
+		try {
+			if (isset($input["application"])) {
+				$wms = $wmsFactory->createLayerFromDb(
+					$input["id"], $input["application"]
+				);
+			}
+			else {
+				$wms = $wmsFactory->createLayerFromDb($input["id"]);
+			}
+		}
+		catch (AccessDeniedException $e) {
+			$resultObj["noPermission"]["wms"][] = array(
+				"title" => $admin->getLayerTitleByLayerId($input["id"]),
+				"id" => $input["id"]
 			);
 		}
-		else {
-			$wms = $wmsFactory->createLayerFromDb($input["id"]);
-		}
-		$options = array();
-		if ($input["visible"]) {
-		// this is a hack for the time being:
-		// make WMS visible if it has less than 100000 layers
-			$options["show"] = 100000;
-		}
-		if (isset($input["querylayer"])) {
-			$options["querylayer"] = $input["querylayer"];
-		}
-		$wmcGetApi->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]
-					);
+		if (is_a($wms, "wms")) {
+			$options = array();
+			if ($input["visible"]) {
+			// this is a hack for the time being:
+			// make WMS visible if it has less than 100000 layers
+				$options["show"] = 100000;
+			}
+			if (isset($input["querylayer"])) {
+				$options["querylayer"] = $input["querylayer"];
+			}
+			$wmcGetApi->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]
+						);
+					}
+					$wmcGetApi->mainMap->mergeExtent($bboxArray);
 				}
-				$wmcGetApi->mainMap->mergeExtent($bboxArray);
+				catch (Exception $e) {
+
+				}
 			}
-			catch (Exception $e) {
 
-			}
 		}
 	}
 }
@@ -281,8 +326,6 @@
 //
 // CONSTRAINTS
 //
-$resultObj = array();
-
 $currentUser = new User();
 
 // remove all WMS with no permission
@@ -297,11 +340,9 @@
 	);
 	$deniedIdsIndices[]= $i["index"];
 }
-$resultObj["noPermission"] = array(
-	"message" => "Sie als Nutzer '" .
-	Mapbender::session()->get("mb_user_name") . "' " .
-	"haben keine Berechtigung auf folgende Layer zuzugreifen.",
-	"wms" => $deniedIdsTitles
+$resultObj["noPermission"]["wms"] = array_merge(
+	$resultObj["noPermission"]["wms"],
+	$deniedIdsTitles
 );
 $wmcGetApi->removeWms($deniedIdsIndices);
 
@@ -315,12 +356,9 @@
 		"title" => $i["title"]
 	);
 }
-$resultObj["withoutId"] = array(
-	"message" => "Folgende Layer stammen aus einer dem " .
-	"Geoportal.rlp unbekannten Quelle. Es kann daher nicht " .
-	"überprüft werden, ob die Links verwaist sind oder ob " .
-	"die Dienste überhaupt Daten liefern.",
-	"wms" => $withoutIdsTitles
+$resultObj["withoutId"]["wms"] = array_merge(
+	$resultObj["withoutId"]["wms"],
+	$withoutIdsTitles
 );
 
 // find orphaned WMS
@@ -333,12 +371,9 @@
 		"title" => $i["title"]
 	);
 }
-$resultObj["invalidId"] = array(
-	"message" => "Folgende Dienste/Layer sind aus der " .
-	"Registrierungsstelle gelöscht worden. Es kann daher nicht " .
-	"überprüft werden, ob die Links verwaist sind oder ob " .
-	"die Dienste überhaupt Daten liefern.",
-	"wms" => $invalidIdsTitles
+$resultObj["invalidId"]["wms"] = array_merge(
+	$resultObj["invalidId"]["wms"],
+	$invalidIdsTitles
 );
 
 // find potentially unavailable WMS
@@ -351,12 +386,9 @@
 		"title" => $i["title"]
 	);
 }
-$resultObj["unavailable"] = array(
-	"message" => "Bei folgenden Diensten kam es während " .
-	"des letzten Monitorings zu Problemen. Es ist möglich, dass " .
-	"diese Dienste derzeit keine Informationen zur Verfügung stellen " .
-	"können.",
-	"wms" => $unavailableIdsTitles
+$resultObj["unavailable"]["wms"] = array_merge(
+	$resultObj["unavailable"]["wms"],
+	$unavailableIdsTitles
 );
 
 //
@@ -370,7 +402,6 @@
 $row = db_fetch_assoc($res);
 $isSessionWmcModuleLoaded = intval($row["i"]);
 
-Mapbender::session()->set("wmcGetApi", $wmcGetApi);
 if (
 	count($resultObj["withoutId"]["wms"]) === 0 &&
 	count($resultObj["invalidId"]["wms"]) === 0 &&
@@ -380,10 +411,18 @@
 	Mapbender::session()->set("wmcConstraints", $resultObj);
 	$output = $wmcGetApi->wmsToJavaScript();
 
+	$extentJs = $wmcGetApi->extentToJavaScript();
+	$output[] = <<<JS
+		Mapbender.events.beforeInit.register(function () {
+			$extentJs
+		});
+JS;
+	Mapbender::session()->delete("wmcGetApi", $wmcGetApi);
 }
 else {
 	Mapbender::session()->set("wmcConstraints", $resultObj);
 	$output = $wmc->wmsToJavaScript();
+	Mapbender::session()->set("wmcGetApi", $wmcGetApi);
 }
 
 
@@ -413,13 +452,6 @@
 
 echo $outputString;
 
-
-//workaround for zoom to WMS
-//$extent = $wmc->mainMap->getExtent();
-//Mapbender::session()->set("mb_myBBOX", $extent->min->x . "," .
-//	$extent->min->y . "," . $extent->max->x . "," . $extent->max->y);
-
-
 Mapbender::session()->delete("addwms_showWMS");
 Mapbender::session()->delete("addwms_zoomToExtent");
 unset($output);

Modified: trunk/mapbender/http/plugins/mb_sessionWmc.js
===================================================================
--- trunk/mapbender/http/plugins/mb_sessionWmc.js	2010-10-04 14:08:49 UTC (rev 7018)
+++ trunk/mapbender/http/plugins/mb_sessionWmc.js	2010-10-04 14:23:01 UTC (rev 7019)
@@ -35,7 +35,6 @@
 
 	var closeDialog = function () {
 		if ($dialog === undefined || !$dialog.jquery) {
-			console.log($dialog);
 			return;
 		}
 		$dialog.dialog('close').remove();
@@ -71,8 +70,10 @@
 					return;
 				}
 				// execute JS code
-				for (var j = 0; j < obj.js.length; j++) {
-					eval(obj.js[j]);
+				if (obj.js) {
+					for (var j = 0; j < obj.js.length; j++) {
+						eval(obj.js[j]);
+					}
 				}
 				
 				closeDialog();



More information about the Mapbender_commits mailing list