[Mapbender-commits] r8555 - in trunk/mapbender: http/javascripts lib

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Feb 5 23:54:52 PST 2013


Author: armin11
Date: 2013-02-05 23:54:52 -0800 (Tue, 05 Feb 2013)
New Revision: 8555

Modified:
   trunk/mapbender/http/javascripts/initWmcObj.php
   trunk/mapbender/lib/class_GetApi.php
Log:
Allow starting mapbender gui with initial extent given thru get-parameter - see http://www.mapbender.org/GET-Parameter#ZOOM - first 2 entries

Modified: trunk/mapbender/http/javascripts/initWmcObj.php
===================================================================
--- trunk/mapbender/http/javascripts/initWmcObj.php	2013-01-29 19:57:28 UTC (rev 8554)
+++ trunk/mapbender/http/javascripts/initWmcObj.php	2013-02-06 07:54:52 UTC (rev 8555)
@@ -22,8 +22,18 @@
 	return $_GET[$key];
 }
 
+//for debugging purposes only
+function logit($text,$filename,$how){
+	 if($h = fopen(LOG_DIR."/".$filename,$how)){
+				$content = $text .chr(13).chr(10);
+				if(!fwrite($h,$content)){
+					#exit;
+				}
+				fclose($h);
+			}	 	
+}
+
 $admin = new administration();
-
 $resultObj = array(
 	"noPermission" => array(
 		"message" => _mb("You as User")." '" .
@@ -47,24 +57,18 @@
 		"message" => ""
 	)
 );
-
-
 //
 // Load WMC from session or application
 //
-
 $wmc = new wmc();
-
 $app = Mapbender::session()->get("mb_user_gui");
 //$wmcDocSession = Mapbender::session()->get("mb_wmc");
-
 $wmcDocSession = false;
+//check if wmc filename is in session - TODO only if should be loaded from session not else! (Module loadWMC)
 if(Mapbender::session()->get("mb_wmc")) {
     $wmc_filename = Mapbender::session()->get("mb_wmc");
     $wmcDocSession = file_get_contents($wmc_filename);
 }
-
-
 try {
 	$loadFromSession = new ElementVar($app, "loadwmc", "loadFromSession");
 	if ($wmcDocSession && $loadFromSession->value === "1") {
@@ -72,27 +76,28 @@
 	//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.");
-			$e = new mb_notice("creating wmc from app: " . $app);
+			$e = new mb_exception("loading session WMC failed.");
+			$e = new mb_notice("creating wmc from app: ".$app);
 			$wmc->createFromApplication($app);
 		}
 	}
 	else {
 		$e = new mb_notice("loading from session WMC disabled in loadwmc or no session WMC set.");
-		$e = new mb_notice("creating wmc from app: " . $app);
+		$e = new mb_notice("creating wmc from app: ".$app);
+		$e = new mb_notice("initWmcObj.php: before load from app");
 		$wmc->createFromApplication($app);
+		$e = new mb_notice("initWmcObj.php: after load from app");
 	}
 }
 catch (Exception $e) {
 	$e = new mb_notice("creating wmc from app: " . $app);
 	$wmc->createFromApplication($app);
 }
-
+//TODO: if no GET API is given then don't do the following things
 //
 // create new WMC with services from GET API
 //
 $wmcGetApi = WmcFactory::createFromXml($wmc->toXml());
