[Mapbender-commits] r2468 - branches/beck_dev/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed May 21 11:38:21 EDT 2008


Author: christoph
Date: 2008-05-21 11:38:21 -0400 (Wed, 21 May 2008)
New Revision: 2468

Added:
   branches/beck_dev/mapbender/http/classes/class_wmcToXml.php
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
Log:
new class for WMC XML generation 

Modified: branches/beck_dev/mapbender/http/classes/class_map.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_map.php	2008-05-20 09:00:07 UTC (rev 2467)
+++ branches/beck_dev/mapbender/http/classes/class_map.php	2008-05-21 15:38:21 UTC (rev 2468)
@@ -6,11 +6,13 @@
  */
 class Map {
 
-	var $width;
-	var $height;
-	var $frameName;
-	var $elementName = "maps";
-	var $extent;
+	private $width;
+	private $height;
+	private $frameName;
+	private $elementName = "maps";
+	private $extent;
+	private $isOverview = false;
+	private $wmsArray = array();
 	
 	/**
 	 * @constructor
@@ -27,6 +29,14 @@
 	}
 
 	/**
+	 * 
+	 * @return 
+	 */
+	public function getWidth () {
+		return $this->width;
+	}
+
+	/**
 	 * @param $value Integer
 	 */
 	public function setHeight ($value) {
@@ -34,6 +44,14 @@
 	}
 
 	/**
+	 * 
+	 * @return 
+	 */
+	public function getHeight () {
+		return $this->height;
+	}
+
+	/**
 	 * @param $value String
 	 */
 	public function setFrameName ($value) {
@@ -79,6 +97,127 @@
 	}
 	
 	/**
+	 * 
+	 * @return 
+	 */
+	public function getWmsArray () {
+		return $this->wmsArray;	
+	}
+	
+	/**
+	 * 
+	 * @return 
+	 * @param $wmsArray Object
+	 */
+	public function setWmsArray ($wmsArray) {
+		$this->wmsArray = $wmsArray;
+	}
+	
+	/**
+	 * 
+	 * @return 
+	 */
+	public function isOverview () {
+		return $this->isOverview;
+	}
+	
+	/**
+	 * 
+	 * @return 
+	 * @param $jsMapObject Object
+	 */
+	public function createFromJs ($jsMapObject) {
+		$arrayBBox = explode(",", $jsMapObject->extent);
+		$minx = floatval($arrayBBox[0]);
+		$miny = floatval($arrayBBox[1]);
+		$maxx = floatval($arrayBBox[2]);
+		$maxy = floatval($arrayBBox[3]);
+		$srs = $jsMapObject->epsg;
+		$bbox = new Mapbender_bbox($minx, $miny, $maxx, $maxy, $srs);
+
+		$this->width = $jsMapObject->width;
+		$this->height = $jsMapObject->height;
+		$this->frameName = $jsMapObject->frameName;
+		$this->extent = $bbox;
+		
+		if (isset($jsMapObject->isOverview) && $jsMapObject->isOverview == "1") {
+			$this->isOverview = true;
+		}
+
+		for ($i=0; $i < count($jsMapObject->wms); $i++){
+	
+			$currentWms = $jsMapObject->wms[$i];
+			$wms = new wms();
+
+			//
+			// set WMS data
+			//
+			$wms->wms_id = $currentWms->wms_id;
+			$wms->wms_version = $currentWms->wms_version;
+			$wms->wms_title = $currentWms->wms_title;
+			$wms->wms_abstract = $currentWms->wms_abstract;
+			$wms->wms_getmap = $currentWms->wms_getmap;
+			$wms->wms_getfeatureinfo = $currentWms->wms_getfeatureinfo;
+			$wms->wms_getlegendurl = $currentWms->wms_getlegendurl;
+			$wms->wms_filter = $currentWms->wms_filter;
+			$wms->gui_epsg = $currentWms->gui_epsg;
+			$wms->gui_minx = $currentWms->gui_minx;
+			$wms->gui_miny = $currentWms->gui_miny;
+			$wms->gui_maxx = $currentWms->gui_maxx;
+			$wms->gui_maxy = $currentWms->gui_maxy;
+			$wms->gui_wms_mapformat = $currentWms->gui_wms_mapformat;
+			$wms->gui_wms_featureinfoformat = $currentWms->gui_wms_featureinfoformat;
+			$wms->gui_wms_exceptionformat = $currentWms->gui_wms_exceptionformat;
+			$wms->gui_wms_opacity = $currentWms->wms_opacity;
+			$wms->gui_wms_sldurl = $currentWms->gui_wms_sldurl;
+			$wms->gui_wms_visible = $currentWms->gui_wms_visible;
+			$wms->gui_wms_epsg = $currentWms->gui_wms_epsg;
+			$wms->data_type = $currentWms->data_type;
+			$wms->data_format = $currentWms->data_format;
+
+			for ($k = 0; $k < count($currentWms->objLayer); $k++){
+				// the current layer of the JSON map object
+				$currentLayer = $currentWms->objLayer[$k];
+
+				// add new layer to WMS
+				$pos = $currentLayer->layer_pos;
+				$parent = $currentLayer->layer_parent;
+				$wms->addLayer($pos, $parent); 
+
+				$newLayerIndex = count($wms->objLayer) - 1;
+				// $newLayer is a short cut to the layer we just added
+				$newLayer = $wms->objLayer[$newLayerIndex];
+				
+				// set layer data
+				$newLayer->layer_uid = $currentLayer->layer_uid;
+				$newLayer->layer_name = $currentLayer->layer_name;
+				$newLayer->layer_title = $currentLayer->layer_title;
+				$newLayer->layer_dataurl_href = $currentLayer->layer_dataurl_href;
+				$newLayer->layer_pos = $currentLayer->layer_pos;
+				$newLayer->layer_queryable = $currentLayer->layer_queryable;
+				$newLayer->layer_minscale = $currentLayer->layer_minscale;
+				$newLayer->layer_maxscale = $currentLayer->layer_maxscale;
+				$newLayer->layer_metadataurl = $currentLayer->metadataurl;
+				$newLayer->gui_layer_wms_id = $wms->objLayer[0]->layer_uid;
+				$newLayer->gui_layer_status = $currentLayer->gui_layer_status;
+				$newLayer->gui_layer_style = $currentLayer->gui_layer_style;
+				$newLayer->gui_layer_selectable = $currentLayer->gui_layer_selectable;
+				$newLayer->gui_layer_visible = $currentLayer->gui_layer_visible;
+				$newLayer->gui_layer_queryable = $currentLayer->gui_layer_queryable;
+				$newLayer->gui_layer_querylayer = $currentLayer->gui_layer_querylayer;
+				$newLayer->gui_layer_minscale = $currentLayer->gui_layer_minscale;
+				$newLayer->gui_layer_maxscale = $currentLayer->gui_layer_maxscale;
+				$newLayer->gui_layer_wfs_featuretype = $currentLayer->gui_layer_wfs_featuretype;
+				$newLayer->layer_epsg = $currentLayer->layer_epsg;
+				$newLayer->layer_style = $currentLayer->layer_style;
+
+			}
+			array_push($this->wmsArray, $wms);
+		}
+		return true;
+	}
+	
+	/**
 	 * Returns an array of string, which are JS statements.
 	 * @return String[]
 	 */

Modified: branches/beck_dev/mapbender/http/classes/class_wmc.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_wmc.php	2008-05-20 09:00:07 UTC (rev 2467)
+++ branches/beck_dev/mapbender/http/classes/class_wmc.php	2008-05-21 15:38:21 UTC (rev 2468)
@@ -24,6 +24,7 @@
 require_once(dirname(__FILE__) . "/../classes/class_json.php");
 require_once(dirname(__FILE__) . "/../classes/class_map.php");
 require_once(dirname(__FILE__) . "/../classes/class_administration.php");
+require_once(dirname(__FILE__) . "/../classes/class_wmcToXml.php");
 
 /**
  * Implementation of a Web Map Context Document, WMC 1.1.0
@@ -49,26 +50,44 @@
  * Output (1) (do Instantiation first) Load a WMC into client
  * 		This will return an array of JS statements
  *  
- * 		$myWmc->load();
+ * 		$myWmc->toJavaScript();
  * 
  * Output (2) (do Instantiation first) Merge with another WMC, then load
  * 	
  * 		$myWmc->merge($anotherWmcXml);
- * 		$myWmc->load();
+ * 		$myWmc->toJavaScript();
  * 
  */
 class wmc {
-
+	/**
+	 * Representing the main map in a map application
+	 * @var Map
+	 */
 	var $mainMap;
+
+	/**
+	 * Representing an (optional) overview map in a map application
+	 * @var Map
+	 */
 	var $overviewMap;
-	var $wmsArray = array();
-	var $overviewWmsIndex = null;
+
+	/**
+	 * @var Array
+	 */
 	var $generalExtensionArray = array();
+
+	/**
+	 * The XML representation of this WMC.
+	 * @var String
+	 */
 	var $xml;
 	
 	// constants
 	var $monitoringIsOn = false;
 	var $saveWmcAsFile = false;
+	var $extensionNamespace = "mapbender";
+	var $extensionNamespaceUrl = "http://www.mapbender.org";
+		
   		
 	// set in constructor
 	var $wmc_id;
@@ -107,7 +126,7 @@
 	} 
 	
 	// ---------------------------------------------------------------------------
-	// INSTANTIATION
+	// CREATION OF A WMC
 	// ---------------------------------------------------------------------------
 
 	/**
@@ -142,505 +161,34 @@
 	 */
 	public function createFromJs($mapObject, $generalTitle, $extensionData) {
 	
-		$extension_namespace = "mapbender";
-		$extension_namespace_url = "http://www.mapbender.org";
-		
-		// 
-		// STEP 1/2: GENERATE THE GENERAL TAG
-		// 
-	
-		$generalWidth = 0; // set below
-		$generalHeight = 0; // set below
-		$generalBboxSrs = 0; // set below
-		$generalName = "Mapbender WMC"; // TO do : insert proper data
-		$generalKeywords = array("Mapbender", "WMC"); // TO do : insert proper data
-		$generalAbstract = ""; // TO do : insert proper data
-		$generalLogoUrl = ""; // TO do : insert proper data
-		$generalLogoUrlWidth = ""; // TO do : insert proper data
-		$generalLogoUrlHeight = ""; // TO do : insert proper data
-		$generalLogoUrlFormat = ""; // TO do : insert proper data
-		$generalDescriptionUrl = ""; // TO do : insert proper data
-		$generalContactPerson = "";
-		$generalContactOrganization = "";
-		$generalContactPosition = "";
-		$generalContactAddressType = "";
-		$generalContactAddress = "";
-		$generalContactCity = "";
-		$generalContactStateOrProvince = "";
-		$generalContactPostCode = "";
-		$generalContactCountry = "";
-		$generalContactVoiceTelephone = "";
-		$generalContactFacsimileTelephone = "";
-		$generalContactElectronicMailAddress = "";
-		
 		if (count($mapObject) > 2) {
 			$e = new mb_exception("Save WMC only works for two concurrent map frames (overview plus main) at the moment.");
 		}
 		
-		// get the width, height, epsg and bbox of the overview and the main map
+		// set extension data		
+		$this->generalExtensionArray = $extensionData;
+
+		// set title
+		$this->wmc_title = $generalTitle;
+		
+		// create the map objects
 		for ($i = 0; $i < count($mapObject); $i++) {
-			if (!isset($mapObject[$i]->isOverview)) {
-				$generalWidth = $mapObject[$i]->width;
-				$generalHeight = $mapObject[$i]->height;
-				$generalBboxSrs = $mapObject[$i]->epsg;
-	
-				$arrayBBox = explode(",", $mapObject[$i]->extent);
-				$generalBboxMinx = floatval($arrayBBox[0]);
-				$generalBboxMiny = floatval($arrayBBox[1]);
-				$generalBboxMaxx = floatval($arrayBBox[2]);
-				$generalBboxMaxy = floatval($arrayBBox[3]);
+			$currentMap = new Map();
+			$currentMap->createFromJs($mapObject[$i]);
+
+			if (isset($mapObject[$i]->isOverview)) {
+				$this->overviewMap = $currentMap;
 			}
 			else {
-				$extensionData->ov_width = $mapObject[$i]->width;
-				$extensionData->ov_height = $mapObject[$i]->height;
-	
-				$arrayBBox = explode(",", $mapObject[$i]->extent);
-				$extensionData->ov_minx = floatval($arrayBBox[0]);
-				$extensionData->ov_miny = floatval($arrayBBox[1]);
-				$extensionData->ov_maxx = floatval($arrayBBox[2]);
-				$extensionData->ov_maxy = floatval($arrayBBox[3]);
-				$extensionData->ov_srs = $mapObject[$i]->epsg;
-				$extensionData->ov_framename = $mapObject[$i]->frameName;
+				$this->mainMap = $currentMap;
 			}
 		}
-				
-		// generate XML
-		$doc = new DOMDocument("1.0", CHARSET);
-		$doc->preserveWhiteSpace = false;
-		
-		// ViewContext
-		$e_view_context = $doc->createElementNS("http://www.opengis.net/context", "ViewContext");
-		$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:" . $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");
-		
-			// General
-			$e_general = $doc->createElement("General");
-		
-				$e_window = $doc->createElement("Window");
-				if (!empty($generalWidth) && !empty($generalHeight)) {
-					$e_window->setAttribute("width", $generalWidth);
-					$e_window->setAttribute("height", $generalHeight);
-				}
-				$e_general->appendChild($e_window);
-				
-				$e_bbox = $doc->createElement("BoundingBox");
-				$e_bbox->setAttribute("SRS", $generalBboxSrs);
-				$e_bbox->setAttribute("minx", $generalBboxMinx);
-				$e_bbox->setAttribute("miny", $generalBboxMiny);
-				$e_bbox->setAttribute("maxx", $generalBboxMaxx);
-				$e_bbox->setAttribute("maxy", $generalBboxMaxy);
-				$e_general->appendChild($e_bbox);
-				
-				$e_name = $doc->createElement("Name", $generalName);
-				$e_general->appendChild($e_name);
-				
-				$e_title = $doc->createElement("Title", $generalTitle);
-				$e_general->appendChild($e_title);
-				
-				$e_keyword_list = $doc->createElement("KeywordList");
-				for ($i=0; $i < count($generalKeywords); $i++) {
-					$e_keyword = $doc->createElement("Keyword", $generalKeywords[$i]);
-					$e_keyword_list->appendChild($e_keyword);
-				}
-				$e_general->appendChild($e_keyword_list);
-				
-				if ($generalAbstract){
-					$e_abstract = $doc->createElement("Abstract", $generalAbstract);
-					$e_general->appendChild($e_abstract);
-				}
-				
-				if ($generalLogoUrlWidth && $generalLogoUrlHeight && $generalLogoUrlFormat && $generalLogoUrl){
-					$e_logo_url = $doc->createElement("LogoURL");
-					$e_logo_url->setAttribute("width", $generalLogoUrlWidth);
-					$e_logo_url->setAttribute("height", $generalLogoUrlHeight);
-					$e_logo_url->setAttribute("format", $generalLogoUrlFormat);
-				
-					$e_logo_url_or = $doc->createElement("OnlineResource");
-					$e_logo_url_or->setAttributeNS("http://www.opengis.net/context", "xmlns:xlink", "http://www.w3.org/1999/xlink");
-					$e_logo_url_or->setAttribute("xlink:type", "simple");
-					$e_logo_url_or->setAttribute("xlink:href", $generalLogoUrl);
-					$e_logo_url->appendChild($e_logo_url_or);
-		
-					$e_general->appendChild($e_logo_url);
-				}
-					
-				if ($generalDescriptionUrl){
-					$e_description_url = $doc->createElement("DescriptionURL");
-		
-					$e_description_url_or = $doc->createElement("OnlineResource");
-					$e_description_url_or->setAttributeNS("http://www.opengis.net/context", "xmlns:xlink", "http://www.w3.org/1999/xlink");
-					$e_description_url_or->setAttribute("xlink:type", "simple");
-					$e_description_url_or->setAttribute("xlink:href", $generalDescriptionUrl);
-					$e_description_url->appendChild($e_description_url_or);
-		
-					$e_general->appendChild($e_description_url);
-				}
-				
-				if ($generalContactElectronicMailAddress || $generalContactOrganization ||
-					$generalContactPerson || $generalContactPosition || $generalContactAddressType ||
-					$generalContactAddress || $generalContactCity || $generalContactStateOrProvince ||
-					$generalContactPostCode || $generalContactCountry || $generalContactVoiceTelephone ||
-					$generalContactFacsimileTelephone || $generalContactElectronicMailAddress) {
-				
-					$e_contact = $doc->createElement("ContactInformation");
-				
-					if ($generalContactPerson || $generalContactOrganization){
-						$e_contact_person_primary = $doc->createElement("ContactPersonPrimary");
-				
-						if ($generalContactPerson){
-							$e_contact_person = $doc->createElement("ContactPerson", $generalContactPerson);
-							$e_contact_person_primary->appendChild($e_contact_person);
-						}
-						if ($generalContactOrganization){
-							$e_contact_organization = $doc->createElement("ContactOrganization", $generalContactOrganization);
-							$e_contact_person_primary->appendChild($e_contact_organization);
-						}
-						$e_contact->appendChild($e_contact_person_primary);
-					}
-				
-					if ($generalContactPosition){
-						$e_contact_position = $doc->createElement("ContactPosition", $generalContactPosition);
-						$e_contact->appendChild($e_contact_position);
-					}
-				
-					if ($generalContactAddressType || $generalContactAddress || 
-						$generalContactCity || $generalContactStateOrProvince ||
-						$generalContactPostCode || $generalContactCountry) {
-				
-						$e_contact_address = $doc->createElement("ContactAddress");
-				
-						if ($generalContactAddressType){
-							$e_address_type = $doc->createElement("AddressType", $generalContactAddressType);
-							$e_contact_address->appendChild($e_address_type);
-						}
-						if ($generalContactAddress){
-							$e_address = $doc->createElement("Address", $generalContactAddress);
-							$e_contact_address->appendChild($e_address);
-						}
-						if ($generalContactCity){
-							$e_city = $doc->createElement("City", $generalContactCity);
-							$e_contact_address->appendChild($e_city);
-						}
-						if ($generalContactStateOrProvince){
-							$e_state = $doc->createElement("StateOrProvince", $generalContactStateOrProvince);
-							$e_contact_address->appendChild($e_state);
-						}
-						if ($generalContactPostCode){
-							$e_postcode = $doc->createElement("PostCode", $generalContactPostCode);
-							$e_contact_address->appendChild($e_postcode);
-						}
-						if ($generalContactCountry){
-							$e_country = $doc->createElement("Country", $generalContactCountry);
-							$e_contact_address->appendChild($e_country);
-						}
-						$e_contact->appendChild($e_contact_address);
-					}
-					
-					if ($generalContactVoiceTelephone){
-						$e_voice_telephone = $doc->createElement("ContactVoiceTelephone", $generalContactVoiceTelephone);
-						$e_contact->appendChild($e_voice_telephone);
-					}
-					if ($generalContactFacsimileTelephone){
-						$e_facsimile_telephone = $doc->createElement("ContactFacsimileTelephone", $generalContactFacsimileTelephone);
-						$e_contact->appendChild($e_facsimile_telephone);
-					}
-					if ($generalContactElectronicMailAddress){
-						$e_email = $doc->createElement("ContactElectronicMailAddress", $generalContactElectronicMailAddress);
-						$e_contact->appendChild($e_email);
-					}
-					$e_general->appendChild($e_contact);
-				}
-				
-				if (count($extensionData) > 0) {
-					$e_extensionGeneral = $doc->createElement("Extension");
-					
-					foreach ($extensionData as $keyExtensionData => $valueExtensionData) {
-						$e_currentExtensionTag = $doc->createElement($extension_namespace.":".$keyExtensionData, $valueExtensionData);
-						$e_extensionGeneral->appendChild($e_currentExtensionTag);
-					}
-					$e_general->appendChild($e_extensionGeneral);
-				}
-			$e_view_context->appendChild($e_general);
-		
-		
-		// 
-		// STEP 2/2: GENERATE THE LAYERLIST TAG
-		// 
-		$e_layer_list = $doc->createElement("LayerList");
-		for ($h = 0; $h < count($mapObject); $h++) {
-			// LayerList variables
-			$layerHidden = "";
-			$layerQueryable = "";
-			$layerAbstract = "";
-			$layerName = "";
-			$layerSrs = "";
-			$layerDataUrl = "";
-			$layerMetadataUrl = "";
-			$layerFormat = "";
-			$layerFormat_current = "";
-			$layerStyle_current = "";
-			$layerStyle_name = "";
-			$layerStyle_title = "";
-			$layerStyle_legendURL = "";
-			$layerStyle_legendURL_width = "";
-			$layerStyle_legendURL_height = "";
-			$layerStyle_legendURL_format = "";		
-			
-		
-			for ($i=0; $i < count($mapObject[$h]->wms); $i++){
-				$wmsId = $mapObject[$h]->wms[$i]->wms_id;
-				$wms_epsg = array();
-				$wms_epsg[0] = $mapObject[$h]->epsg;
-			
-				if ($mapObject[$h]->wms[$i]->gui_wms_epsg != $mapObject[$h]->epsg){
-					$wms_epsg[1] = $mapObject[$h]->wms[$i]->gui_wms_epsg;
-				}
-		
-				for ($q = 0; $q < count($mapObject[$h]->wms[$i]->gui_epsg); $q++){
-					$isInArray = false;
-					
-					for ($r=0 ; $r < count($wms_epsg); $r++){
-						if ($wms_epsg[$r] == $mapObject[$h]->wms[$i]->gui_epsg[$q]){
-							$isInArray = true;
-						}
-					}
-					if ($isInArray == false){
-						array_push($wms_epsg, $mapObject[$h]->wms[$i]->gui_epsg[$q]);
-					}
-				}
-				for ($j = 0; $j < count($mapObject[$h]->wms[$i]->objLayer); $j++){
-					if ($mapObject[$h]->wms[$i]->objLayer[$j]->layer_parent != ''){
-						if ($mapObject[$h]->wms[$i]->objLayer[$j]->gui_layer_visible == "1"){
-							$layerHidden = 0;
-						}
-						else{
-							$layerHidden = 1;
-						}
-						$layerQueryable = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_queryable;
-						$layerQuerylayer = $mapObject[$h]->wms[$i]->objLayer[$j]->gui_layer_querylayer;
-						$layerId = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_uid;
-						$layerName = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_name;
-						$layerTitle = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_title;
-						$layerAbstract = $mapObject[$h]->wms[$i]->wms_abstract; //To Do: insert actual abstract
-						$layerDataUrl = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_dataurl_href; 
-						$layerMetadataUrl = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_metadataurl;
-						$layerMinscale = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_minscale; 
-						$layerMaxscale = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_maxscale; 
-						$guiLayerMinscale = $mapObject[$h]->wms[$i]->objLayer[$j]->gui_layer_minscale; 
-						$guiLayerMaxscale = $mapObject[$h]->wms[$i]->objLayer[$j]->gui_layer_maxscale; 
-						$wmsVersion = $mapObject[$h]->wms[$i]->wms_version;
-						$wmsTitle = $mapObject[$h]->wms[$i]->wms_title;
-						$wmsLayerId = $mapObject[$h]->wms[$i]->objLayer[0]->layer_uid;
-						$wmsOnlineResource = $mapObject[$h]->wms[$i]->wms_getmap;
-						$layerPos = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_pos;
-						$layerParent = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_parent;
-						$queryLayer = $mapObject[$h]->wms[$i]->objLayer[$j]->gui_layer_querylayer;
-						$wfsFeatureType = $mapObject[$h]->wms[$i]->objLayer[$j]->gui_layer_wfs_featuretype;
-						
-						$e_layer = $doc->createElement("Layer");
-						$e_layer->setAttribute("queryable", $layerQueryable);
-						$e_layer->setAttribute("hidden", $layerHidden);
-			
-							$e_service = $doc->createElement("Server");
-							$e_service->setAttribute("service", "OGC:WMS");
-							$e_service->setAttribute("version", $wmsVersion);
-							$e_service->setAttribute("title", $wmsTitle);
-			
-							$e_service_or = $doc->createElement("OnlineResource");
-							$e_service_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-							$e_service_or->setAttribute("xlink:type", "simple");
-							$e_service_or->setAttribute("xlink:href", $wmsOnlineResource);
-							
-							$e_service->appendChild($e_service_or);
-							$e_layer->appendChild($e_service);
-			
-							$e_layer_name = $doc->createElement("Name", $layerName);
-							$e_layer->appendChild($e_layer_name);
-			
-							$e_layer_title = $doc->createElement("Title", $layerTitle);
-							$e_layer->appendChild($e_layer_title);
-			
-							if ($layerAbstract){
-								$e_layer_abstract = $doc->createElement("Abstract", $layerAbstract);
-								$e_layer->appendChild($e_layer_abstract);
-							}
-			
-							$e_layer_srs = $doc->createElement("SRS", implode(" ", $wms_epsg));
-							$e_layer->appendChild($e_layer_name);
-			
-							if ($layerDataUrl){
-								$e_layer_data_url = $doc->createElement("DataURL");
-				
-								$e_layer_data_url_or = $doc->createElement("OnlineResource");
-								$e_layer_data_url_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-								$e_layer_data_url_or->setAttribute("xlink:type", "simple");
-								$e_layer_data_url_or->setAttribute("xlink:href", $layerDataUrl);
-								
-								$e_layer_data_url->appendChild($e_layer_data_url_or);
-								$e_layer->appendChild($e_layer_data_url);
-							}
-			
-							if ($layerMetadataUrl){
-								$e_layer_metadata_url = $doc->createElement("MetadataURL");
-				
-								$e_layer_metadata_url_or = $doc->createElement("OnlineResource");
-								$e_layer_metadata_url_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-								$e_layer_metadata_url_or->setAttribute("xlink:type", "simple");
-								$e_layer_metadata_url_or->setAttribute("xlink:href", $layerMetadataUrl);
-								
-								$e_layer_metadata_url->appendChild($e_layer_metadata_url_or);
-								$e_layer->appendChild($e_layer_metadata_url);
-							}
-			
-							$e_extension = $doc->createElement("Extension");
-			
-							$e_minscalehint = $doc->createElement($extension_namespace.":minscale", $layerMinscale);
-							$e_extension->appendChild($e_minscalehint);
-							
-							$e_maxscalehint = $doc->createElement($extension_namespace.":maxscale", $layerMaxscale);
-							$e_extension->appendChild($e_maxscalehint);
-							
-							$e_gui_minscalehint = $doc->createElement($extension_namespace.":gui_minscale", $guiLayerMinscale);
-							$e_extension->appendChild($e_gui_minscalehint);
-							
-							$e_gui_maxscalehint = $doc->createElement($extension_namespace.":gui_maxscale", $guiLayerMaxscale);
-							$e_extension->appendChild($e_gui_maxscalehint);
-							
-							$e_layer_id = $doc->createElement($extension_namespace.":layer_id", $layerId);
-							$e_extension->appendChild($e_layer_id);
-							
-							$e_wms_layer_id = $doc->createElement($extension_namespace.":wms_layer_id", $wmsLayerId);
-							$e_extension->appendChild($e_wms_layer_id);
-							
-							$e_layer_pos = $doc->createElement($extension_namespace.":layer_pos", $layerPos);
-							$e_extension->appendChild($e_layer_pos);
-			
-							$e_layer_parent = $doc->createElement($extension_namespace.":layer_parent", $layerParent);
-							$e_extension->appendChild($e_layer_parent);
-			
-							$e_wms_id = $doc->createElement($extension_namespace.":wms_id", $wmsId);
-							$e_extension->appendChild($e_wms_id);
-			
-							$e_querylayer = $doc->createElement($extension_namespace.":querylayer", $layerQuerylayer);
-							$e_extension->appendChild($e_querylayer);
-							
-							if (isset($mapObject[$h]->isOverview)) {
-								$e_isOverviewLayer = $doc->createElement($extension_namespace.":isOverviewLayer", 1);
-								$e_extension->appendChild($e_isOverviewLayer);
-							}
-							
-							if ($wfsFeatureType) {
-								$e_wfsFeatureType = $doc->createElement($extension_namespace.":wfsFeatureType", $wfsFeatureType);
-								$e_extension->appendChild($e_wfsFeatureType);
-							}
-	
-							$e_layer->appendChild($e_extension);
-			
-							//layerFormat
-							$e_layer_format = $doc->createElement("FormatList");
-			
-							$data_format_current = false;
-			
-							for ($k = 0; $k < count($mapObject[$h]->wms[$i]->data_format); $k++){
-			
-								if ($mapObject[$h]->wms[$i]->data_type[$k] == "map") {
-									$layerFormat = $mapObject[$h]->wms[$i]->data_format[$k];
-					
-									$e_format = $doc->createElement("Format", $layerFormat);
-			
-									if ($data_format_current == false && ( 
-											($mapObject[$h]->wms[$i]->data_format[$k] == $mapObject[$h]->wms[$i]->gui_wms_mapformat) ||
-											($k == (count($mapObject[$h]->wms[$i]->data_format)-1))
-									)){
-			
-										$e_format->setAttribute("current", "1");
-										$data_format_current = true;
-									}
-									$e_layer_format->appendChild($e_format);
-								}
-							}
-							$e_layer->appendChild($e_layer_format);
-			
-			
-							// LayerStyle
-							$e_layer_stylelist = $doc->createElement("StyleList");
-				
-							for ($k = 0; $k < count($mapObject[$h]->wms[$i]->objLayer[$j]->layer_style); $k++){
-			
-								if ($k == 0){
-									$layerStyle_current = 1; // To do: insert proper data
-								}
-								else{
-									$layerStyle_current = 0; // To do: insert proper data
-								}
-			
-								$e_layer_style = $doc->createElement("Style");
-			
-								$layerStyleSLD = "";
-			
-								if ($layerStyleSLD){
-									$layerStyleSLDUrl = ""; // To Do: Insert Proper Data
-									
-									$e_layer_style_or = $doc->createElement("OnlineResource");
-									$e_layer_style_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-									$e_layer_style_or->setAttribute("xlink:type", "simple");
-									$e_layer_style_or->setAttribute("xlink:href", $layerStyleSLDUrl);
-									$e_layer_style->appendChild($e_layer_style_or);
-								}
-								else{
-									//TODO: determine correct layer style entries
-									$layerStyle_name = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_style[$k]->name;
-									$layerStyle_title = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_style[$k]->title;
-									$layerStyle_legendUrl = $mapObject[$h]->wms[$i]->objLayer[$j]->layer_style[$k]->legendurl;
-									$layerStyle_legendUrl_width = ""; // To Do: add proper data
-									$layerStyle_legendUrl_height = ""; // To Do: add proper data
-									$layerStyle_legendUrl_format = ""; // To Do: add proper data
-			
-									if ($layerStyle_current == 1){
-										$e_layer_style->setAttribute("current", "1");
-									}
-		
-									$e_layer_style_name = $doc->createElement("Name", $layerStyle_name);
-									$e_layer_style->appendChild($e_layer_style_name);
-		
-									$e_layer_style_title = $doc->createElement("Title", $layerStyle_title);
-									$e_layer_style->appendChild($e_layer_style_title);
-									
-									
-									$e_layer_style_legendurl = $doc->createElement("LegendUrl");
-									$e_layer_style_legendurl->setAttribute("width", $layerStyle_legendUrl_width);
-									$e_layer_style_legendurl->setAttribute("height", $layerStyle_legendUrl_height);
-									$e_layer_style_legendurl->setAttribute("format", $layerStyle_legendUrl_format);
-		
-									$e_layer_style_legendurl_or = $doc->createElement("OnlineResource");
-									$e_layer_style_legendurl_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-									$e_layer_style_legendurl_or->setAttribute("xlink:type", "simple");
-									$e_layer_style_legendurl_or->setAttribute("xlink:href", $layerStyle_legendUrl);
-									$e_layer_style_legendurl->appendChild($e_layer_style_legendurl_or);
-									$e_layer_style->appendChild($e_layer_style_legendurl);
-								}
-								$e_layer_stylelist->appendChild($e_layer_style);
-							}	
-							$e_layer->appendChild($e_layer_stylelist);
-							
-						$e_layer_list->appendChild($e_layer);
-					}
-				}
-			}
-		}
-		$e_view_context->appendChild($e_layer_list);
-		$doc->appendChild($e_view_context);
 
-		$this->xml = $doc->saveXML();
-		$this->wmc_title = $generalTitle;
 		
-		$this->createFromXml($this->xml);
-		
-		$filename = $this->saveAsFile();
+		// create XML
+		$this->createXml();
+
+		return true;
 	}
 	
 	// ---------------------------------------------------------------------------
@@ -675,7 +223,7 @@
 		}
 		else {
 			$result["success"] = false;
-			$errMsg = "missing parameters (user_id: ".$this->userId.", title: " . $this->title . ")";
+			$errMsg = "missing parameters (user_id: ".$this->userId.", title: " . $this->wmc_title . ")";
 			$result["message"] = $errMsg;
 			$e = new mb_exception("mod_insertWMCIntoDB: " . $errMsg .")");
 		}
