[Mapbender-commits] r6707 - trunk/mapbender/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Aug 6 04:57:35 EDT 2010


Author: christoph
Date: 2010-08-06 08:57:35 +0000 (Fri, 06 Aug 2010)
New Revision: 6707

Modified:
   trunk/mapbender/http/javascripts/initWmcObj.php
Log:
normalized layer inputs in order to accept these: http://www.mapbender.org/GET-Parameter#LAYER

Modified: trunk/mapbender/http/javascripts/initWmcObj.php
===================================================================
--- trunk/mapbender/http/javascripts/initWmcObj.php	2010-08-06 08:56:28 UTC (rev 6706)
+++ trunk/mapbender/http/javascripts/initWmcObj.php	2010-08-06 08:57:35 UTC (rev 6707)
@@ -103,23 +103,80 @@
 
 $getParams["LAYER"] = getConfiguration("LAYER");
 
-if ($getParams["LAYER"]) {
-	// Layer param given as array
-	if (is_array($getParams['LAYER'])) {
-		$inputLayerArray = $getParams['LAYER'];
+// for possible inputs see http://www.mapbender.org/GET-Parameter#LAYER
+// for test cases, see http://www.mapbender.org/Talk:GET-Parameter#LAYER
+function normalizeLayerInput ($input) {
+	if (is_array($input)) {
+		$keys = array_keys($input);
+		$isSingleLayer = false;
+		foreach ($keys as $key) {
+			if (!is_numeric($key)) {
+				$isSingleLayer = true;
+				break;
+			}
+		}
+		// LAYER[id]=12&LAYER[application]=something
+		if ($isSingleLayer) {
+			$input[0] = array();
+			foreach ($keys as $key) {
+				if (!is_numeric($key)) {
+					$input[0][$key] = $input[$key];
+					unset($input[$key]);
+				}
+			}
+		}
+		else {
+			for ($i = 0; $i < count($input); $i++) {
+				// assume LAYER[]=12&LAYER[]=13
+				if (is_numeric($input[$i])) {
+					$id = $input[$i];
+					$input[$i] = array("id" => $id);
+				}
+				// else assume LAYER[0][id]=12&LAYER[0][application]=something
+			}
+		}
 	}
-	// Layer param given as comma separated list
 	else {
-		$inputLayerArray = split(",",$getParams['LAYER']); 
+		// assume LAYER=12,13,14
+		$inputArray = split(",", $input); 
+		$input = array();
+		$i = 0;
+		foreach ($inputArray as $id) {
+			if (is_numeric($id)) {
+				$input[$i++]["id"] = $id;
+			}
+		}
 	}
-	
-	// just make it work for a single layer id
-	$wmsFactory = new UniversalWmsFactory();
-	$layerId = intval($getParams["LAYER"]);
-	$wms = $wmsFactory->createLayerFromDb($layerId);
-	$wmc->mergeWmsArray(array($wms));
+	// check if each layer has at least an id, if not, delete
+	$i = 0;
+	while ($i < count($input)) {
+		if (!is_array($input[$i]) || !isset($input[$i]["id"]) || !is_numeric($input[$i]["id"])) {
+			array_splice($input, $i, 1);
+			continue;
+		}
+		$input[$i]["id"] = intval($input[$i]["id"]);
+		$i++;
+	}
+	return $input;
 }
 
+if ($getParams["LAYER"]) {
+	$inputLayerArray = normalizeLayerInput($getParams['LAYER']);
+
+	foreach ($inputLayerArray as $input) {
+		// just make it work for a single layer id
+		$wmsFactory = new UniversalWmsFactory();
+		$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;
+		}
+		$wmc->mergeWmsArray(array($wms), $options);
+	}
+}
+
 $output = $wmc->wmsToJavaScript();
 
 for ($i = 0; $i < count($output); $i++) {



More information about the Mapbender_commits mailing list