-
 $options = array();
 if (Mapbender::session()->exists("addwms_showWMS")) {
 	$options["show"] = intval(Mapbender::session()->get("addwms_showWMS"));
@@ -100,22 +105,22 @@
 if (Mapbender::session()->exists("addwms_zoomToExtent")) {
 	$options["zoom"] = !!Mapbender::session()->get("addwms_zoomToExtent");
 }
-
 $getParams = array(
 	"WMC" => getConfiguration("WMC"),
 	"WMS" => getConfiguration("WMS"),
 	"LAYER" => getConfiguration("LAYER"),
 	"FEATURETYPE" => getConfiguration("FEATURETYPE"),
-	"GEORSS"=>getConfiguration("GEORSS")
+	"GEORSS"=>getConfiguration("GEORSS"),
+	"ZOOM"=>getConfiguration("ZOOM")
 );
 $getApi = new GetApi($getParams);
-
 //
 // WMC
 //
+$e = new mb_notice("initWmcObj.php: check WMC API");
 $inputWmcArray = $getApi->getWmc();
-
 if ($inputWmcArray) {
+	$e = new mb_notice("initWmcObj.php: some WMC id was set thru Get Api!");
 	foreach ($inputWmcArray as $input) {
 	// just make it work for a single Wmc
 		try {
@@ -131,10 +136,10 @@
 		}
 	}
 }
-
 //
 // WMS
 //
+$e = new mb_notice("initWmcObj.php: check WMS API");
 if ($getParams['WMS']) {
 // WMS param given as array
 	if (is_array($getParams['WMS'])) {
@@ -144,11 +149,9 @@
 	else {
 		$inputWmsArray = split(",",$getParams['WMS']);
 	}
-
 	$wmsArray = array();
 	$singleAssocArray = array();
 	$multipleAssocArray = array();
-
 	foreach ($inputWmsArray as $key=>$val) {
 		if (is_array($val)) {
 			foreach ($val as $attr=>$value) {
@@ -203,7 +206,6 @@
 			}
 		}
 	}
-
 	//get WMS by ID with settings of given application
 	if (array_key_exists('application', $singleAssocArray) &&
 		array_key_exists('id', $singleAssocArray)) {
@@ -240,11 +242,10 @@
 		$singleAssocArray = array();
 	}
 }
-
 //
 // LAYER
 //
-
+$e = new mb_notice("initWmcObj.php: check LAYER API");
 $inputLayerArray = $getApi->getLayers();
 if ($inputLayerArray) {
 	foreach ($inputLayerArray as $input) {
@@ -271,8 +272,8 @@
 			$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;
+			// make WMS visible if it has less than 10000 layers
+				$options["show"] = 10000;
 			}
 			if (isset($input["querylayer"])) {
 				$options["querylayer"] = $input["querylayer"];
@@ -301,10 +302,10 @@
 		}
 	}
 }
-
 //
 // FEATURETYPE
 //
+$e = new mb_notice("initWmcObj.php: check FEATURETYPE API");
 $inputFeaturetypeArray = $getApi->getFeaturetypes();
 if ($inputFeaturetypeArray) {
 	$wfsConfIds = array();
@@ -319,28 +320,31 @@
 		$wfsConfIds
 	)));
 }
-
+//
+//GEORSS
+//
 $inputGeoRSSArray = $getApi->getGeoRSSFeeds();
+$e = new mb_notice("initWmcObj.php: check GEORSS API");
 if($inputGeoRSSArray){
 	$wmc->generalExtensionArray['GEORSS'] = $inputGeoRSSArray; 
 }
-
+//TODO test following
 //workaround to have a fully merged WMC for loading
-
+$e = new mb_notice("initWmcObj.php: export to xml");
 $xml = $wmcGetApi->toXml();
 
 $wmcGetApi = new wmc();
 //new Object with merged layers and other features
+$e = new mb_notice("initWmcObj.php: import from xml");
 $wmcGetApi->createFromXml($xml);
-
-
-
+$e = new mb_notice("initWmcObj.php: import done!");
 //
 // CONSTRAINTS
 //
 $currentUser = new User();
 
 // remove all WMS with no permission
+$e = new mb_notice("initWmcObj.php: get wms without permission");
 $deniedIdsArray = $wmcGetApi->getWmsWithoutPermission($currentUser);
 $deniedIdsTitles = array();
 $deniedIdsIndices = array();
@@ -356,9 +360,11 @@
 	$resultObj["noPermission"]["wms"],
 	$deniedIdsTitles
 );