@@ -752,10 +300,10 @@
 	 * @return String The XML document; if unavailable, null is returned.
 	 */
 	public function toXml () {
-		if ($this->xml) {
-			return $this->xml;
+		if (!$this->xml) {
+			$this->createXml();
 		}
-		return null;
+		return $this->xml;
 	}
 
 	/**
@@ -778,7 +326,7 @@
 		$wmcJsArray = array();
 		
 		// set general extension data
-		if (count($this->wmc_general_extension) > 0) {
+		if (count($this->generalExtensionArray) > 0) {
 			$json = new Mapbender_JSON();
 			array_push($wmcJsArray, "restoredWmcExtensionData = " . $json->encode($this->generalExtensionArray) . ";"); 
 		}
@@ -786,26 +334,41 @@
 		// reset WMS data
 		array_push($wmcJsArray, "wms = [];");
 
+		// add WMS for main map frame
+		$wmsArray = $this->mainMap->getWmsArray();
 		// for all wms...
-		for ($i = 0; $i < count($this->wmsArray); $i++) {
+		for ($i = 0; $i < count($wmsArray); $i++) {
 			// ..add wms and set properties
-			array_push($wmcJsArray, $this->wmsArray[$i]->createJsObjFromWMS_());
+			array_push($wmcJsArray, $wmsArray[$i]->createJsObjFromWMS_());
 		}
 
 		// delete existing map objects...
 		array_push($wmcJsArray, "mb_mapObj = [];");
 
-		// .. and add main map ..
-		$wmcJsArray = array_merge($wmcJsArray, $this->mainMap->createJsObj(null));
+		// .. and add the overview map (if exists)
+		if ($this->overviewMap !== null) {
+			// find the WMS in the main map which is equal to the WMS
+			// in the overview map
+			$ovWmsArray = $this->overviewMap->getWmsArray();
+			$overviewWmsIndex = 0;
+			for ($i = 0; $i < count($ovWmsArray); $i++) {
+				for ($j = 0; $j < count($wmsArray); $j++) {
+					if ($ovWmsArray[$i]->equals($wmsArray[$j])) {
+						$overviewWmsIndex = $j;						
+						break;
+					}
+				}
+			}
+			$wmcJsArray = array_merge($wmcJsArray, $this->overviewMap->createJsObj($overviewWmsIndex));
 
-		// .. and the overview map (if exists)
-		if ($this->overviewWmsIndex !== null) {
-			$wmcJsArray = array_merge($wmcJsArray, $this->overviewMap->createJsObj($this->overviewWmsIndex));
 		}
 
+		// .. and add main map ..
+		$wmcJsArray = array_merge($wmcJsArray, $this->mainMap->createJsObj(null));
+
 		// Finally, request the maps
 		array_push($wmcJsArray, "setMapRequest('" . $this->mainMap->getFrameName() . "');");
-		if ($this->overviewWmsIndex !== null) {
+		if ($this->overviewMap !== null) {
 			array_push($wmcJsArray, "setMapRequest('" . $this->overviewMap->getFrameName() . "');");
 		}
 		return $wmcJsArray;
@@ -839,295 +402,7 @@
 		return $this->toJavaScript();
 	}
 
-	
-	/**
-	 * Creates JS code manipulating the map and wms objects, 
-	 * by this displaying the WMC
-	 * 
-	 * @param string $target the link to the map object, f.e. "parent." or "window.opener."
-	 * @param string $mapObj the name of the map object, f.e. "mapframe1"
-	 * @param string $action "load", "merge" or "append"
-	 * 
-	 * @return string the JS code
-	 * @deprecated
-	 */
-	function createJsObjFromWMC($target, $mapObj, $action){
-		
-		// abort if action is not valid
-		$validActions = array("load", "merge", "append");
-		if (!in_array($action, $validActions)) {
-			return "alert('invalid action: ".$action."');";	
-		}
 
-		// counts how often a layer has been loaded
-		if ($this->monitoringIsOn) {
-			$monitor = new Layer_load_count();
-			for ($i = 0; $i < count($this->wmc_layer_id); $i++) {
-				$monitor->increment($this->wmc_layer_id[$i]);
-			}
-		}
-		
-		// will contain the JS code to create the maps
-		// representing the state stored in this WMC
-		$wmc_string = "";
-
-		// general extension
-		if (count($this->wmc_general_extension) > 0) {
-			$json = new Mapbender_JSON();
-			$wmc_string .= "restoredWmcExtensionData = " . $json->encode($this->wmc_general_extension) . ";\n"; 
-		}
-		
-/*
-		$wmc_string .= "var index = " . $target . "getMapObjIndexByName('" . $mapObj . "');\n";
-		if ($action == "load") {
-			// delete all previous wms
-			$wmc_string .= "while(" . $target . "mb_mapObj[index].wms.length > 0){" . $target . "mb_mapObjremoveWMS(index,0);}";
-			$wmc_string .= $target . "deleteWmsObject();\n";
-		}
-		if ($action == "merge") {
-			$wmc_string .= "var wms_exists = false;\n";				// true if this wms exists in the mapObj
-			$wmc_string .= "var current_wms_index = null;\n";		// if wms_exists: index of the wms in the map obj; else: null
-			$wmc_string .= "var layer_exists = false;\n";			// true if this layer exists in an existing wms of the mapObj
-			$wmc_string .= "var current_layer_index = null;\n";		// if layer_exists: index of the layer of the wms in the mapObj; else: null
-		}
-		$new_wms = "";
-		$cnt_wms = -1;
-		$added_wms = array();
-*/		
-
-		$foundWmsArray = array();
-		
-		// for all layers in wmc, find individual wms...
-		for ($i = 0; $i < count($this->wmc_layer_title); $i++) {
-			$currentWms = $this->wmc_wms_serviceURL[$i];
-
-			// skip this WMS if it has been found before
-			if (in_array($currentWms , $foundWmsArray)) {
-				continue;
-			}
-			
-			// mark this WMS as found
-			array_push($foundWmsArray, $currentWms);
-
-			$layerlist = "";
-			$querylayerlist = "";
-			$srs_array = array();
-
-			$mywms = new wms();
-/*	
-	  		if(!$this->wmc_layer_title[$i] || $this->wmc_layer_title[$i] == ""){
-				echo "alert('Error: no valid capabilities-document !!');\n";
-				die; exit;
-			}
-*/
-			
-			$wmc_addWMS_string = $this->getJsCodeAddWms($i);
-
-/*
-			$cnt_wms++;
-			$cnt_layers = 0;
-			$cnt_query_layers = 0;
-*/
-
-			// When merging, add this WMS only if it is not already loaded in the application
-			if ($action == "merge") {
-				$wmc_string .=  "wms_exists = false;\n" . 
-								"current_wms_index = null;\n" . 
-								"for (var m=0; m < " . $target . "mb_mapObj[index].wms.length; m++) {\n" . 
-									"\tif ('" . $this->wmc_wms_serviceURL[$i] . "' ==  " . $target . "mb_mapObj[index].wms[m].wms_getmap) {\n" . 
-										"\t\twms_exists = true;\n" . 
-										"\t\tcurrent_wms_index = m;\n" . 
-									"\t}\n" . 
-								"}\n" . 
-								"if (!wms_exists) {\n" . 
-									$wmc_addWMS_string . 
-								"}\n";
-			}
-			else {
-				$wmc_string .= $wmc_addWMS_string;
-			}
-
-			// add epsg
-			$wmc_string .= $this->createJsCodeAddWmsSrs();
-
-			// for each layer...
-			for ($ii = 0; $ii < count($this->wmc_layer_title); $ii++) {
-				$layer_wms = $this->wmc_wms_serviceURL[$ii];
-				// ... of this wms
-				if ($current_wms == $layer_wms) {
-					
-					// add format (FIXME: is this working?)
-					$wmc_string .= $this->getJsCodeAddLayerDataFormat($ii);
-					
-					// add root layer
-					if ($cnt_layers == 0) {
-						$wmc_addLayer_string = $this->getJsCodeAddRootLayer($i);
-
-						if ($action == "merge") {
-							$wmc_string .=  "if (!wms_exists) {\n\t" . 
-												$wmc_addLayer_string . 
-											"}\n";
-						} 
-						else {
-							$wmc_string .= $wmc_addLayer_string;
-						}
-					}
-					$cnt_layers++;
-					
-					// add other layers
-					$wmcAddLayerString = $this->getJsCodeAddLayer ($cnt_layers, $i, $ii);
-					
-					if ($action == "merge") {
-						$wmc_string .= "if (wms_exists) {\n";
-						
-						// check if this layer already exists in this wms
-						$wmc_string .=  "\tlayer_exists = false;\n" . 
-										"\tcurrent_layer_index = null;\n" . 
-										"\tfor (var m=0; m < mb_mapObj[index].wms[current_wms_index].objLayer.length; m++) {\n" . 
-											"\t\tif ('" . $this->wmc_layer_name[$ii] . "' == mb_mapObj[index].wms[current_wms_index].objLayer[m].layer_name) {\n" . 
-												"\t\t\tlayer_exists = true;\n" . 
-												"\t\t\tcurrent_layer_index = m;\n" . 
-											"\t\t}\n" . 
-										"\t}\n"; 
-
-						if ($this->wmc_layer_querylayer[$ii] != "") {
-							$querylayer_yn = $this->wmc_layer_querylayer[$ii];
-						}
-						else {
-							$querylayer_yn = $this->wmc_layer_queryable[$ii];
-						}			
-
-						$wmc_string .= "\tif (layer_exists) {\n";
-
-						// check if the visibility or the queryability are different to the existing layer
-						$wmc_string .=  	"\t\tif (mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_visible != '" . intval(!$this->wmc_layer_hidden[$ii]) . "'" . 
-											" || mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_querylayer != '" . $querylayer_yn . "') {\n";
-
-						// if yes, update the visibility and queryability
-						$wmc_string .= 			"\t\t\tmb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_visible = " . intval(!$this->wmc_layer_hidden[$ii]) . ";\n" .
-												"\t\t\tmb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_querylayer = " . $querylayer_yn . ";\n" .
-											"\t\t}\n" .
-										"\t}\n" . 
-									"}\n" . 
-									"\telse {\n" . 
-										$wmcAddLayerString . 
-									"\t}\n";
-					}
-					else {
-						$wmc_string .= $wmcAddLayerString;
-					} 
-
-/*										
-					// if layer is queryable, add it to querylayerlist
-					if (($this->wmc_layer_querylayer[$ii] != "" ? $this->wmc_layer_querylayer[$ii] : $this->wmc_layer_queryable[$ii])) {
-						$cnt_query_layers++;
-						$isAlreadyInList = !in_array($this->wmc_layer_name[$ii], explode(",",$querylayerlist));
-						if (!$isAlreadyInList) {
-							if ($querylayerlist != "") {
-								$querylayerlist .= ",";
-							} 
-							$querylayerlist .= $this->wmc_layer_name[$ii];
-						}
-					}
-					// if layer is visible, add it to layerlist 
-					$isAlreadyInList = in_array($this->wmc_layer_name[$ii], explode(",", $layerlist));
-					$isVisible = intval(!$this->wmc_layer_hidden[$ii]);
-					if (!$isAlreadyInList && $isVisible) {
-						if ($layerlist != "") {
-							$layerlist .= ",";
-						} 
-						$layerlist .= $this->wmc_layer_name[$ii];
-					}
-*/
-					// add layer style (FIXME: is this working?)
-					$wmc_string .= $this->getJsCodeAddLayerStyle($cnt_layers, $ii);
-				}
-
-				// add wms to mapObj with all layers and querylayers
-/*
-				$wmc_addWMSwithLayers_string = $target. "mb_mapObjaddWMSwithLayers('" . $mapObj . "', '" . $layerlist . "', '" . $querylayerlist . "');\n";
-				if ($action == "merge") {
-					$wmc_string .=  "if (!wms_exists) {\n" . 
-										$wmc_addWMSwithLayers_string . 
-									"}\n" . 
-									"else {\n" . 
-										"mb_mapObj[index].layers[current_wms_index] = \"" . $layerlist . "\";\n" . 
-										"mb_mapObj[index].querylayers[current_wms_index] = \"" . $querylayerlist . "\";\n" . 
-									"}\n";
-				}
-				else {
-					$wmc_string .= $wmc_addWMSwithLayers_string;
-				}
-*/
-			}
-		}
-		$wmc_string .= "var old_mapObj = ".$target."cloneObject(".$target."mb_mapObj);\n";
-		$wmc_string .= $target . "deleteMapObj();\n";
-		$wmc_string .= "for (var i=0; i<old_mapObj.length; i++) {\n";
-		$wmc_string .= "\tif (old_mapObj[i].frameName != 'overview') {\n";
-		$wmc_string .= "\t\t" . $target . "mb_registerMapObj(old_mapObj[i].frameName, old_mapObj[i].elementName, null, " . $this->wmc_windowWidth . ", " . $this->wmc_windowHeight . ");\n"; 
-		$wmc_string .= "\t\t" . $target . "document.getElementById(old_mapObj[i].frameName).style.width = " . $this->wmc_windowWidth . ";\n";
-		$wmc_string .= "\t\t" . $target . "document.getElementById(old_mapObj[i].frameName).style.height = " . $this->wmc_windowHeight . ";\n";
-		$wmc_string .= "\t}\n";
-		$wmc_string .= "\telse {\n";
-		$wmc_string .= "\t\tvar found = false;\n";
-		$wmc_string .= "\t\tfor (var j=0; j < " . $target . "wms.length && found == false; j++) {\n";
-		$wmc_string .= "\t\t\tif (" . $target . "wms[j].wms_getmap == old_mapObj[i].wms[0].wms_getmap) {\n";
-		$wmc_string .= "\t\t\t\t" . $target . "mb_registerMapObj('overview', old_mapObj[i].elementName, j, " . $this->wmc_general_extension["ov_width"] . ", " . $this->wmc_general_extension["ov_height"] . ");\n"; 
-		$wmc_string .= "\t\t\t\tfound = true;\n"; 
-		$wmc_string .= "\t\t\t}\n";
-		$wmc_string .= "\t\t}\n";
-		$wmc_string .= "\t\tif (!found) {\n";
-		$wmc_string .= "\t\t\t" . $target . "mb_registerMapObj('overview', old_mapObj[i].elementName, 0, old_mapObj[i].width,  old_mapObj[i].width);\n"; 
-		$wmc_string .= "\t\t}\n";
-		$wmc_string .= "\t}\n";
-		$wmc_string .= "}\n";
-		
-		$ov_bbox = array();
-
-		// 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));
-			
-		}
-		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); 				
-		
-
-		$wmc_string .= "for (var i=0; i<old_mapObj.length; i++) {\n";
-		$wmc_string .= "\tif (old_mapObj[i].frameName != 'overview') {\n";
-		$wmc_string .= "\t\t".$target."mb_calculateExtent(old_mapObj[i].frameName, ";
-		$wmc_string .= $this->wmc_bBox_minx .",".$this->wmc_bBox_miny .",";
-		$wmc_string .= $this->wmc_bBox_maxx .",".$this->wmc_bBox_maxy.");\n";
-		$wmc_string .= "\t}\n";
-		$wmc_string .= "\telse {\n";
-		$wmc_string .= "\t\t".$target."mb_calculateExtent(old_mapObj[i].frameName, ";
-		$wmc_string .= $ov_bbox[0] .",".$ov_bbox[1] .",";
-		$wmc_string .= $ov_bbox[2] .",".$ov_bbox[3] .");\n";
-		$wmc_string .= "\t}\n";
-		$wmc_string .= "\t". $target . "setMapRequest(old_mapObj[i].frameName);\n";
-		$wmc_string .= "}\n";
-		$wmc_string .= $target . "mb_execloadWmsSubFunctions();\n";
-		return $wmc_string;
-	}
-
 // ---------------------------------------------------------------------------
 // private functions
 // ---------------------------------------------------------------------------
