[Mapbender-commits] r2461 - in branches/beck_dev/mapbender/http: classes javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri May 16 11:00:10 EDT 2008


Author: christoph
Date: 2008-05-16 11:00:10 -0400 (Fri, 16 May 2008)
New Revision: 2461

Modified:
   branches/beck_dev/mapbender/http/classes/class_map.php
   branches/beck_dev/mapbender/http/classes/class_wmc.php
   branches/beck_dev/mapbender/http/classes/class_wms.php
   branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.js
Log:
supporting nested WMS
merge and equals function for WMS


Modified: branches/beck_dev/mapbender/http/classes/class_map.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_map.php	2008-05-16 10:00:51 UTC (rev 2460)
+++ branches/beck_dev/mapbender/http/classes/class_map.php	2008-05-16 15:00:10 UTC (rev 2461)
@@ -11,7 +11,6 @@
 	var $frameName;
 	var $elementName = "maps";
 	var $extent;
-	var $overviewLayerIndex;
 	
 	/**
 	 * @constructor
@@ -83,16 +82,25 @@
 	 * Returns an array of string, which are JS statements.
 	 * @return String[]
 	 */
-	public function createJsObj () {
+	public function createJsObj ($wmsIndex) {
 		$jsCodeArray = array();
 		$registerMapString = "mb_registerMapObj('" . 
 			$this->frameName . "', " . 
 			"'maps', " . 
-			(isset($this->overviewLayerIndex)?$this->overviewLayerIndex:"null") . ", " . 
+			(($wmsIndex !== null)?$wmsIndex:"null") . ", " . 
 			$this->width . ", " . 
 			$this->height . ");"; 
 		array_push($jsCodeArray, $registerMapString);
 
+		$setMapframeWidth = "document.getElementById('" . $this->frameName . "')." . 
+			"style.width = " . $this->width . ";";
+		array_push($jsCodeArray, $setMapframeWidth);
+
+		$setMapframeHeight = "document.getElementById('" . $this->frameName . "')." . 
+			"style.height = " . $this->height . ";";
+		array_push($jsCodeArray, $setMapframeHeight);
+
+
 		$calcExtentString = "mb_calculateExtent('" . 
 			$this->frameName . "', " .
 			$this->extent->min->x . ", " . 

Modified: branches/beck_dev/mapbender/http/classes/class_wmc.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_wmc.php	2008-05-16 10:00:51 UTC (rev 2460)
+++ branches/beck_dev/mapbender/http/classes/class_wmc.php	2008-05-16 15:00:10 UTC (rev 2461)
@@ -35,6 +35,7 @@
 	var $mainMap;
 	var $overviewMap;
 	var $wmsArray = array();
+	var $overviewWmsIndex = null;
 	var $generalExtensionArray = array();
 	
 	var $monitoringIsOn = false;
@@ -79,21 +80,19 @@
 	 * @return	boolean		Did the query run successful?
 	 */
 	public function delete ($wmcId, $userId) {
-		if (!isset($userId) || $userId == null) {
+		if (!isset($userId) || $userId === null) {
 			$userId = $_SESSION["mb_user_id"];
 		}
 		
 		$sql = "DELETE FROM mb_user_wmc ";
 		$sql .= "WHERE fkey_user_id = $1 AND wmc_id = $2";
 		$v = array($userId, $wmcId);
-		$t = array('i','s');
-		$res = db_prep_query($sql,$v,$t);
+		$t = array('i', 's');
+		$res = db_prep_query($sql, $v, $t);
 		if ($res) {
 			return true;
 		}
-		else {
-			return false;
-		}
+		return false;
 	}
 	
 	/**
@@ -102,7 +101,7 @@
 	 * @param $id String the WMC id
 	 */
 	public function getDocument ($id) {
-		$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1 ";
+		$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1";
 		$v = array($id);
 		$t = array('s');
 		$res = db_prep_query($sql,$v,$t);
@@ -110,11 +109,16 @@
 		if ($row) {
 			return $row["wmc"];
 		}
-		else {
-			return false;
-		}
+		return false;
 	}
 
+	public static function merge ($xml1, $xml2) {
+		$mergedWmc = new wmc();
+		$mergedWmc->createWmcFromXml($xml1);
+		$this->wmsArray = wms::merge($this->wmsArray, $someWmc->wmsArray);
+		return $mergedWmc->load();
+	}
+
 	/**
 	 * @return string the title of the WMC.
 	 */
@@ -134,6 +138,7 @@
 	public function createWmcFromJs($mapObject, $user_id, $generalTitle, $extensionData) {
 	
 		$extension_namespace = "mapbender";
+		$extension_namespace_url = "http://www.mapbender.org";
 		
 		// 
 		// STEP 1/2: GENERATE THE GENERAL TAG
@@ -201,12 +206,10 @@
 		
 		// ViewContext
 		$e_view_context = $doc->createElementNS("http://www.opengis.net/context", "ViewContext");
-		
-		
-		$e_view_context->setAttribute("version", "1.0.0");
+		$e_view_context->setAttribute("version", "1.1.0");
 		$e_view_context->setAttribute("id", $this->wmc_id);
 		$e_view_context->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-		$e_view_context->setAttribute("xmlns:mapbender", "http://www.mapbender.org");
+		$e_view_context->setAttribute("xmlns:" . $extension_namespace, $extension_namespace_url);
 		$e_view_context->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
 		$e_view_context->setAttribute("xsi:SchemaLocation", "http://schemas.opengis.net/context/1.0.0/context.xsd");
 		
@@ -644,6 +647,10 @@
 		$this->createObjFromWMC_xml($doc);
 	}
 	
+	public function createWmcFromXml ($xml) {
+		return $this->createObjFromWMC_xml($xml);
+	}
+	
 	/**
 	 * Loads a WMC from an actual WMC XML document.
 	 * Uses WMS class.
@@ -654,14 +661,8 @@
 		// store xml 
 		$this->xml = $data;
 	
-		// for debugging: saving WMC as file
-		// (comment when no longer needed)
-#		$filename = $this->saveAsFile();
-#		if ($filename) {
-#			$e = new mb_notice("class_wmc: saving WMC as file " . $filename);
-#		}
-	
 		$values = administration::parseXml($data);
+
 		//
 		// Local variables that indicate which section of the WMC
 		// is currently parsed.
@@ -677,6 +678,10 @@
 		$this->overviewMap = null;
 		$this->wmsArray = array();
 		$this->generalExtensionArray = array();
+		
+		$layerlistArray = array();
+		$layerlistArray["main"] = array();
+		$layerlistArray["overview"] = array();
 			 
 		foreach ($values as $element) {
 			$tag = strtoupper(administration::sepNameSpace($element[tag]));
@@ -811,7 +816,6 @@
 						$this->wmc_keyword[$cnt_keyword] = $value;
 					}
 				}
-						
 				if ($tag == "EXTENSION" && $type == "close") {
 					$generalExtension = false;
 					//
@@ -864,8 +868,12 @@
 						// we have all necessary information to CREATE
 						// a layer object and append it to the WMS object
 						//
-						$this->setLayerData($currentLayer);
-
+						if ($currentLayer["extension"]["ISOVERVIEWLAYER"] == "1") {
+							array_push($layerlistArray["overview"], $currentLayer);		
+						}
+						else {
+							array_push($layerlistArray["main"], $currentLayer);											
+						}
 				 		$layer = false;
 					}
 					if ($formatlist) {
@@ -1004,6 +1012,20 @@
 				}
 			}
 		}
+		
+		// set WMS data
+		
+		$layerlistCompleteArray = array_merge($layerlistArray["main"], $layerlistArray["overview"]);
+		
+		for ($i = 0; $i < count($layerlistCompleteArray); $i++) {
+			$this->setLayerData($layerlistCompleteArray[$i]);
+		}
+
+		$yetAnotherWmsArray = array_merge($this->wmsArray, $this->wmsArray);
+		$otherWmsArray = wms::merge($yetAnotherWmsArray);
+		$e = new mb_exception("old wms: " . implode(", ", $yetAnotherWmsArray)) ;
+		$e = new mb_exception("new wms: " . implode(", ", $otherWmsArray)) ;
+		
 		return true;
 	}
 
@@ -1021,59 +1043,41 @@
 		// will contain the JS code to create the maps
 		// representing the state stored in this WMC
 		$wmcJsArray = array();
-		array_push($wmcJsArray, "wms = [];");
-
-		// general extension
+		
+		// set general extension data
 		if (count($this->wmc_general_extension) > 0) {
 			$json = new Mapbender_JSON();
 			array_push($wmcJsArray, "restoredWmcExtensionData = " . $json->encode($this->generalExtensionArray) . ";"); 
 		}
 		
+		// reset WMS data
+		array_push($wmcJsArray, "wms = [];");
+
 		// for all wms...
 		for ($i = 0; $i < count($this->wmsArray); $i++) {
-			// add wms
-			array_push($wmcJsArray, $this->this->wmsArray[$i]->createJsObjFromWMS_());
+			// ..add wms and set properties
+			array_push($wmcJsArray, $this->wmsArray[$i]->createJsObjFromWMS_());
 		}
 
+		// delete existing map objects...
 		array_push($wmcJsArray, "mb_mapObj = [];");
-		$wmcJsArray = array_merge($wmcJsArray, $this->mainMap->createJsObj());
-		$wmcJsArray = array_merge($wmcJsArray, $this->overviewMap->createJsObj());
 
-/*
-		$ov_bbox = array();
+		// .. and add main map ..
+		$wmcJsArray = array_merge($wmcJsArray, $this->mainMap->createJsObj(null));
 
-		// box for mapframe
-		$mf_min = new Mapbender_point($this->wmc_bBox_minx, $this->wmc_bBox_miny, $this->wmc_bBox_SRS);
-		$mf_max = new Mapbender_point($this->wmc_bBox_maxx, $this->wmc_bBox_maxy, $this->wmc_bBox_SRS);
-		$mf_box = new Mapbender_bbox($mf_min, $mf_max, $this->wmc_bBox_SRS);
-
-		// compute the union of the overview and the mapframe bbox for the new overview bbox
-		if ($this->wmc_general_extension["ov_minx"] && $this->wmc_general_extension["ov_miny"] && 
-			$this->wmc_general_extension["ov_maxx"] && $this->wmc_general_extension["ov_maxy"]) {
-
-			// box for overview
-			$ov_min = new Mapbender_point($this->wmc_general_extension["ov_minx"], $this->wmc_general_extension["ov_miny"], $this->wmc_bBox_SRS);
-			$ov_max = new Mapbender_point($this->wmc_general_extension["ov_maxx"], $this->wmc_general_extension["ov_maxy"], $this->wmc_bBox_SRS);
-			$ov_box = new Mapbender_bbox($ov_min, $ov_max, $this->wmc_bBox_SRS);
-			
-			$unionBox = Mapbender_bbox::union(array($ov_box, $mf_box));
-			
+		// .. and the overview map (if exists)
+		if ($this->overviewWmsIndex !== null) {
+			$wmcJsArray = array_merge($wmcJsArray, $this->overviewMap->createJsObj($this->overviewWmsIndex));
 		}
-		else {
-			$unionBox = $mf_box;
-		}
-		array_push($ov_bbox, $unionBox->min->x); 				
-		array_push($ov_bbox, $unionBox->min->y); 				
-		array_push($ov_bbox, $unionBox->max->x); 				
-		array_push($ov_bbox, $unionBox->max->y); 				
-*/	
 
-		// Finally, request maps
+		// Finally, request the maps
 		array_push($wmcJsArray, "setMapRequest('" . $this->mainMap->getFrameName() . "');");
-		array_push($wmcJsArray, "setMapRequest('" . $this->overviewMap->getFrameName() . "');");
+		if ($this->overviewWmsIndex !== null) {
+			array_push($wmcJsArray, "setMapRequest('" . $this->overviewMap->getFrameName() . "');");
+		}
 		return $wmcJsArray;
 	}
-
+/*
 	function append ($wmcId) {
 		$this->createObjFromWMC_id($wmcId);
 		$this->createJsObjFromWMC("", "", "append");
@@ -1083,7 +1087,7 @@
 		$this->createObjFromWMC_id($wmcId);
 		$this->createJsObjFromWMC("", "", "merge");
 	}
-	
+*/	
 	/**
 	 * Creates JS code manipulating the map and wms objects, 
 	 * by this displaying the WMC
@@ -1406,16 +1410,58 @@
 	 * @param $currentLayer Array an associative array with layer data
 	 */
 	private function setLayerData ($currentLayer) {
-		// check if current layer belongs to an existing WMS...
+		if ($currentLayer["extension"]["ISOVERVIEWLAYER"] == "1" &&
+			$this->overviewWmsIndex !== null) {
+			return;
+		}
+
+		//
+		// check if current layer belongs to an existing WMS.
+		// If yes, store the index of this WMS in $wmsIndex.
+		// If not, set the value to null.
+		//
 		$wmsIndex = null;
-		for ($i = 0; $i < count($this->wmsArray); $i++) {
+
+		// find last WMS with the same online resource
+		for ($i = count($this->wmsArray) - 1; $i >= 0; $i--) {
 			if (isset($currentLayer["url"]) && 
 				$currentLayer["url"] == $this->wmsArray[$i]->wms_getmap) {
-	
-				$wmsIndex = $i;
+					$wmsIndex = $i;
+					break;
 			}
 		}
 
+		// Even if this WMS has been found before it could still
+		// be a duplicate! We would have to create a new WMS and 
+		// not append this layer to that WMS.
+		if ($wmsIndex !== null) {
+
+			// for the overview layer we never add a new wms.
+			// check if this layer is an overview layer. If yes, skip this layer.
+			//
+			// TO DO: THIS WILL FAIL IF THE OVERVIEW WMS IS STORED BEFORE
+			// THE MAIN FRAME LAYERS!!!
+			if ($currentLayer["extension"]["ISOVERVIEWLAYER"] == "1") {
+				$this->overviewWmsIndex = $wmsIndex;
+				return;
+			}
+
+			// check if this WMS has a layer equal to the current layer.
+			// If yes, this is a new WMS. If not, append this layer
+			// to the existing WMS.
+			$matchingWmsLayerArray = $this->wmsArray[$wmsIndex]->objLayer;
+			
+			for ($i = 0; $i < count($matchingWmsLayerArray); $i++) {
+				if ($matchingWmsLayerArray[$i]->layer_name == $currentLayer["name"]) {
+
+					// by re-setting the index to null, a new WMS will be 
+					// added below.
+					$wmsIndex = null;
+					break;
+				}
+			}
+		}
+
 		// if yes, create a new WMS ...
 		if ($wmsIndex === null) {
 			$wmsIndex = 0;
@@ -1467,10 +1513,7 @@
 			$currentLayerEpsg["maxy"] = $mainMapExtent->max->y;
 
 			array_push($this->wmsArray, $wms);
-
-			if ($currentLayer["extension"]["ISOVERVIEWLAYER"] == "1") {
-				$this->overviewMap->overviewLayerIndex = count($this->wmsArray) - 1;
-			}
+			$wmsIndex = count($this->wmsArray) - 1;
 		}
 		// add layer to existing WMS ...
 		$currentWms = $this->wmsArray[$wmsIndex];

Modified: branches/beck_dev/mapbender/http/classes/class_wms.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_wms.php	2008-05-16 10:00:51 UTC (rev 2460)
+++ branches/beck_dev/mapbender/http/classes/class_wms.php	2008-05-16 15:00:10 UTC (rev 2461)
@@ -75,7 +75,116 @@
 	  
 	function wms() {
 	} 
-	  
+	
+	/**
+	 * Compares this WMS to another WMS.
+	 * 
+	 * @return boolean false, if
+	 * 					- the capabilities URLs don't match
+	 * 					- the layer count is different
+	 * 					- the layer names are different
+	 * 
+	 * @param $anotherWms wms this is just another WMS object
+	 */
+	public function equals ($anotherWms) {
+		// If the capabilities URLs are not equal, the WMS are not equal.
+		if ($this->wms_getcapabilities != $anotherWms->wms_getcapabilities) {
+			$e = new mb_notice($this . " != " . $anotherWms . " (capabilities)");
+			return false;
+		}
+
+		// If the layer count is different, the WMS are not equal.
+		if (count($this->objLayer) != count($anotherWms->objLayer)) {
+			$e = new mb_notice($this . " != " . $anotherWms . " (layer count)");
+			return false;
+		}
+		
+		// If the layer names are different, the WMS are not equal.
+		for ($i = 0; $i < count($this->objLayer); $i++) {
+			$name1 = $this->objLayer[$i]->layer_name;
+			$name2 = $anotherWms->objLayer[$i]->layer_name;
+			
+			if ($name1 != $name2) {
+				$e = new mb_notice($this . " != " . $anotherWms . " (layer names, " . $name1 . " vs. " . $name2 . ")");
+				return false;
+			}
+		}
+		$e = new mb_notice($this . " == " . $anotherWms);
+		return true;
+	}  
+	
+	/**
+	 * The other WMS must be the same as this WMS, but with different
+	 * application settings. These application settings are copied,
+	 * the local settings are overwritten.
+	 * 
+	 * @return boolean true if the settings could be copied; false 
+	 * 					when an error occured.
+	 * @param $anotherWms wms The same WMS with possibly other settings
+	 */
+	public function copyConfiguration ($anotherWms) {
+		if (!$this->equals($anotherWms)) {
+			$e = new mb_exception("class_wms.php: copyConfiguration(): parameters cannot be copied, it's a different WMS.");
+			return false;
+		}
+		for ($i = 0; $i < count($this->objLayer); $i++) {
+			$myCurrentLayer = $this->objLayer[$i];
+			$theirCurrentLayer = $anotherWms->objLayer[$i];
+
+			$myCurrentLayer->gui_layer_selectable = $theirCurrentLayer->gui_layer_selectable;
+			$myCurrentLayer->gui_layer_visible    = $theirCurrentLayer->gui_layer_visible;
+			$myCurrentLayer->gui_layer_queryable  = $theirCurrentLayer->gui_layer_queryable;
+			$myCurrentLayer->gui_layer_querylayer = $theirCurrentLayer->gui_layer_querylayer;
+			$myCurrentLayer->gui_layer_style      = $theirCurrentLayer->gui_layer_style;
+		}
+	}
+	
+	
+	/**
+	 * Removes duplicate WMS from an array of WMS. To find duplicates,
+	 * two WMS are compared via equals().
+	 * 
+	 * @return wms[]
+	 * @param $wmsArray wms[]
+	 */
+	public static function merge ($wmsArray) {
+		if (!is_array($wmsArray)) {
+			$e = new mb_exception("class_wms.php: merge(): parameter is NOT an array.");
+			return array();
+		}
+		if (count($wmsArray) == 0) {
+			$e = new mb_exception("class_wms.php: merge(): parameter is an EMPTY array.");
+			return array();
+		}
+		
+		$newWmsArray = array();
+		while (count($wmsArray) > 0) {
+			$currentWms = array_pop($wmsArray);
+			
+			$isNewWms = true;
+
+			if (get_class($currentWms) != "wms") {
+				$e = new mb_exception("class_wms.php: merge(): current WMS is not a WMS object, but a " . get_class($currentWms));
+			}
+			else {
+				for ($i = 0; $i < count($newWmsArray) && $isNewWms; $i++) {
+					if ($currentWms->equals($newWmsArray[$i])) {
+						$isNewWms = false;
+					}
+				}
+				if ($isNewWms) {
+					array_push($newWmsArray, $currentWms);
+				}
+			}
+			
+		}
+		return array_reverse($newWmsArray);
+	}
+	
+	public function __toString () {
+		return $this->wms_title;
+	}
+	
 	function createObjFromXML($url){
 	
 		$x = new connector($url);

Modified: branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.js
===================================================================
--- branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.js	2008-05-16 10:00:51 UTC (rev 2460)
+++ branches/beck_dev/mapbender/http/javascripts/mod_loadwmc.js	2008-05-16 15:00:10 UTC (rev 2461)
@@ -25,6 +25,17 @@
  */
 function mod_loadwmc(){
 
+	var initialHtml = "<div>" +
+					"<h2 style='font-family: Arial, Helvetica, sans-serif; color: #808080;'><font align='left' color='#000000'>load WMC from list</font></h2>" +
+					"<table id='loadwmc_list' width='90%' style='font-family: Arial, Helvetica, sans-serif;font-size : 12px;color: #808080;' border='1' cellpadding='3' rules='rows'>" +
+						"<tr style='background-color:#F0F0F0;' width='80px'>" +
+							"<td><b>WMC name</b></td>" +
+							"<td><b>last update</b></td>" +
+							"<td colspan=5></td>" +
+						"</tr>" +
+					"</table>" +
+				"</div>";
+
 	// creates a new pop up (if it doesn't already exist)
 	// the pop up allows you to load, append, merge, 
 	// display and delete WMC documents
@@ -35,22 +46,15 @@
 			height:600,
 			top:100,
 			left:100,
-			html:"<div>" +
-					"<h2 style='font-family: Arial, Helvetica, sans-serif; color: #808080;'><font align='left' color='#000000'>load WMC from list</font></h2>" +
-					"<table id='loadwmc_list' width='90%' style='font-family: Arial, Helvetica, sans-serif;font-size : 12px;color: #808080;' border='1' cellpadding='3' rules='rows'>" +
-						"<tr style='background-color:#F0F0F0;' width='80px'>" +
-							"<td><b>WMC name</b></td>" +
-							"<td><b>last update</b></td>" +
-							"<td colspan=5></td>" +
-						"</tr>" +
-					"</table>" +
-				"</div>"
+			html:initialHtml
 		});
 	}
 
 	// display the pop up
 	if (!wmcPopup.isVisible()) {
+		wmcPopup.setHtml(initialHtml);
 		wmcPopup.show();
+		
 	}
 
 	// get WMC data from server
@@ -94,7 +98,6 @@
 						try {
 							if (resultObj.javascript && typeof(resultObj.javascript) == "object") {
 								for (var j=0; j < resultObj.javascript.length; j++) {
-									console.log("%s", resultObj.javascript[j]);
 									eval(resultObj.javascript[j]);
 								}
 							}	
@@ -107,6 +110,14 @@
 					if (loadWmcError) {
 						alert("An error has occured while loading this WMC.");
 					}
+					else {
+						// close the Pop up
+						if (wmcDisplayPopup !== null && wmcDisplayPopup.isVisible()) {
+							wmcDisplayPopup.hide();
+						}
+						wmcPopup.hide();
+						alert("WMC has been loaded successfully.");
+					}
 				});
 			});
 			$td = $("<td></td>").append($loadWmc);
@@ -124,7 +135,6 @@
 			$displayWmc.click(function() {
 				// create Popup
 				if (wmcDisplayPopup === null) {
-					console.log("is null");
 					wmcDisplayPopup = new mb_popup({
 						title:"WMC Document",
 						width:600,



More information about the Mapbender_commits mailing list