+$e = new mb_notice("initWmcObj.php: list of wms without permission created");
 $wmcGetApi->removeWms($deniedIdsIndices);
-
+$e = new mb_notice("initWmcObj.php: wms without permission removed from wmc");
 // find WMS without ID
+$e = new mb_notice("initWmcObj.php: find wms without id");
 $withoutIdsArray = $wmcGetApi->getWmsWithoutId();
 $withoutIdsTitles = array();
 foreach ($withoutIdsArray as $i) {
@@ -372,8 +378,9 @@
 	$resultObj["withoutId"]["wms"],
 	$withoutIdsTitles
 );
-
+$e = new mb_notice("initWmcObj.php: wms without id list generated");
 // find orphaned WMS
+$e = new mb_notice("initWmcObj.php: find invalid wms");
 $invalidIdsArray = $wmcGetApi->getInvalidWms();
 $invalidIdsTitles = array();
 foreach ($invalidIdsArray as $i) {
@@ -387,8 +394,9 @@
 	$resultObj["invalidId"]["wms"],
 	$invalidIdsTitles
 );
-
+$e = new mb_notice("initWmcObj.php: invalid wms list generated");
 // find potentially unavailable WMS
+$e = new mb_notice("initWmcObj.php: find problematic wms");
 $unavailableIdsArray = $wmcGetApi->getUnavailableWms($currentUser);
 $unavailableIdsTitles = array();
 foreach ($unavailableIdsArray as $i) {
@@ -402,9 +410,9 @@
 	$resultObj["unavailable"]["wms"],
 	$unavailableIdsTitles
 );
-
+$e = new mb_notice("initWmcObj.php: problematic wms list generated");
 //get terms of use from wms objects which are in the remaining wmc and are not already accepted for this session
-
+$e = new mb_notice("initWmcObj.php: collect known tou");
 $validWMS = $wmcGetApi->getValidWms();
 $translation['wms'] = _mb("MapService");
 $resourceSymbol = "<img src='../img/osgeo_graphics/geosilk/server_map.png' alt='".$translation['wms']." - picture' title='".$translation['wms']."'>";
@@ -435,31 +443,31 @@
 			$tou .= $touHeader.$touForWMS;
 		}
 		//set the tou to be accepted - TODO maybe do this after the button which deletes the message window - from a ajax request.
-
 		$classTou->set('wms',$WMS['id']);
 	} 
 }
-	
 if ($tou != "") {
 	$tou = _mb("The configuration, which should be loaded, consists of different services which have the following terms of use:")."<br>".$tou;
 }
 $resultObj["wmcTou"]["message"] = $tou;
-
-
-#$resultObj["wmcTou"]["message"] = "Terms of Use";
-
+$e = new mb_notice("initWmcObj.php: collect known tou done!");
 //
 // Output
 //
-// Check if session WMC module is loaded
+// Check if session WMC module is loaded - TODO maybe do this before the other things are done!!!
+$e = new mb_notice("initWmcObj.php: check if disclaimer should be set");
 $sql = "SELECT COUNT(e_id) AS i FROM gui_element WHERE fkey_gui_id = $1 AND e_id = $2";
 $v = array(Mapbender::session()->get("mb_user_gui"), "sessionWmc");
 $t = array("s", "s");
 $res = db_prep_query($sql, $v, $t);
 $row = db_fetch_assoc($res);
 $isSessionWmcModuleLoaded = intval($row["i"]);
-
+$e = new mb_notice("initWmcObj.php: check for disclaimer done");
+//
+//GML in session
+//
 // check if Session contains a GML, and then zoom to it
+$e = new mb_notice("initWmcObj.php: check session for GML to zoom");
 $gml_string = Mapbender::session()->get("GML");
 if($gml_string){
 	$gml = new gml2();
@@ -472,17 +480,63 @@
 	$epsg = "EPSG:".$gml->epsg);
 	$wmcGetApi->mainMap->setExtent($bbox);
 }