@@ -1157,7 +432,6 @@
 		//
 		$this->mainMap = new Map();
 		$this->overviewMap = null;
-		$this->wmsArray = array();
 		$this->generalExtensionArray = array();
 		
 		$layerlistArray = array();
@@ -1385,13 +659,6 @@
 						 }
 					 }
 					 elseif ($stylelist) {
-						 if ($tag == "STYLE" && $type == "open") {
-						 	$style = true;
-						 	array_push($currentLayer["style"], array("current" => $attributes["current"]));
-							if ($attributes["current"] == "1") {
-								$currentLayer["styleIndex"] = count($currentLayer) - 1;
-							}
-						 }
 						 if ($style) {
 							$index = count($currentLayer["style"]) - 1;
 							if ($tag == "STYLE" && $type == "close") {
@@ -1419,12 +686,6 @@
 								if ($tag == "TITLE") {
 									$currentLayer["style"][$index]["title"] = $value;
 								}
-								if ($tag == "LEGENDURL" && $type == "open") {
-								 	$legendurl = true;
-								 	$currentLayer["style"][$index]["legendurl_width"] = $attributes["width"];
-								 	$currentLayer["style"][$index]["legendurl_height"] = $attributes["height"];
-								 	$currentLayer["style"][$index]["legendurl_format"] = $attributes["format"];
-								}
 								if ($legendurl) {
 									if ($tag == "LEGENDURL" && $type == "close") {
 										$legendurl = false;
@@ -1434,8 +695,21 @@
 									 	$currentLayer["style"][$index]["legendurl"] = $attributes["xlink:href"];
 									}
 								}
+								if ($tag == "LEGENDURL" && $type == "open") {
+								 	$legendurl = true;
+								 	$currentLayer["style"][$index]["legendurl_width"] = $attributes["width"];
+								 	$currentLayer["style"][$index]["legendurl_height"] = $attributes["height"];
+								 	$currentLayer["style"][$index]["legendurl_format"] = $attributes["format"];
+								}
 							}
 						}
+						if ($tag == "STYLE" && $type == "open") {
+							$style = true;
+							array_push($currentLayer["style"], array("current" => $attributes["current"]));
+							if ($attributes["current"] == "1") {
+								$currentLayer["styleIndex"] = count($currentLayer["style"]) - 1;
+							}
+						}
 						if ($tag == "STYLELIST" && $type == "close") {
 							$stylelist = false;
 						}
@@ -1536,11 +810,16 @@
 	 * @param $currentLayer Array an associative array with layer data
 	 */
 	private function setLayerData ($currentLayer) {
-		if ($currentLayer["extension"]["ISOVERVIEWLAYER"] == "1" &&
-			$this->overviewWmsIndex !== null) {
-			return;
+		$currentMap = $this->mainMap;
+		$currentMapIsOverview = false;
+
+		if ($currentLayer["extension"]["ISOVERVIEWLAYER"] == "1") {
+			$currentMap = $this->overviewMap;
+			$currentMapIsOverview = true;
 		}
 
+		$wmsArray = $currentMap->getWmsArray();
+
 		//
 		// check if current layer belongs to an existing WMS.
 		// If yes, store the index of this WMS in $wmsIndex.
@@ -1549,9 +828,9 @@
 		$wmsIndex = null;
 
 		// find last WMS with the same online resource
-		for ($i = count($this->wmsArray) - 1; $i >= 0; $i--) {
+		for ($i = count($wmsArray) - 1; $i >= 0; $i--) {
 			if (isset($currentLayer["url"]) && 
-				$currentLayer["url"] == $this->wmsArray[$i]->wms_getmap) {
+				$currentLayer["url"] == $wmsArray[$i]->wms_getmap) {
 					$wmsIndex = $i;
 					break;
 			}
@@ -1564,11 +843,7 @@
 
 			// 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;
+			if ($currentMapIsOverview) {
 				return;
 			}
 
@@ -1604,6 +879,7 @@
 			$wms->wms_getfeatureinfo = $currentLayer["url"]; // TODO : Add correct data
 			
 			$styleIndex = $currentLayer["styleIndex"];
+			$e = new mb_notice("StyleIndex: " . $styleIndex);
 			$wms->wms_getlegendurl = $currentLayer["style"][$styleIndex]["legendurl"];
 
 			$wms->wms_filter = ""; // TODO : Add correct data
@@ -1618,6 +894,7 @@
 			$wms->gui_wms_opacity = 100; // TODO : Add correct data
 			$wms->gui_wms_sldurl = $currentLayer["style"][$styleIndex]["sld_url"];
 
+			$wms->gui_epsg = $currentLayer["epsg"];
 			//
 			// set data formats
 			//
@@ -1626,77 +903,34 @@
 				array_push($wms->data_format, $currentLayer["format"][$i]["name"]);							
 			}
 
-			//
-			// set wms epsg
-			//
-			$layerEpsgIndex = count($newLayer->objLayer[$i]->layer_epsg) - 1;
-			$currentLayerEpsg = $newLayer->objLayer[$i]->layer_epsg[$layerEpsgIndex];
-			$currentLayerEpsg["epsg"] = $this->mainMap->getEpsg();
-			$mainMapExtent = $this->mainMap->getExtent();
-			$currentLayerEpsg["minx"] = $mainMapExtent->min->x;
-			$currentLayerEpsg["miny"] = $mainMapExtent->min->y; 
-			$currentLayerEpsg["maxx"] = $mainMapExtent->max->x;
-			$currentLayerEpsg["maxy"] = $mainMapExtent->max->y;
+			// set root layer
+			$wms->addLayer(0, "");
+			$wms->objLayer[0]->layer_uid = $currentLayer["extension"]["WMS_LAYER_ID"];
+			$wms->objLayer[0]->layer_name = $currentLayer["wms_title"];
+			$wms->objLayer[0]->layer_pos = 0;
+			$wms->objLayer[0]->layer_queryable = 0;
+			$wms->objLayer[0]->layer_minscale = 0;
+			$wms->objLayer[0]->layer_maxscale = 0;
+			$wms->objLayer[0]->gui_layer_wms_id = $currentLayer["extension"]["WMS_LAYER_ID"];
+			$wms->objLayer[0]->gui_layer_status = 1;
+			$wms->objLayer[0]->gui_layer_selectable = 1; 
+			$wms->objLayer[0]->gui_layer_visible = 1;
+			$wms->objLayer[0]->gui_layer_queryable = 0;
+			$wms->objLayer[0]->gui_layer_querylayer = 0;
+			$wms->objLayer[0]->gui_layer_minscale = 0;
+			$wms->objLayer[0]->gui_layer_maxscale = 0;
 
-			array_push($this->wmsArray, $wms);
-			$wmsIndex = count($this->wmsArray) - 1;
-		}
-		// add layer to existing WMS ...
-		$currentWms = $this->wmsArray[$wmsIndex];
-		$pos = $currentLayer["extension"]["LAYER_POS"];
-		$parent = $currentLayer["extension"]["LAYER_PARENT"];
-		$currentWms->addLayer($pos, $parent); // TO DO: how about WMC from other sources
+			// add WMS
+			array_push($wmsArray, $wms);
 
-		// set layer data
-		$layerIndex = count($currentWms->objLayer) - 1;
-		$newLayer = $currentWms->objLayer[$layerIndex];
-		$newLayer->layer_uid = $currentLayer["extension"]["LAYER_ID"];
-		$newLayer->layer_name = $currentLayer["name"];
-		$newLayer->layer_title = $currentLayer["title"];
-		$newLayer->layer_dataurl_href = $currentLayer["dataurl"];
-		$newLayer->layer_pos = $currentLayer["extension"]["LAYER_POS"];
-		$newLayer->layer_queryable = $currentLayer["queryable"];
-		$newLayer->layer_minscale = $currentLayer["extension"]["MINSCALE"];
-		$newLayer->layer_maxscale = $currentLayer["extension"]["MAXSCALE"];
-		$newLayer->layer_metadataurl = $currentLayer["metadataurl"];
-		$newLayer->gui_layer_wms_id = $currentLayer["extension"]["WMS_LAYER_ID"];
-		$newLayer->gui_layer_status = 1; // TODO: Add correct data
-		$newLayer->gui_layer_style = ""; // TODO: Add correct data
-		$newLayer->gui_layer_selectable = ""; // TODO: Add correct data
-		$newLayer->gui_layer_visible = $currentLayer["visible"];
-		$newLayer->gui_layer_queryable = ""; // TODO: Add correct data
-		$newLayer->gui_layer_querylayer = ""; // TODO: Add correct data
-		$newLayer->gui_layer_minscale = $currentLayer["extension"]["GUI_MINSCALE"];
-		$newLayer->gui_layer_maxscale = $currentLayer["extension"]["GUI_MAXSCALE"];
-		$newLayer->gui_layer_wfs_featuretype = ""; // TODO: Add correct data
-		$newLayer->layer_abstract = $currentLayer["abstract"];
-
-		//
-		// set layer epsg
-		//
-		$layerEpsgIndex = count($newLayer->objLayer[$i]->layer_epsg) - 1;
-
-		$currentLayerEpsg = $newLayer->objLayer[$i]->layer_epsg[$layerEpsgIndex];
-		$currentLayerEpsg["epsg"] = $this->mainMap->getEpsg();
-
-		$mainMapExtent = $this->mainMap->getExtent();
-		$currentLayerEpsg["minx"] = $mainMapExtent->min->x;
-		$currentLayerEpsg["miny"] = $mainMapExtent->min->y; 
-		$currentLayerEpsg["maxx"] = $mainMapExtent->max->x;
-		$currentLayerEpsg["maxy"] = $mainMapExtent->max->y;
-
-		//
-		// set layer style
-		//
-		for ($i = 0; $i < count($currentLayer["format"]); $i++) {
-			$layerStyleIndex = count($newLayer->gui_layer_style) - 1;
-			$newLayer->layer_style[$layerStyleIndex] = array();
-			$currentStyle = $newLayer->layer_style[$layerStyleIndex];
-			$currentStyle["name"] = $currentLayer["style"][$i]["name"];
-			$currentStyle["title"] = $currentLayer["style"][$i]["title"];
-			$currentStyle["legendurl"] = $currentLayer["style"][$i]["legendurl"];
-			$currentStyle["legendurl_format"] = $currentLayer["style"][$i]["legendurl_type"];
+			// the index of the WMS we just added
+			$wmsIndex = count($wmsArray) - 1;
 		}
+
+		// add layer to existing WMS ...
+		$currentWms = $wmsArray[$wmsIndex];
+		$currentWms->newLayer($currentLayer);
+		$currentMap->setWmsArray($wmsArray);
 		return true;
 	}
 	
@@ -1731,6 +965,17 @@
 		}
 		return true;
 	}
+
+	/**
+	 * 
+	 * @return 
+	 */
+	private function createXml() {
+		$wmcToXml = new WmcToXml($this);
+		$this->xml = $wmcToXml->getXml();
+	}
+
+	
 } 
 
 /**

Added: branches/beck_dev/mapbender/http/classes/class_wmcToXml.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_wmcToXml.php	                        (rev 0)
+++ branches/beck_dev/mapbender/http/classes/class_wmcToXml.php	2008-05-21 15:38:21 UTC (rev 2468)
@@ -0,0 +1,535 @@
+<?php
+# $Id: class_wmc.php 2466 2008-05-20 08:55:03Z christoph $
+# http://www.mapbender.org/index.php/class_wmc.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+/**
+ * The XML representation of a WMC object.
+ * 
+ * Usage:
+ * 
+ * $wmcToXml = new WmcToXml($wmc);
+ * $xml = $wmcToXml->getXml();
+ * 
+ */
+class WmcToXml {
+
+	private $wmc = null;
+	private $doc;
+	private $xml = "";
+	
+	/**
+	 * Constructor. Computes the XML of the WMC object given as parameter.
+	 * 
+	 * @param $someWmc wmc
+	 */
+	public function __construct ($someWmc) {
+		$this->wmc = $someWmc;
+		$this->toXml();
+	} 
+
+	// ---------------------------------------------------------------------
+	// public functions
+	// ---------------------------------------------------------------------
+	
+	public function getXml () {
+		return $this->xml;
+	}
+	
+	// ---------------------------------------------------------------------
+	// private functions
+	// ---------------------------------------------------------------------
+	
+	private function toXml () {
+
+		// add main map and overview (if exists) to $mapArray
+		$mapArray = array($this->wmc->mainMap);
+		if ($this->wmc->overviewMap !== null) {
+			array_push($mapArray, $this->wmc->overviewMap);
+		}
+
+		// generate XML
+		$this->doc = new DOMDocument("1.0", CHARSET);
+		$this->doc->preserveWhiteSpace = false;
+		
+		// ViewContext
+		$e_view_context = $this->doc->createElementNS("http://www.opengis.net/context", "ViewContext");
+		$e_view_context->setAttribute("version", "1.1.0");
+		$e_view_context->setAttribute("id", $this->wmc->wmc_id);
+		$e_view_context->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+		$e_view_context->setAttribute("xmlns:" . $this->wmc->extensionNamespace, $this->wmc->extensionNamespaceUrl);
+		$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");
+		
+		// General
+		$e_general = $this->createGeneralNode();	
+		if ($e_general !== null) {
+			$e_view_context->appendChild($e_general);
+		}	
+		
+		// Layerlist
+		$e_layer_list = $this->doc->createElement("LayerList");
+		while (count($mapArray) > 0) {
+			
+			$currentMap = array_pop($mapArray);
+			$currentWmsArray = $currentMap->getWmsArray();
+	
+			for ($i = 0; $i < count($currentWmsArray); $i++) {
+				$currentWms = $currentWmsArray[$i];
+				
+				for ($j = 0; $j < count($currentWms->objLayer); $j++) {
+					$currentLayer = $currentWms->objLayer[$j];
+					
+					$layerNode = $this->createLayerNode($currentMap, $currentWms, $currentLayer);
+					if ($layerNode !== null) {
+						$e_layer_list->appendChild($layerNode);
+					}
+				}
+			}
+		}
+		$e_view_context->appendChild($e_layer_list);
+
+		$this->doc->appendChild($e_view_context);
+		$this->xml = $this->doc->saveXML();
+	}
+
+	private function createGeneralNode () {
+		if ($this->wmc->overviewMap !== null) {
+			$ovExtent = $this->wmc->overviewMap->getExtent();
+			$extensionData->ov_minx = $ovExtent->min->x;
+			$extensionData->ov_miny = $ovExtent->min->y;
+			$extensionData->ov_maxx = $ovExtent->max->x;
+			$extensionData->ov_maxy = $ovExtent->max->y;
+			$extensionData->ov_srs = $ovExtent->epsg;
+			$extensionData->ov_framename = $this->wmc->overviewMap->getFrameName();
+			$extensionData->ov_width = $this->wmc->overviewMap->getWidth();
+			$extensionData->ov_height = $this->wmc->overviewMap->getHeight();
+		}
+				
+		// General
+		$e_general = $this->doc->createElement("General");
+		
+		// Window
+		$e_window = $this->doc->createElement("Window");
+		if ($this->wmc->mainMap->getWidth() && $this->wmc->mainMap->getHeight()) {
+			$e_window->setAttribute("width", $this->wmc->mainMap->getWidth());
+			$e_window->setAttribute("height", $this->wmc->mainMap->getHeight());
+		}
+		$e_general->appendChild($e_window);
+		
+		// BoundingBox
+		$mainExtent = $this->wmc->mainMap->getExtent();
+		$e_bbox = $this->doc->createElement("BoundingBox");
+		$e_bbox->setAttribute("SRS", $mainExtent->epsg);
+		$e_bbox->setAttribute("minx", $mainExtent->min->x);
+		$e_bbox->setAttribute("miny", $mainExtent->min->y);
+		$e_bbox->setAttribute("maxx", $mainExtent->max->x);
+		$e_bbox->setAttribute("maxy", $mainExtent->max->y);
+		$e_general->appendChild($e_bbox);
+				
+		// Name
+		$e_name = $this->doc->createElement("Name", $this->wmc->wmc_name);
+		$e_general->appendChild($e_name);
+				
+		// Title
+		$e_title = $this->doc->createElement("Title", $this->wmc->wmc_title);
+		$e_general->appendChild($e_title);
+				
+		// Keywords
+		$e_keyword_list = $this->doc->createElement("KeywordList");
+		for ($i=0; $i < count($this->wmc->wmc_keyword); $i++) {
+			$e_keyword = $this->doc->createElement("Keyword", $this->wmc->wmc_keyword[$i]);
+			$e_keyword_list->appendChild($e_keyword);
+		}
+		$e_general->appendChild($e_keyword_list);
+				
+		// Abstract
+		if ($this->wmc->wmc_abstract) {
+			$e_abstract = $this->doc->createElement("Abstract", $this->wmc->wmc_abstract);
+			$e_general->appendChild($e_abstract);
+		}
+	
+		// Logo URL			
+		if ($this->wmc->wmc_logourl_width && $this->wmc->wmc_logourl_height && 
+			$this->wmc->wmc_logourl_format && $this->wmc->wmc_logourl){
+			
+			$e_logo_url = $this->doc->createElement("LogoURL");
+			$e_logo_url->setAttribute("width", $this->wmc->wmc_logourl_width);
+			$e_logo_url->setAttribute("height", $this->wmc->wmc_logourl_height);
+			$e_logo_url->setAttribute("format", $this->wmc->wmc_logourl_format);
+		
+			$e_logo_url_or = $this->doc->createElement("OnlineResource");
+			$e_logo_url_or->setAttributeNS("http://www.opengis.net/context", "xmlns:xlink", "http://www.w3.org/1999/xlink");
+			$e_logo_url_or->setAttribute("xlink:type", "simple");
+			$e_logo_url_or->setAttribute("xlink:href", $this->wmc->wmc_logourl);
+			$e_logo_url->appendChild($e_logo_url_or);
+
+			$e_general->appendChild($e_logo_url);
+		}
+				
+		// Description URL	
+		if ($this->wmc->wmc_descriptionurl){
+			$e_description_url = $this->doc->createElement("DescriptionURL");
+
+			$e_description_url_or = $this->doc->createElement("OnlineResource");
+			$e_description_url_or->setAttributeNS("http://www.opengis.net/context", "xmlns:xlink", "http://www.w3.org/1999/xlink");
+			$e_description_url_or->setAttribute("xlink:type", "simple");
+			$e_description_url_or->setAttribute("xlink:href", $this->wmc->wmc_descriptionurl);
+			$e_description_url->appendChild($e_description_url_or);
+
+			$e_general->appendChild($e_description_url);
+		}
+				
+		// Contact information
+		$e_contact = $this->createContactInformationNode();
+		if ($e_contact !== null) {
+			$e_general->appendChild($e_contact);
+		}
+
+		// Extension data				
+		if (count($extensionData) > 0) {
+			$e_extensionGeneral = $this->doc->createElement("Extension");
+			
+			foreach ($extensionData as $keyExtensionData => $valueExtensionData) {
+				$e_currentExtensionTag = $this->doc->createElement($this->wmc->extensionNamespace.":".$keyExtensionData, $valueExtensionData);
+				$e_extensionGeneral->appendChild($e_currentExtensionTag);
+			}
+			$e_general->appendChild($e_extensionGeneral);
+		}
+		return $e_general;
+	}
+	
+	private function createLayerNode ($currentMap, $currentWms, $currentLayer) {
+		if ($currentLayer->layer_parent != '') {
+
+			// Layer
+			$e_layer = $this->doc->createElement("Layer");
+			$e_layer->setAttribute("queryable", $currentLayer->layer_queryable);
+			$e_layer->setAttribute("hidden", ($currentLayer->gui_layer_visible ? 0 : 1));
+
+			// Server
+			$e_service = $this->doc->createElement("Server");
+			$e_service->setAttribute("service", "OGC:WMS");
+			$e_service->setAttribute("version", $currentWms->wms_version);
+			$e_service->setAttribute("title", $currentWms->wms_title);
+
+			// Online resource
+			$e_service_or = $this->doc->createElement("OnlineResource");
+			$e_service_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+			$e_service_or->setAttribute("xlink:type", "simple");
+			$e_service_or->setAttribute("xlink:href", $currentWms->wms_getmap);
+			$e_service->appendChild($e_service_or);
+			$e_layer->appendChild($e_service);
+
+			// Name
+			$e_layer_name = $this->doc->createElement("Name", $currentLayer->layer_name);
+			$e_layer->appendChild($e_layer_name);
+
+			// Title
+			$e_layer_title = $this->doc->createElement("Title", $currentLayer->layer_title);
+			$e_layer->appendChild($e_layer_title);
+
+			// Abstract
+			if ($currentWms->wms_abstract){
+				$e_layer_abstract = $this->doc->createElement("Abstract", $currentWms->wms_abstract);
+				$e_layer->appendChild($e_layer_abstract);
+			}
+
+			// SRS		
+			$srsNode = $this->createSrsNode($currentMap, $currentWms);
+			if ($srsNode !== null) {
+				$e_layer->appendChild($srsNode);
+			}
+	
+			// Data URL
+			if ($currentLayer->layer_dataurl_href){
+				$e_layer_data_url = $this->doc->createElement("DataURL");
+	
+				$e_layer_data_url_or = $this->doc->createElement("OnlineResource");
+				$e_layer_data_url_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+				$e_layer_data_url_or->setAttribute("xlink:type", "simple");
+				$e_layer_data_url_or->setAttribute("xlink:href", $currentLayer->layer_dataurl_href);
+				
+				$e_layer_data_url->appendChild($e_layer_data_url_or);
+				$e_layer->appendChild($e_layer_data_url);
+			}
+
+			// Metadata URL
+			if ($currentLayer->layer_metadataurl){
+				$e_layer_metadata_url = $this->doc->createElement("MetadataURL");
+
+				// Metadata URL online resource
+				$e_layer_metadata_url_or = $this->doc->createElement("OnlineResource");
+				$e_layer_metadata_url_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+				$e_layer_metadata_url_or->setAttribute("xlink:type", "simple");
+				$e_layer_metadata_url_or->setAttribute("xlink:href", $currentLayer->layer_metadataurl);
+				$e_layer_metadata_url->appendChild($e_layer_metadata_url_or);
+				$e_layer->appendChild($e_layer_metadata_url);
+			}
+
+			// Layer format
+			$formatListNode = $this->createLayerFormatListNode($currentWms);
+			if ($formatListNode !== null) {
+				$e_layer->appendChild($formatListNode);
+			}
+
+			// Layer style
+			$layerStyleListNode = $this->createLayerStyleNode($currentWms, $currentLayer);
+			if ($layerStyleListNode !== null) {
+				$e_layer->appendChild($layerStyleListNode);
+			}
+
+			// Extension
+			$extensionNode = $this->createLayerExtensionNode($currentMap, $currentWms, $currentLayer);
+			if ($extensionNode !== null) {
+				$e_layer->appendChild($extensionNode);
+			}
+
+			return $e_layer;
+		}
+		return null;	
+	}
+
+	private function createSrsNode ($currentMap, $currentWms) {
+		$wms_epsg = array();
+		$wms_epsg[0] = $currentMap->getEpsg();
+	
+		if ($currentWms->gui_wms_epsg != $currentMap->getEpsg()) {
+			$wms_epsg[1] = $currentWms->gui_wms_epsg;
+		}
+
+		for ($j = 0; $j < count($currentWms->gui_epsg); $j++) {
+			if (!in_array($currentWms->gui_epsg[$j], $wms_epsg)){
+				array_push($wms_epsg, $currentWms->gui_epsg[$j]);
+			}
+		}
+
+		$e_layer_srs = $this->doc->createElement("SRS", implode(" ", $wms_epsg));
+		return $e_layer_srs;
+	}
+
+	private function createLayerFormatListNode ($currentWms) {
+		$e_layer_format = $this->doc->createElement("FormatList");
+
+		$data_format_current = false;
+		
+		for ($k = 0; $k < count($currentWms->data_format); $k++){
+
+			if ($currentWms->data_type[$k] == "map") {
+				$layerFormat = $currentWms->data_format[$k];
+
+				$e_format = $this->doc->createElement("Format", $layerFormat);
+
+				if ($data_format_current === false && ( 
+						$currentWms->data_format[$k] == $currentWms->gui_wms_mapformat ||
+						$k == (count($currentWms->data_format)-1)
+				)){
+
+					$e_format->setAttribute("current", "1");
+					$data_format_current = true;
+				}
+				$e_layer_format->appendChild($e_format);
+			}
+		}
+		return $e_layer_format;
+	}
+
+	private function createLayerExtensionNode ($currentMap, $currentWms, $currentLayer) {
+		$layerExtensionData = array();
+		$layerExtensionData["minscale"] = $currentLayer->layer_minscale;
+		$layerExtensionData["maxscale"] = $currentLayer->layer_maxscale;
+		$layerExtensionData["gui_minscale"] = $currentLayer->gui_layer_minscale;
+		$layerExtensionData["gui_maxscale"] = $currentLayer->gui_layer_maxscale;
+		$layerExtensionData["layer_id"] = $currentLayer->layer_uid;
+		$layerExtensionData["wms_layer_id"] = $currentWms->objLayer[0]->layer_uid;
+		$layerExtensionData["layer_pos"] = $currentLayer->layer_pos;
+		$layerExtensionData["layer_parent"] = $currentLayer->layer_parent;
+		$layerExtensionData["wms_id"] = $currentWms->wms_id;
+		$layerExtensionData["querylayer"] = $currentLayer->gui_layer_querylayer;
+		$layerExtensionData["gui_selectable"] = $currentLayer->gui_layer_selectable;
+		$layerExtensionData["gui_queryable"] = $currentLayer->gui_layer_queryable;
+		$layerExtensionData["gui_status"] = $currentLayer->gui_layer_status;
+		if ($currentMap->isOverview()) {
+			$layerExtensionData["isOverviewLayer"] = 1;
+		}
+		if ($currentLayer->gui_layer_wfs_featuretype) {
+			$layerExtensionData["wfsFeatureType"] = $currentLayer->gui_layer_wfs_featuretype;
+		}
+
+		if (count($layerExtensionData) > 0) {
+			$e_extension = $this->doc->createElement("Extension");
+			
+			foreach ($layerExtensionData as $keyExtensionData => $valueExtensionData) {
+				$e_currentExtensionTag = $this->doc->createElement($this->wmc->extensionNamespace.":".$keyExtensionData, $valueExtensionData);
+				$e_extension->appendChild($e_currentExtensionTag);
+			}
+			return $e_extension;
+		}
+		return null;
+	}
+	
+	private function createLayerStyleNode ($currentWms, $currentLayer) {
+		$e_layer_stylelist = $this->doc->createElement("StyleList");
+		
+		for ($k = 0; $k < count($currentLayer->layer_style); $k++) {
+
+			$currentStyle = $currentLayer->layer_style[$k];
+			
+			$layerStyle_current = 0;
+			if ($k === 0){
+				$layerStyle_current = 1; // To do: insert proper data
+			}
+
+			$e_layer_style = $this->doc->createElement("Style");
+
+			$layerStyleSLD = "";
+
+			if ($layerStyleSLD) {
+				$e_layer_style_or = $this->doc->createElement("OnlineResource");
+				$e_layer_style_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+				$e_layer_style_or->setAttribute("xlink:type", "simple");
+				$e_layer_style_or->setAttribute("xlink:href", $currentWms->gui_wms_sldurl);
+				$e_layer_style->appendChild($e_layer_style_or);
+			}
+			else{
+				
+				if ($layerStyle_current == 1){
+					$e_layer_style->setAttribute("current", "1");
+				}
+
+				$e_layer_style_name = $this->doc->createElement("Name", $currentStyle->name);
+				$e_layer_style->appendChild($e_layer_style_name);
+
+				$e_layer_style_title = $this->doc->createElement("Title", $currentStyle->title);
+				$e_layer_style->appendChild($e_layer_style_title);
+				
+				
+				$e_layer_style_legendurl = $this->doc->createElement("LegendUrl");
+
+				//TODO: determine correct layer style entries
+				$layerStyle_legendUrl_width = ""; // To Do: add proper data
+				$layerStyle_legendUrl_height = ""; // To Do: add proper data
+				$layerStyle_legendUrl_format = ""; // To Do: add proper data
+				$e_layer_style_legendurl->setAttribute("width", $layerStyle_legendUrl_width);
+				$e_layer_style_legendurl->setAttribute("height", $layerStyle_legendUrl_height);
+				$e_layer_style_legendurl->setAttribute("format", $layerStyle_legendUrl_format);
+
+				$e_layer_style_legendurl_or = $this->doc->createElement("OnlineResource");
+				$e_layer_style_legendurl_or->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+				$e_layer_style_legendurl_or->setAttribute("xlink:type", "simple");
+				$e_layer_style_legendurl_or->setAttribute("xlink:href", $currentWms->wms_getlegendurl);
+				$e_layer_style_legendurl->appendChild($e_layer_style_legendurl_or);
+				$e_layer_style->appendChild($e_layer_style_legendurl);
+			}
+			$e_layer_stylelist->appendChild($e_layer_style);
+		}	
+		return $e_layer_stylelist;
+	}
+	
+	/**
+	 * 
+	 * @return 
+	 */
+	private function createContactInformationNode () {
+		
+		if ($this->wmc->wmc_contactemail || $this->wmc->wmc_contactorganization ||
+			$this->wmc->wmc_contactperson || $this->wmc->wmc_contactposition || 
+			$this->wmc->wmc_contactaddresstype || $this->wmc->wmc_contactaddress || 
+			$this->wmc->wmc_contactcity || $this->wmc->wmc_contactstateorprovince ||
+			$this->wmc->wmc_contactpostcode || $this->wmc->wmc_contactcountry || 
+			$this->wmc->wmc_contactvoicetelephone || $this->wmc->wmc_contactfacsimiletelephone) {
+				
+			$e_contact = $this->doc->createElement("ContactInformation");
+			$e_contact_person_primary = $this->wmc->createContactPersonPrimaryNode();
+			if ($e_contact_person_primary !== null) {
+				$e_contact->appendChild($e_contact_person_primary);
+			}
+		
+			if ($this->wmc->wmc_contactposition){
+				$e_contact_position = $this->doc->createElement("ContactPosition", $this->wmc->wmc_contactposition);
+				$e_contact->appendChild($e_contact_position);
+			}
+		
+			if ($this->wmc->wmc_contactaddresstype || $this->wmc->wmc_contactaddress || 
+				$this->wmc->wmc_contactcity || $this->wmc->wmc_contactstateorprovince ||
+				$this->wmc->wmc_contactpostcode || $this->wmc->wmc_contactcountry) {
+		
+				$e_contact_address = $this->doc->createElement("ContactAddress");
+		
+				if ($this->wmc->wmc_contactaddresstype){
+					$e_address_type = $this->doc->createElement("AddressType", $this->wmc->wmc_contactaddresstype);
+					$e_contact_address->appendChild($e_address_type);
+				}
+				if ($this->wmc->wmc_contactaddress){
+					$e_address = $this->doc->createElement("Address", $this->wmc->wmc_contactaddress);
+					$e_contact_address->appendChild($e_address);
+				}
+				if ($this->wmc->wmc_contactcity){
+					$e_city = $this->doc->createElement("City", $this->wmc->wmc_contactcity);
+					$e_contact_address->appendChild($e_city);
+				}
+				if ($this->wmc->wmc_contactstateorprovince){
+					$e_state = $this->doc->createElement("StateOrProvince", $this->wmc->wmc_contactstateorprovince);
+					$e_contact_address->appendChild($e_state);
+				}
+				if ($this->wmc->wmc_contactpostcode){
+					$e_postcode = $this->doc->createElement("PostCode", $this->wmc->wmc_contactpostcode);
+					$e_contact_address->appendChild($e_postcode);
+				}
+				if ($this->wmc->wmc_contactcountry){
+					$e_country = $this->doc->createElement("Country", $this->wmc->wmc_contactcountry);
+					$e_contact_address->appendChild($e_country);
+				}
+				$e_contact->appendChild($e_contact_address);
+			}
+			
+			if ($this->wmc->wmc_contactvoicetelephone){
+				$e_voice_telephone = $this->doc->createElement("ContactVoiceTelephone", $this->wmc->wmc_contactvoicetelephone);
+				$e_contact->appendChild($e_voice_telephone);
+			}
+			if ($this->wmc->wmc_contactfacsimiletelephone){
+				$e_facsimile_telephone = $this->doc->createElement("ContactFacsimileTelephone", $this->wmc->wmc_contactfacsimiletelephone);
+				$e_contact->appendChild($e_facsimile_telephone);
+			}
+			if ($this->wmc->wmc_contactemail){
+				$e_email = $this->doc->createElement("ContactElectronicMailAddress", $this->wmc->wmc_contactemail);
+				$e_contact->appendChild($e_email);
+			}
+			return $e_contact;
+		}		
+		return null;
+	}
+	
+	private function createContactPersonPrimaryNode () {
+		if ($this->wmc->wmc_contactperson || $this->wmc->wmc_contactorganization){
+			$e_contact_person_primary = $this->doc->createElement("ContactPersonPrimary");
+	
+			if ($this->wmc->wmc_contactperson){
+				$e_contact_person = $this->doc->createElement("ContactPerson", $this->wmc->wmc_contactperson);
+				$e_contact_person_primary->appendChild($e_contact_person);
+			}
+			if ($this->wmc->wmc_contactorganization){
+				$e_contact_organization = $this->doc->createElement("ContactOrganization", $this->wmc->wmc_contactorganization);
+				$e_contact_person_primary->appendChild($e_contact_organization);
+			}
+			return $e_contact_person_primary;
+		}
+		return null;		
+	}
+
+}
+?>
\ No newline at end of file