+$e = new mb_notice("initWmcObj.php: session GML zoom done");
+//overwrite extent of wmc with information from GetApi if given
+$e = new mb_notice("initWmcObj.php: check ZOOM API");
+$zoom = $getApi->getZoom();
+if (count($zoom) == 4 || count($zoom) == 5) {
+	$e = new mb_notice("initWmcObject.php: found EXTENT");
+	if (count($zoom) == 5){
+		$bbox = new Mapbender_bbox(
+			$zoom[0],
+			$zoom[1],
+			$zoom[2],
+			$zoom[3],	
+			$epsg = $zoom[4]);
+	} else {
+		//get current epsg from wmc bounding box
+		//ViewContext->General->BoundingBox->SRS
+		//$e = new mb_notice("initWmcObject.php: SRS found in current WMC: ".$wmcGetApi->mainMap->getEpsg());
+		$bbox = new Mapbender_bbox(
+			$zoom[0],
+			$zoom[1],
+			$zoom[2],
+			$zoom[3],	
+			$epsg = $wmcGetApi->mainMap->getEpsg());
+	}
+	$wmcGetApi->mainMap->setExtent($bbox);
+}
+//check if something have to be shown in disclaimer
 if (
 	count($resultObj["withoutId"]["wms"]) === 0 &&
 	count($resultObj["invalidId"]["wms"]) === 0 &&
 	count($resultObj["unavailable"]["wms"]) === 0 ||
 	!$isSessionWmcModuleLoaded
 ) {
-	
+	$e = new mb_notice("initWmcObj.php: build js!");
+	//put them into the session to pull them later on
 	Mapbender::session()->set("wmcConstraints", $resultObj);
+//*******************************************************
+	//Alternate approach: create map object from xml:
+	//$e = new mb_notice("initWmcObj.php: build alternate js!");
+	//$alternateWMC = new wmc();
+	//$alternateWMC->createFromXml($wmcGetApi->xml);
+	//$jsarray = $alternateWMC->toJavaScript();
+	//foreach($jsarray as $key => $value){
+	//	logit($value,"javascript_new.store","a+");
+	//}
+	//save to some position
+	//$e = new mb_notice("initWmcObj.php: alternate js:".$alternateWMC->toJavaScript());
+	//$e = new mb_notice("initWmcObj.php: alternate js build successfully!");
+//*******************************************************
+	//$e = new mb_notice("initWmcObj.php: wmc to js!");
 	$output = $wmcGetApi->wmsToJavaScript();
+	//output without wms
+	//$output = "";
+	$e = new mb_notice("initWmcObj.php: WMC to js with empty array!");
 	$wmcJs = $wmcGetApi->toJavaScript(array());
 	$wmcJs = implode(";\n",$wmcJs);
+	$e = new mb_notice("initWmcObj.php: extent to js!");
 	$extentJs = $wmcGetApi->extentToJavaScript();
 	$output[] = <<<JS
 		Mapbender.events.afterInit.register(function () {
@@ -493,12 +547,17 @@
 		});
 JS;
 	Mapbender::session()->delete("wmcGetApi", $wmcGetApi);
+	$e = new mb_notice("initWmcObj.php: js have been build!");
 }
 else {
+	$e = new mb_notice("initWmcObj.php: build js!");
 	Mapbender::session()->set("wmcConstraints", $resultObj);
+	$e = new mb_notice("initWmcObj.php: wms to js!");
 	$output = $wmc->wmsToJavaScript();
+	$e = new mb_notice("initWmcObj.php: WMC to js with empty array!");
 	$wmcJs = $wmc->toJavaScript(array());
 	$wmcJs = implode(";\n",$wmcJs);
+	$e = new mb_notice("initWmcObj.php: extent to js!");
 	$extentJs = $wmc->extentToJavaScript();
 	$output[] = <<<JS
 		Mapbender.events.afterInit.register(function () {
@@ -509,9 +568,10 @@
 		});
 JS;
 	Mapbender::session()->set("wmcGetApi", $wmcGetApi);
+	$e = new mb_notice("initWmcObj.php: js have been build!");
 }
 