Modified: branches/beck_dev/mapbender/http/classes/class_wms.php
===================================================================
--- branches/beck_dev/mapbender/http/classes/class_wms.php	2008-05-20 09:00:07 UTC (rev 2467)
+++ branches/beck_dev/mapbender/http/classes/class_wms.php	2008-05-21 15:38:21 UTC (rev 2468)
@@ -794,6 +794,66 @@
 		function createJsObjFromWMS($parent=0){
 			echo $this->createJsObjFromWMS_();
 		}
+		
+
+	function newLayer ($currentLayer, $currentExtent) {
+		$pos = $currentLayer["extension"]["LAYER_POS"];
+		$parent = $currentLayer["extension"]["LAYER_PARENT"];
+		$this->addLayer($pos, $parent); 
+
+		// set layer data
+		$layerIndex = count($this->objLayer) - 1;
+		$newLayer = $this->objLayer[$layerIndex];
+		$newLayer->layer_uid = $currentLayer["extension"]["LAYER_ID"];
+		$newLayer->layer_name = $currentLayer["name"];
+		$newLayer->layer_title = $currentLayer["title"];
+		$newLayer->layer_dataurl_href = $currentLayer["dataurl"];
+		$newLayer->layer_pos = $currentLayer["extension"]["LAYER_POS"];
+		$newLayer->layer_queryable = $currentLayer["queryable"];
+		$newLayer->layer_minscale = $currentLayer["extension"]["MINSCALE"];
+		$newLayer->layer_maxscale = $currentLayer["extension"]["MAXSCALE"];
+		$newLayer->layer_metadataurl = $currentLayer["metadataurl"];
+		$newLayer->gui_layer_wms_id = $currentLayer["extension"]["WMS_LAYER_ID"];
+		$newLayer->gui_layer_status = $currentLayer["extension"]["GUI_STATUS"];
+		$newLayer->gui_layer_style = ""; // TODO: Add correct data
+		$newLayer->gui_layer_selectable = $currentLayer["extension"]["GUI_SELECTABLE"];
+		$newLayer->gui_layer_visible = $currentLayer["visible"];
+		$newLayer->gui_layer_queryable = $currentLayer["extension"]["GUI_QUERYABLE"];
+		$newLayer->gui_layer_querylayer = $currentLayer["extension"]["QUERYLAYER"];
+		$newLayer->gui_layer_minscale = $currentLayer["extension"]["GUI_MINSCALE"];
+		$newLayer->gui_layer_maxscale = $currentLayer["extension"]["GUI_MAXSCALE"];
+		if (isset($currentLayer["extension"]["WFSFEATURETYPE"])) {
+			$newLayer->gui_layer_wfs_featuretype = $currentLayer["extension"]["WFSFEATURETYPE"];
+		}
+		$newLayer->layer_abstract = $currentLayer["abstract"];
+
+/*
+		//
+		// set layer epsg
+		//
+		$currentLayerEpsg = array();
+		$currentLayerEpsg["epsg"] = $currentExtent->epsg;
+		$currentLayerEpsg["minx"] = $currentExtent->min->x;
+		$currentLayerEpsg["miny"] = $currentExtent->min->y; 
+		$currentLayerEpsg["maxx"] = $currentExtent->max->x;
+		$currentLayerEpsg["maxy"] = $currentExtent->max->y;
+		array_push($newLayer->objLayer[$i]->layer_epsg, $currentLayerEpsg);
+*/
+
+		//
+		// set layer style
+		//
+		for ($i = 0; $i < count($currentLayer["format"]); $i++) {
+			$layerStyleIndex = count($newLayer->gui_layer_style) - 1;
+			$newLayer->layer_style[$layerStyleIndex] = array();
+			$currentStyle = $newLayer->layer_style[$layerStyleIndex];
+			$currentStyle["name"] = $currentLayer["style"][$i]["name"];
+			$currentStyle["title"] = $currentLayer["style"][$i]["title"];
+			$currentStyle["legendurl"] = $currentLayer["style"][$i]["legendurl"];
+			$currentStyle["legendurl_format"] = $currentLayer["style"][$i]["legendurl_type"];
+		}
+	}
+	
 	  function createJsObjFromWMS_($parent=0){
 	  	$str = "";
 	  	if(!$this->wms_title || $this->wms_title == ""){



More information about the Mapbender_commits mailing list