-
+$e = new mb_notice("initWmcObj.php: build output string!");
 $outputString = "";
 for ($i = 0; $i < count($output); $i++) {
 	$outputString .= administration::convertOutgoingString($output[$i]);
@@ -539,11 +599,12 @@
 
 $outputString .= $GeoRSSStr;
 
-
+$e = new mb_notice("initWmcObj.php: output string ready!");
 echo $outputString;
-
+//logit($outputString,"javascript_old.store","w");
 Mapbender::session()->delete("addwms_showWMS");
 Mapbender::session()->delete("addwms_zoomToExtent");
 unset($output);
 unset($wmc);
+$e = new mb_notice("initWmcObj.php: done all!");
 ?>

Modified: trunk/mapbender/lib/class_GetApi.php
===================================================================
--- trunk/mapbender/lib/class_GetApi.php	2013-01-29 19:57:28 UTC (rev 8554)
+++ trunk/mapbender/lib/class_GetApi.php	2013-02-06 07:54:52 UTC (rev 8555)
@@ -15,6 +15,7 @@
 	private $featuretypes = array();
 	private $geoRSSFeeds = array();
 	private $wmc = array();
+	private $zoom = array();
 	
 	/**
 	 * @param array $input
@@ -37,6 +38,9 @@
 				case "GEORSS":
 					$this->geoRSSFeeds = $this->normalizeGeoRSSInput($value);
 					break;
+				case "ZOOM":
+					$this->zoom = $this->normalizeZoomInput($value);
+					break;
 			}
 		}
 	}
@@ -67,6 +71,14 @@
 	}
 
 	/**
+	 * Returns an array of zoom parameters
+	 * @return array
+	 */
+	public function getZoom () {
+		return $this->zoom;
+	}
+
+	/**
 	 * Returns an array of wmc
 	 * @return array
 	 */
@@ -210,6 +222,57 @@
 		return $input;
 	}
 
+	private function normalizeZoomInput($input){
+		$inputArray = explode(",", $input);
+		$input = array();
+		switch (count($inputArray)) {
+			case 4:
+				//read out coordinates - have to be numeric values
+				$i = 0;
+				foreach ($inputArray as $id) {
+					if (is_numeric($id)) {
+						$input[$i++]["id"] = $id;
+					} else {
+						$e = new mb_exception("lib/class_GetApi.php: found non numeric value in zoom parameter: at pos ".$i." : ".$id);
+						return false;	
+					}
+				}
+				return $input;
+			break;
+			case 5:
+				//read out coordinates and epsg
+				for ($i=0; $i < 4; $i++) {
+					if (is_numeric($inputArray[$i])) {
+						//do nothing
+					} else {
+						$e = new mb_exception("lib/class_GetApi.php: found non numeric value in zoom parameter: at pos ".$i." : ".$inputArray[$i]);
+						return false;	
+					}
+				}
+				//check 5th value
+				//check for EPSG:XXXXX
+				$pattern = '/^EPSG:\d{1,6}$/';		
+ 				if (!preg_match($pattern,$inputArray[4])){ 
+					$e = new mb_exception("lib/class_GetApi.php: found not allowed value for epsg code for zoom parameter: ".$inputArray[4]);
+					return false;	
+ 				}
+				return $inputArray;
+			break;
+			default:
+				//count doesn't match
+				return false;
+			break;
+		}
+		/*$i = 0;
+		foreach ($inputArray as $id) {
+			if (is_numeric($id)) {
+				$input[$i++]["id"] = $id;
+			}
+		}*/
+
+		//return is_array($input) ? $input : array($input);
+	}
+
 	private function normalizeGeoRSSInput($input){
 		return is_array($input) ? $input : array($input);
 	}



More information about the Mapbender_commits mailing list