[Mapbender-commits] r1758 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Oct 26 11:12:54 EDT 2007


Author: christoph
Date: 2007-10-26 11:12:54 -0400 (Fri, 26 Oct 2007)
New Revision: 1758

Modified:
   trunk/mapbender/http/classes/class_wmc.php
Log:
* new table layer monitor: counts how often a layer has been loaded from a WMC

* overview extent is now in WMC

* other Mapbender specific data stored in WMC, like wfs_conf_ids

Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2007-10-26 14:59:11 UTC (rev 1757)
+++ trunk/mapbender/http/classes/class_wmc.php	2007-10-26 15:12:54 UTC (rev 1758)
@@ -1,5 +1,5 @@
 <?php
-# $Id: class_wmc.php 645 2006-12-08 12:58:39Z christoph $
+# $Id: class_wmc.php 1233 2007-10-19 14:28:21Z baudson $
 # http://www.mapbender.org/index.php/class_wmc.php
 # Copyright (C) 2002 CCGIS 
 #
@@ -16,21 +16,33 @@
 # 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.
-
 require_once("../../conf/mapbender.conf");
 require_once("../classes/class_wms.php");
 require_once("../classes/class_mb_exception.php");
-require_once("../classes/class_administration.php");
+require_once("../classes/class_layer_monitor.php");
+require_once("../classes/class_bbox.php");
+require_once("../extensions/JSON.php");
 
+$con = db_connect(DBSERVER,OWNER,PW);
+db_select_db(DB,$con);
+
+function mb_utf8_encode ($str) {
+	if(CHARSET=="UTF-8") return utf8_encode($str);
+	return $str;
+}
+function mb_utf8_decode ($str) {
+	if(CHARSET=="UTF-8") return utf8_decode($str);
+	return $str;
+}
 function sepNameSpace($s){
-	$c = mb_strpos($s,":"); 
-	if($c>0)return mb_substr($s,$c+1);
+	$c = strpos($s,":"); 
+	if($c>0)return substr($s,$c+1);
 	return $s;
 }
 class wmc {
 
 	var $xml;
-
+	
 	var $wmc_id;
 	var $wmc_version;
 	var $wmc_windowWidth;
@@ -43,6 +55,7 @@
 	var $wmc_name;
 	var $wmc_title;
 	var $wmc_abstract;
+	var $wmc_general_extension = array();
 	var $wmc_logourl;
 	var $wmc_logourl_format;
 	var $wmc_logourl_type;
@@ -65,14 +78,19 @@
 	var $wmc_contactpostcode;
 	var $wmc_contactcountry;
 				
+				
 	var $wmc_wms_title = array();
 	var $wmc_layer_queryable = array();
-	var $wmc_layer_querylayer = array();
 	var $wmc_layer_hidden = array();
 	var $wmc_wms_id = array();
 	var $wmc_wms_service = array();
 	var $wmc_wms_version = array();
+	var $wmc_wms_layer_id = array();
+	var $wmc_layer_wfs_featuretype = array();
 	var $wmc_layer_id = array();
+	var $wmc_layer_pos = array();
+	var $wmc_layer_parent = array();
+	var $wmc_layer_querylayer = array();
 	var $wmc_layer_title = array();
 	var $wmc_layer_name = array();
 	var $wmc_layer_abstract = array();
@@ -83,6 +101,8 @@
 	var $wmc_layer_metadataurl = array();
 	var $wmc_layer_minscale = array();
 	var $wmc_layer_maxscale = array();
+	var $wmc_gui_layer_minscale = array();
+	var $wmc_gui_layer_maxscale = array();
 	var $wmc_layer_format = array();
 	var $wmc_layer_style_current = array();
 	var $wmc_layer_style_name = array();
@@ -95,20 +115,51 @@
 	var $wmc_layer_style_sld_url = array();
 	var $wmc_layer_style_sld_type = array();
 	var $wmc_layer_style_sld_title = array();
+	
 	var $wmc_wms_count = 0;
 			
-	function wmc() {	
-	} 
+	/*	
+	 	var $data_type = array(); 
+		var $data_format = array();
+		
+		var $objLayer = array(); 
+		  
+		var $gui_wms_mapformat;
+		var $gui_wms_featureinfoformat;
+		var $gui_wms_exceptionformat;
+		var $gui_wms_epsg;
+		  
+		var $default_epsg = 0;
+  */
+	var $monitoringIsOn = false;
+  		
+function wmc() {
+} 
+
+function saveAsFile() {
+	$filename = "wmc_" . date("Y_m_d_H_i_s") . ".log";
+	$logfile = "../../log/" . $filename;
 	
-	function getTitle() {
-		return $this->wmc_title;
+	if($h = fopen($logfile,"a")){
+		$content = $this->xml;
+		if(!fwrite($h,$content)){
+			$e = new mb_exception("class_wmc.php: failed to write wmc.");
+			return false;
+		}
+		fclose($h);
 	}
-	
-	function getNumberOfWms () {
-		return $this->wmc_wms_count;
-	}
+	return $filename;
+}
 
-function createWMCFromObj($mapObject, $user_id, $generalTitle) {
+function getTitle() {
+	return $this->wmc_title;
+}
+
+function getNumberOfWms () {
+	return $this->wmc_wms_count;
+}
+
+function createWMCFromObj($mapObject, $user_id, $generalTitle, $extensionData) {
 	$this->wmc_id = $user_id . '_' . time();
 	
 	$generalWidth = $mapObject->width;
@@ -314,6 +365,18 @@
 				}
 				$e_general->appendChild($e_contact);
 			}
+			
+			
+			if (count($extensionData) > 0) {
+				//$e = new mb_exception("writing wmc...");
+				$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);
 	
 	
@@ -359,6 +422,8 @@
 					$layerMetadataUrl = $mapObject->wms[$i]->objLayer[$j]->layer_metadataurl;
 					$layerMinscale = $mapObject->wms[$i]->objLayer[$j]->layer_minscale; 
 					$layerMaxscale = $mapObject->wms[$i]->objLayer[$j]->layer_maxscale; 
+					$guiLayerMinscale = $mapObject->wms[$i]->objLayer[$j]->gui_layer_minscale; 
+					$guiLayerMaxscale = $mapObject->wms[$i]->objLayer[$j]->gui_layer_maxscale; 
 					$wmsVersion = $mapObject->wms[$i]->wms_version;
 					$wmsTitle = $mapObject->wms[$i]->wms_title;
 					$wmsLayerId = $mapObject->wms[$i]->objLayer[0]->layer_uid;
@@ -366,7 +431,8 @@
 					$layerPos = $mapObject->wms[$i]->objLayer[$j]->layer_pos;
 					$layerParent = $mapObject->wms[$i]->objLayer[$j]->layer_parent;
 					$queryLayer = $mapObject->wms[$i]->objLayer[$j]->gui_layer_querylayer;
-		
+					$wfsFeatureType = $mapObject->wms[$i]->objLayer[$j]->gui_layer_wfs_featuretype;
+					
 					$e_layer = $doc->createElement("Layer");
 					$e_layer->setAttribute("queryable", $layerQueryable);
 					$e_layer->setAttribute("hidden", $layerHidden);
@@ -429,6 +495,11 @@
 						$e_scalehint->setAttribute("max", $layerMaxscale);
 						$e_extension->appendChild($e_scalehint);
 						
+						$e_gui_scalehint = $doc->createElement($extension_namespace.":guiScaleHint");
+						$e_gui_scalehint->setAttribute("min", $guiLayerMinscale);
+						$e_gui_scalehint->setAttribute("max", $guiLayerMaxscale);
+						$e_extension->appendChild($e_gui_scalehint);
+						
 						$e_layer_id = $doc->createElement($extension_namespace.":layer_id", $layerId);
 						$e_extension->appendChild($e_layer_id);
 						
@@ -446,6 +517,11 @@
 		
 						$e_querylayer = $doc->createElement($extension_namespace.":querylayer", $layerQuerylayer);
 						$e_extension->appendChild($e_querylayer);
+						
+						if ($wfsFeatureType) {
+							$e_wfsFeatureType = $doc->createElement($extension_namespace.":wfsFeatureType", $wfsFeatureType);
+							$e_extension->appendChild($e_wfsFeatureType);
+						}
 
 						$e_layer->appendChild($e_extension);
 		
@@ -545,198 +621,229 @@
 	
 	$doc->appendChild($e_view_context);
 	$this->xml = $doc->saveXML();
+	
+	// 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);
+	}
 }
 
+function createObjFromWMC_id($wmc_id){
+	
+	global $DBSERVER,$DB,$OWNER,$PW;
+	$con = db_connect($DBSERVER,$OWNER,$PW);
+	db_select_db(DB, $con);
+	
+	$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = '" . $wmc_id . "'";
+	$res = db_query($sql);
+	$wmc = db_fetch_row($res);
+	$this->createObjFromWMC_xml($wmc[0]);
+	$this->monitoringIsOn = true;
 
-	function createObjFromWMC_id($wmc_id){
-		
-		$con = db_connect(DBSERVER,OWNER,PW);
-		db_select_db(DB, $con);
-		
-		$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1";
-		$v = array($wmc_id);
-		$t = array("s");
-		$res = db_prep_query($sql, $v, $t);
-		$wmc = db_fetch_array($res);
-		$this->createObjFromWMC_xml($wmc[0]);
-	
+}
+function createObjFromWMC_xml($data){
+#	$data = str_replace("&#38;", "&amp;", $data);
+
+	// 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);
 	}
 
-	function createObjFromWMC_xml($data){
-		$values = NULL;
-		$tags = NULL;
-		$parser = xml_parser_create(CHARSET);
-		xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
-		xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
-		xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
-		xml_parse_into_struct($parser,$data,$values,$tags);
-		$code = xml_get_error_code ($parser);
-		if ($code) {
-			$line = xml_get_current_line_number($parser); 
-			$mb_exception = new mb_exception(xml_error_string($code) .  " in line " . $line);
-			return false;
+
+
+	$values = NULL;
+	$tags = NULL;
+	$parser = xml_parser_create(CHARSET);
+	xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
+	xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
+	xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
+	xml_parse_into_struct($parser,$data,$values,$tags);
+	$code = xml_get_error_code ($parser);
+	if ($code) {
+		$line = xml_get_current_line_number($parser); 
+		$mb_exception = new mb_exception(xml_error_string($code) .  " in line " . $line);
+		return false;
+	}
+	xml_parser_free($parser);
+	
+	$section = NULL;
+	$format = NULL;
+	$cnt_format = 0;
+	$parent = array();
+	$myParent = array();
+	$cnt_layer = -1;
+	$request = NULL; 
+	$layer_style = array();
+	$extension = false;
+	
+	$general = false;
+	$layerlist = false;
+	$layer = false;
+	$formatlist = false;
+	$dataurl = false;
+	$metadataurl = false; 
+	$stylelist = false;
+	$cnt_style = -1;
+		 
+	foreach ($values as $element) {
+					$verbose .= ".";
+		if(strtoupper($element[tag]) == "VIEWCONTEXT" && $element[type] == "open"){
+				$this->wmc_id = $element[attributes]["id"];
+				$this->wmc_version = $element[attributes]["version"];
 		}
-		xml_parser_free($parser);
-		
-		$section = NULL;
-		$format = NULL;
-		$cnt_format = 0;
-		$parent = array();
-		$myParent = array();
-		$cnt_layer = -1;
-		$request = NULL; 
-		$layer_style = array();
-		$cnt_style = -1;
-		$extension = false;
-		
-		$general = false;
-		$layerlist = false;
-		$layer = false;
-		$formatlist = false;
-		$metadataurl = false;
-		$dataurl = false;
-		$stylelist = false;
-		
-		foreach ($values as $element) {
-			if(mb_strtoupper($element[tag]) == "VIEWCONTEXT" && $element[type] == "open"){
-					$this->wmc_id = $element[attributes]["id"];
-					$this->wmc_version = $element[attributes]["version"];
-			}
-			if(mb_strtoupper($element[tag]) == "GENERAL" && $element[type] == "open"){
-			   $general = true;
-			}
-			if(mb_strtoupper($element[tag]) == "LAYERLIST" && $element[type] == "open"){
-			   $layerlist = true;
-			}
-			if ($general) {
-				if(mb_strtoupper($element[tag]) == "WINDOW"){
-					$this->wmc_windowWidth = $element[attributes]["width"];
-					$this->wmc_windowHeight = $element[attributes]["height"];
+		if(strtoupper($element[tag]) == "GENERAL" && $element[type] == "open"){
+		   $general = true;
+		}
+		if(strtoupper($element[tag]) == "LAYERLIST" && $element[type] == "open"){
+		   $layerlist = true;
+		}
+		if ($general) {
+				if(strtoupper($element[tag]) == "WINDOW"){
+						$this->wmc_windowWidth = $element[attributes]["width"];
+						$this->wmc_windowHeight = $element[attributes]["height"];
 				}
-				if(mb_strtoupper($element[tag]) == "BOUNDINGBOX"){
-					$this->wmc_bBox_SRS = $element[attributes]["SRS"];
-					$this->wmc_bBox_minx = $element[attributes]["minx"];
-					$this->wmc_bBox_miny = $element[attributes]["miny"];
-					$this->wmc_bBox_maxx = $element[attributes]["maxx"];
-					$this->wmc_bBox_maxy = $element[attributes]["maxy"];
+				if(strtoupper($element[tag]) == "BOUNDINGBOX"){
+						$this->wmc_bBox_SRS = $element[attributes]["SRS"];
+						$this->wmc_bBox_minx = $element[attributes]["minx"];
+						$this->wmc_bBox_miny = $element[attributes]["miny"];
+						$this->wmc_bBox_maxx = $element[attributes]["maxx"];
+						$this->wmc_bBox_maxy = $element[attributes]["maxy"];
 				}
-				if(mb_strtoupper($element[tag]) == "NAME"){
-					$this->wmc_name = $element[value];
+				if(strtoupper($element[tag]) == "NAME"){
+						$this->wmc_name = mb_utf8_decode(html_entity_decode($element[value]));
 				}
-				if(mb_strtoupper($element[tag]) == "TITLE"){
-					$this->wmc_title = $element[value];
+				if(strtoupper($element[tag]) == "TITLE"){
+						$this->wmc_title = mb_utf8_decode(html_entity_decode($element[value]));
 				}
-				if(mb_strtoupper($element[tag]) == "ABSTRACT"){
-					$this->wmc_abstract = $element[value];
+				if(strtoupper($element[tag]) == "ABSTRACT"){
+						$this->wmc_abstract = mb_utf8_decode(html_entity_decode($element[value]));
 				}
-				if(mb_strtoupper($element[tag]) == "CONTACTINFORMATION" && $element['type'] == "open"){
-					$contactinformation = true;
+				if(strtoupper($element[tag]) == "CONTACTINFORMATION" && $element['type'] == "open"){
+						$contactinformation = true;
 				}
 				if ($contactinformation) {
-					if(mb_strtoupper($element[tag]) == "CONTACTPOSITION"){
-						$this->wmc_contactposition = $element[value];
+					if(strtoupper($element[tag]) == "CONTACTPOSITION"){
+							$this->wmc_contactposition = mb_utf8_decode(html_entity_decode($element[value]));
 					}
-					if(mb_strtoupper($element[tag]) == "CONTACTVOICETELEPHONE"){
-						$this->wmc_contactvoicetelephone = $element[value];
+					if(strtoupper($element[tag]) == "CONTACTVOICETELEPHONE"){
+							$this->wmc_contactvoicetelephone = $element[value];
 					}
-					if(mb_strtoupper($element[tag]) == "CONTACTFACSIMILETELEPHONE"){
-						$this->wmc_contactfacsimiletelephone = $element[value];
+					if(strtoupper($element[tag]) == "CONTACTFACSIMILETELEPHONE"){
+							$this->wmc_contactfacsimiletelephone = $element[value];
 					}
-					if(mb_strtoupper($element[tag]) == "CONTACTELECTRONICMAILADDRESS"){
-						$this->wmc_contactemail = $element[value];
+					if(strtoupper($element[tag]) == "CONTACTELECTRONICMAILADDRESS"){
+							$this->wmc_contactemail = mb_utf8_decode(html_entity_decode($element[value]));
 					}
-					if(mb_strtoupper($element[tag]) == "CONTACTPERSONPRIMARY" && $element['type'] == "open"){
-						$contactpersonprimary = true;
+					if(strtoupper($element[tag]) == "CONTACTPERSONPRIMARY" && $element['type'] == "open"){
+							$contactpersonprimary = true;
 					}
 					if ($contactpersonprimary) {
-						if(mb_strtoupper($element[tag]) == "CONTACTPERSON"){
-							$this->wmc_contactperson = $element[value];
+						if(strtoupper($element[tag]) == "CONTACTPERSON"){
+								$this->wmc_contactperson = mb_utf8_decode(html_entity_decode($element[value]));
 						}
-						if(mb_strtoupper($element[tag]) == "CONTACTORGANIZATION"){
-							$this->wmc_contactorganization = $element[value];
+						if(strtoupper($element[tag]) == "CONTACTORGANIZATION"){
+								$this->wmc_contactorganization = mb_utf8_decode(html_entity_decode($element[value]));
 						}
-						if(mb_strtoupper($element[tag]) == "CONTACTPERSONPRIMARY" && $element['type'] == "close"){
-							$contactpersonprimary = false;
+						if(strtoupper($element[tag]) == "CONTACTPERSONPRIMARY" && $element['type'] == "close"){
+								$contactpersonprimary = false;
 						}
 					}
-					if(mb_strtoupper($element[tag]) == "CONTACTADDRESS" && $element['type'] == "open"){
-						$contactaddress = true;
+					if(strtoupper($element[tag]) == "CONTACTADDRESS" && $element['type'] == "open"){
+							$contactaddress = true;
 					}
 					if ($contactaddress) {
-						if(mb_strtoupper($element[tag]) == "ADDRESSTYPE"){
-							$this->wmc_contactaddresstype = $element[value];
+						if(strtoupper($element[tag]) == "ADDRESSTYPE"){
+								$this->wmc_contactaddresstype = mb_utf8_decode(html_entity_decode($element[value]));
 						}
-						if(mb_strtoupper($element[tag]) == "ADDRESS"){
-							$this->wmc_contactaddress = $element[value];
+						if(strtoupper($element[tag]) == "ADDRESS"){
+								$this->wmc_contactaddress = mb_utf8_decode(html_entity_decode($element[value]));
 						}
-						if(mb_strtoupper($element[tag]) == "CITY"){
-							$this->wmc_contactcity = $element[value];
+						if(strtoupper($element[tag]) == "CITY"){
+								$this->wmc_contactcity = mb_utf8_decode(html_entity_decode($element[value]));
 						}
-						if(mb_strtoupper($element[tag]) == "STATEORPROVINCE"){
-							$this->wmc_contactstateorprovince = $element[value];
+						if(strtoupper($element[tag]) == "STATEORPROVINCE"){
+								$this->wmc_contactstateorprovince = mb_utf8_decode(html_entity_decode($element[value]));
 						}
-						if(mb_strtoupper($element[tag]) == "POSTCODE"){
-							$this->wmc_contactpostcode = $element[value];
+						if(strtoupper($element[tag]) == "POSTCODE"){
+								$this->wmc_contactpostcode = $element[value];
 						}
-						if(mb_strtoupper($element[tag]) == "COUNTRY"){
-							$this->wmc_contactcountry = $element[value];
+						if(strtoupper($element[tag]) == "COUNTRY"){
+								$this->wmc_contactcountry = mb_utf8_decode(html_entity_decode($element[value]));
 						}
-						if(mb_strtoupper($element[tag]) == "CONTACTADDRESS" && $element['type'] == "close"){
-							$contactaddress = false;
+						if(strtoupper($element[tag]) == "CONTACTADDRESS" && $element['type'] == "close"){
+								$contactaddress = false;
 						}
 					}
 				}
-				if(mb_strtoupper($element[tag]) == "LOGOURL" && $element['type'] == "open"){
-					$logourl = true;
-					$this->wmc_logourl_width = $element[attributes]["width"];
-					$this->wmc_logourl_height = $element[attributes]["height"];
-					$this->wmc_logourl_format = $element[attributes]["format"];
+				if(strtoupper($element[tag]) == "LOGOURL" && $element['type'] == "open"){
+						$logourl = true;
+						$this->wmc_logourl_width = $element[attributes]["width"];
+						$this->wmc_logourl_height = $element[attributes]["height"];
+						$this->wmc_logourl_format = $element[attributes]["format"];
 				}
 				if ($logourl) {
-					if(mb_strtoupper($element[tag]) == "LOGOURL" && $element['type'] == "close"){
-						$logourl = false;
+					if(strtoupper($element[tag]) == "LOGOURL" && $element['type'] == "close"){
+							$logourl = false;
 					}
-					if(mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+					if(strtoupper($element[tag]) == "ONLINERESOURCE"){
 						$this->wmc_logourl_type = $element[attributes]["xlink:type"];
 						$this->wmc_logourl = $element[attributes]["xlink:href"];
 					}
 				}
-				if(mb_strtoupper($element[tag]) == "DESCRIPTIONURL" && $element['type'] == "open"){
-					$descriptionurl = true;
-					$this->wmc_descriptionurl_format = $element[attributes]["format"];
+				if(strtoupper($element[tag]) == "DESCRIPTIONURL" && $element['type'] == "open"){
+						$descriptionurl = true;
+						$this->wmc_descriptionurl_format = $element[attributes]["format"];
 				}
 				if ($descriptionurl) {
-					if(mb_strtoupper($element[tag]) == "DESCRIPTIONURL" && $element['type'] == "close"){
-						$descriptionurl = false;
+					if(strtoupper($element[tag]) == "DESCRIPTIONURL" && $element['type'] == "close"){
+							$descriptionurl = false;
 					}
-					if(mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+					if(strtoupper($element[tag]) == "ONLINERESOURCE"){
 						$this->wmc_descriptionurl_type = $element[attributes]["xlink:type"];
 						$this->wmc_descriptionurl = $element[attributes]["xlink:href"];
 					}
 				}
-				if(mb_strtoupper($element[tag]) == "KEYWORDLIST" && $element['type'] == "open"){
-					$keywordlist = true;
+				if(strtoupper($element[tag]) == "KEYWORDLIST" && $element['type'] == "open"){
+						$keywordlist = true;
 				}
 				if ($keywordlist) {
-					if(mb_strtoupper($element[tag]) == "KEYWORDLIST" && $element['type'] == "close"){
-						$keywordlist = false;
-						$cnt_keyword = -1;
+					if(strtoupper($element[tag]) == "KEYWORDLIST" && $element['type'] == "close"){
+							$keywordlist = false;
+							$cnt_keyword = -1;
 					}
-					if(mb_strtoupper($element[tag]) == "KEYWORD"){
+					if(strtoupper($element[tag]) == "KEYWORD"){
 						$cnt_keyword++;
-						$this->wmc_keyword[$cnt_keyword] = $element[value];
+						$this->wmc_keyword[$cnt_keyword] = mb_utf8_decode(html_entity_decode($element[value]));
 					}
 				}
 						
-				if(mb_strtoupper($element[tag]) == "GENERAL" && $element['type'] == "close"){
+				if(strtoupper($element[tag]) == "EXTENSION" && $element['type'] == "close"){
+					$generalExtension = false;
+				}
+				if ($generalExtension) {
+					$this->wmc_general_extension[sepNameSpace($element[tag])] = $element[value];
+//					$e = new mb_exception("WMC: " . $element[tag] . ": " . $element[value]);
+				}
+				if(strtoupper($element[tag]) == "EXTENSION" && $element['type'] == "open"){
+					$generalExtension = true;
+				}
+
+				if(strtoupper($element[tag]) == "GENERAL" && $element['type'] == "close"){
 		   			$general = false;
 			 	}
-			}
-			if ($layerlist) {
-				if(mb_strtoupper($element[tag]) == "LAYERLIST" && $element['type'] == "close"){
+		}
+		if ($layerlist) {
+				if(strtoupper($element[tag]) == "LAYERLIST" && $element['type'] == "close"){
 				   $layerlist = false;
 				}
-				if(mb_strtoupper($element[tag]) == "LAYER" && $element[type] == "open"){
+				if(strtoupper($element[tag]) == "LAYER" && $element[type] == "open"){
 					 $cnt_layer++;
 					 $this->wmc_layer_queryable[$cnt_layer] = $element[attributes]["queryable"];
 					 $this->wmc_layer_hidden[$cnt_layer] = $element[attributes]["hidden"];
@@ -744,113 +851,113 @@
       		 		 $cnt_epsg = 0;
 				}
 				if ($layer) {
-					if(mb_strtoupper($element[tag]) == "LAYER" && $element[type] == "close"){
-						$layer = false;
-					}
+					 if(strtoupper($element[tag]) == "LAYER" && $element[type] == "close"){
+					 		$layer = false;
+					 }
 					 if ($formatlist) {
-						 if(mb_strtoupper($element[tag]) == "FORMAT"){
+						 if(strtoupper($element[tag]) == "FORMAT"){
 						 	$cnt_format++;
 						 	$this->wmc_layer_format_current[$cnt_layer][$cnt_format] = $element[attributes]["current"];
 						 	$this->wmc_layer_format[$cnt_layer][$cnt_format] = $element[value];
 						 }
-						 if(mb_strtoupper($element[tag]) == "FORMATLIST" && $element[type] == "close"){
+						 if(strtoupper($element[tag]) == "FORMATLIST" && $element[type] == "close"){
 							 $formatlist = false;
 						 }
 					 }
 					 elseif ($metadataurl) {
-						 if(mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
-							$this->wmc_layer_metadataurl[$cnt_layer] = $element[attributes]["xlink:href"];
+						 if(strtoupper($element[tag]) == "ONLINERESOURCE"){
+						 	$this->wmc_layer_metadataurl[$cnt_layer] = $element[attributes]["xlink:href"];
 						 }
-						 if(mb_strtoupper($element[tag]) == "METADATAURL" && $element[type] == "close"){
-							$metadataurl = false;
+						 if(strtoupper($element[tag]) == "METADATAURL" && $element[type] == "close"){
+							 $metadataurl = false;
 						 }
 					 }
 					 elseif ($dataurl) {
-						 if(mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+						 if(strtoupper($element[tag]) == "ONLINERESOURCE"){
 						 	$this->wmc_layer_dataurl[$cnt_layer] = $element[attributes]["xlink:href"];
 						 }
-						 if(mb_strtoupper($element[tag]) == "DATAURL" && $element[type] == "close"){
+						 if(strtoupper($element[tag]) == "DATAURL" && $element[type] == "close"){
 							 $dataurl = false;
 						 }
 					 }
 					 elseif ($stylelist) {
-						 if(mb_strtoupper($element[tag]) == "STYLE" && $element[type] == "open"){
+						 if(strtoupper($element[tag]) == "STYLE" && $element[type] == "open"){
 						 	$cnt_style++;
 						 	$style = true;
 						 	$this->wmc_layer_style_current[$cnt_layer][$cnt_style] = $element[attributes]["current"];
 						 }
 						 if ($style) {
-							 if(mb_strtoupper($element[tag]) == "STYLE" && $element[type] == "close"){
+							 if(strtoupper($element[tag]) == "STYLE" && $element[type] == "close"){
 							 	$style = false;
 							 }
-							 if(mb_strtoupper($element[tag]) == "SLD" && $element[type] == "open"){
+							 if(strtoupper($element[tag]) == "SLD" && $element[type] == "open"){
 							 	$sld = true;
 							 }
 							 if ($sld) {
-								 if(mb_strtoupper($element[tag]) == "SLD" && $element[type] == "close"){
+								 if(strtoupper($element[tag]) == "SLD" && $element[type] == "close"){
 								 	$sld = false;
 								 }
-								 if(mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+								 if(strtoupper($element[tag]) == "ONLINERESOURCE"){
 								 	$this->wmc_layer_style_sld_type[$cnt_layer][$cnt_style] = $element[attributes]["xlink:type"];
 								 	$this->wmc_layer_style_sld_url[$cnt_layer][$cnt_style] = $element[attributes]["xlink:href"];
 								 }
-								 if(mb_strtoupper($element[tag]) == "TITLE"){
-								 	$this->wmc_layer_style_sld_title[$cnt_layer][$cnt_style] = $element[value];
+								 if(strtoupper($element[tag]) == "TITLE"){
+								 	$this->wmc_layer_style_sld_title[$cnt_layer][$cnt_style] = mb_utf8_decode(html_entity_decode($element[value]));
 								 }
 							 }
 							 else {
-								 if(mb_strtoupper($element[tag]) == "NAME"){
-								 	$this->wmc_layer_style_name[$cnt_layer][$cnt_style] = $element[value];
+								 if(strtoupper($element[tag]) == "NAME"){
+								 	$this->wmc_layer_style_name[$cnt_layer][$cnt_style] = mb_utf8_decode(html_entity_decode($element[value]));
 								 }
-								 if(mb_strtoupper($element[tag]) == "TITLE"){
+								 if(strtoupper($element[tag]) == "TITLE"){
 								 	$this->wmc_layer_style_title[$cnt_layer][$cnt_style] = $element[value];
 								 }
-								 if(mb_strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "open"){
+								 if(strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "open"){
 								 	$legendurl = true;
 								 	$this->wmc_layer_style_legendurl_width[$cnt_layer][$cnt_style] = $element[attributes]["width"];
 								 	$this->wmc_layer_style_legendurl_height[$cnt_layer][$cnt_style] = $element[attributes]["height"];
 								 	$this->wmc_layer_style_legendurl_format[$cnt_layer][$cnt_style] = $element[attributes]["format"];
 								 }
 								 if ($legendurl) {
-									 if(mb_strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "close"){
+									 if(strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "close"){
 									 	$legendurl = false;
 									 }
-									 if(mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+									 if(strtoupper($element[tag]) == "ONLINERESOURCE"){
 									 	$this->wmc_layer_style_legendurl_type[$cnt_layer][$cnt_style] = $element[attributes]["xlink:type"];
 									 	$this->wmc_layer_style_legendurl[$cnt_layer][$cnt_style] = $element[attributes]["xlink:href"];
 									 }
 								 }
 							 }
 						 }
-						 if(mb_strtoupper($element[tag]) == "STYLELIST" && $element[type] == "close"){
+						 if(strtoupper($element[tag]) == "STYLELIST" && $element[type] == "close"){
 							 $stylelist = false;
 						 }
 					 }
 					 else {
-						 if(mb_strtoupper($element[tag]) == "SERVER" && $element[type] == "open"){
+						 if(strtoupper($element[tag]) == "SERVER" && $element[type] == "open"){
 						 	 $server = true;
 						 	 $this->wmc_wms_service[$cnt_layer] = $element[attributes]["service"];
 						 	 $this->wmc_wms_version[$cnt_layer] = $element[attributes]["version"];
-						 	 $this->wmc_wms_title[$cnt_layer] = $element[attributes]["title"];
+						 	 $this->wmc_wms_title[$cnt_layer] = mb_utf8_decode(html_entity_decode($element[attributes]["title"]));
 						 }
 						 if ($server) {
-							 if(mb_strtoupper($element[tag]) == "SERVER" && $element[type] == "close"){
+							 if(strtoupper($element[tag]) == "SERVER" && $element[type] == "close"){
 							 	 $server = false;
 							 }
-							 if(mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+							 if(strtoupper($element[tag]) == "ONLINERESOURCE"){
 						 		 $this->wmc_wms_serviceURL[$cnt_layer] = $element[attributes]["xlink:href"];
 							 }
 						 }
-						 if(mb_strtoupper($element[tag]) == "NAME"){
-					 		 $this->wmc_layer_name[$cnt_layer] = $element[value];
+						 if(strtoupper($element[tag]) == "NAME"){
+					 		 $this->wmc_layer_name[$cnt_layer] = mb_utf8_decode(html_entity_decode($element[value]));
 						 }
-						 if(mb_strtoupper($element[tag]) == "TITLE"){
-					 		 $this->wmc_layer_title[$cnt_layer] = $element[value];
+						 if(strtoupper($element[tag]) == "TITLE"){
+					 		 $this->wmc_layer_title[$cnt_layer] = mb_utf8_decode(html_entity_decode($element[value]));
 						 }
-						 if(mb_strtoupper($element[tag]) == "ABSTRACT"){
-					 		 $this->wmc_layer_abstract[$cnt_layer] = $element[value];
+						 if(strtoupper($element[tag]) == "ABSTRACT"){
+					 		 $this->wmc_layer_abstract[$cnt_layer] = mb_utf8_decode(html_entity_decode($element[value]));
 						 }
-						 if(mb_strtoupper($element[tag]) == "SRS"){
+						 if(strtoupper($element[tag]) == "SRS"){
 							 $epsgArray = explode(" ", $element[value]);						 	
 					 		 
 					 		 for ($c = 0 ; $c < count($epsgArray) ; $c ++) {
@@ -858,36 +965,52 @@
 								 $cnt_epsg++;
 					 		 }
 						 }
-						 if (mb_strtoupper($element[tag]) == "EXTENSION" && $element[type] == "open") {
+						 if (strtoupper($element[tag]) == "EXTENSION" && $element[type] == "open") {
 						 	$extension = true;
 						 }
-						 if (mb_strtoupper($element[tag]) == "EXTENSION" && $element[type] == "close") {
+						 if (strtoupper($element[tag]) == "EXTENSION" && $element[type] == "close") {
 						 	$extension = false;
 						 }
-						 if($extension == true && mb_strtoupper(sepNameSpace($element[tag])) == "SCALEHINT"){
+						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "SCALEHINT"){
 					 		 $this->wmc_layer_minscale[$cnt_layer] = $element[attributes]["min"];
 					 		 $this->wmc_layer_maxscale[$cnt_layer] = $element[attributes]["max"];
 						 }
-						 if($extension == true && mb_strtoupper(sepNameSpace($element[tag])) == "LAYER_ID"){
+						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "GUISCALEHINT"){
+					 		 $this->wmc_gui_layer_minscale[$cnt_layer] = $element[attributes]["min"];
+					 		 $this->wmc_gui_layer_maxscale[$cnt_layer] = $element[attributes]["max"];
+						 }
+						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "LAYER_ID"){
 					 		 $this->wmc_layer_id[$cnt_layer] = $element[value];
 						 }
-						 if($extension == true && mb_strtoupper(sepNameSpace($element[tag])) == "WMS_ID"){
-					 		 $this->wmc_wms_id[$cnt_layer] = $element[value];
+						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "WMS_LAYER_ID"){
+					 		 $this->wmc_wms_layer_id[$cnt_layer] = $element[value];
 						 }
-						 if($extension == true && mb_strtoupper(sepNameSpace($element[tag])) == "QUERYLAYER"){
+						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "LAYER_POS"){
+					 		 $this->wmc_layer_pos[$cnt_layer] = $element[value];
+						 }
+						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "LAYER_PARENT"){
+					 		 $this->wmc_layer_parent[$cnt_layer] = $element[value];
+						 }
+						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "QUERYLAYER"){
 					 		 $this->wmc_layer_querylayer[$cnt_layer] = $element[value];
 						 }
-						 if(mb_strtoupper(sepNameSpace($element[tag])) == "METADATAURL" && $element[type] == "open"){
+						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "WMS_ID"){
+					 		 $this->wmc_wms_id[$cnt_layer] = $element[value];
+						 }
+						 if($extension == true && strtoupper(sepNameSpace($element[tag])) == "WFSFEATURETYPE"){
+					 		 $this->wmc_layer_wfs_featuretype[$cnt_layer] = $element[value];
+						 }
+						 if(strtoupper($element[tag]) == "METADATAURL" && $element[type] == "open"){
 							 $metadataurl = true;
 						 }
-						 if(mb_strtoupper(sepNameSpace($element[tag])) == "DATAURL" && $element[type] == "open"){
+						 if(strtoupper($element[tag]) == "DATAURL" && $element[type] == "open"){
 							 $dataurl = true;
 						 }
-						 if(mb_strtoupper(sepNameSpace($element[tag])) == "FORMATLIST" && $element[type] == "open"){
+						 if(strtoupper($element[tag]) == "FORMATLIST" && $element[type] == "open"){
 							 $formatlist = true;
 							 $cnt_format = -1;
 						 }
-						 if(mb_strtoupper(sepNameSpace($element[tag])) == "STYLELIST" && $element[type] == "open"){
+						 if(strtoupper($element[tag]) == "STYLELIST" && $element[type] == "open"){
 							 $stylelist = true;
 							 $cnt_style = -1;
 						 }
@@ -896,15 +1019,34 @@
 			}
 		}
 		return true;
+	  //return $verbose;
 	}
 
 	function createJsObjFromWMC($target, $mapObj, $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]);
+			}
+		}
+		
 		$wmc_string = "";
 		$validActions = array("load", "merge", "append");
 		if (!in_array($action, $validActions)) {
 			$wmc_string .= "alert('invalid action: ".$action."');";			
 		}
 		else {
+			
+			// general extension
+			if (count($this->wmc_general_extension) > 0) {
+				$json = new Services_JSON();
+				$wmc_string .= $target . "restoredWmcExtensionData = " . $json->encode($this->wmc_general_extension) . ";\n"; 
+			}
+			
 			$wmc_string .= "var index = " . $target . "getMapObjIndexByName('" . $mapObj . "');\n";
 			if ($action == "load") {
 				// delete all previous wms
@@ -955,7 +1097,8 @@
 						}
 					}
 					// add wms
-					$wmc_string .= "\t" . $target . "add_wms('','".
+					$wmc_string .= "\t" . $target . "add_wms('".
+						$this->wmc_wms_id[$i]."','".
 						$this->wmc_wms_version[$i] ."','".
 						$this->wmc_wms_title[$i] ."','".
 						$this->wmc_layer_abstract[$i] ."','".
@@ -999,7 +1142,10 @@
 									$wmc_string .= "if (!wms_exists) {\n\t";
 								} 
 								// add parent layer
-								$wmc_string .= $target . "wms_add_layer('','".$this->wmc_layer_id[$i]."','','". $this->wmc_wms_title[$i] ."','','0','0','0','0','','".$this->wmc_wms_id[$i]."','1','1','1','0','0','0','0');\n";
+								$wmc_string .= $target . "wms_add_layer('','".
+									$this->wmc_wms_layer_id[$i]."','','". 
+									$this->wmc_wms_title[$i] ."','','0','0','0','0','','".
+									$this->wmc_wms_id[$i]."','1','', '1','1','0','0','0','0','');\n";
 								if ($action == "merge") {
 									$wmc_string .= "}\n";
 								} 
@@ -1019,15 +1165,21 @@
 								$wmc_string .= "\t\t\tcurrent_layer_index = m;\n";
 								$wmc_string .= "\t\t}\n";
 								$wmc_string .= "\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 (" . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_visible != '" . intval(!$this->wmc_layer_hidden[$ii]) . "'";
-								$wmc_string .= " || " . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_querylayer != '" . $this->wmc_layer_queryable[$ii] . "') {\n";
+								$wmc_string .= " || " . $target . "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\t" . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_visible = " . intval(!$this->wmc_layer_hidden[$ii]) . ";\n"; 
-								$wmc_string .= "\t\t\t" . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_querylayer = " . $this->wmc_layer_queryable[$ii] . ";\n"; 
+								$wmc_string .= "\t\t\t" . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_querylayer = " . $querylayer_yn . ";\n"; 
 								$wmc_string .= "\t\t}\n";
 								$wmc_string .= "\t}\n"; 
 								$wmc_string .= "}\n"; 
@@ -1035,29 +1187,31 @@
 							} 
 
 							// add layer
-							$wmc_string .= "\t" . $target . "wms_add_layer('0','". 
+							$wmc_string .= "\t" . $target . "wms_add_layer('".
+								($this->wmc_layer_parent[$ii]!=""?$this->wmc_layer_parent[$ii]:"0") . "','". 
 								$this->wmc_layer_id[$ii] . "','". 
 								$this->wmc_layer_name[$ii] . "','". 
 								$this->wmc_layer_title[$ii] ."','". 
 								$this->wmc_layer_dataurl[$ii] . "','". 
-								intval($cnt_layers) ."','". 
+								($this->wmc_layer_pos[$ii]!=""?$this->wmc_layer_pos[$ii]:intval($cnt_layers)) ."','". 
 								$this->wmc_layer_queryable[$ii] ."','".
 								$this->wmc_layer_minscale[$ii]  ."','". 
 								$this->wmc_layer_maxscale[$ii]  ."','". 
 								$this->wmc_layer_metadataurl[$ii] ."','". 
-								$this->wmc_wms_id[$ii] ."','1','1','". 
+								$this->wmc_wms_id[$i] ."','1','', '1','". 
 								intval(!$this->wmc_layer_hidden[$ii]) ."','". 
 								$this->wmc_layer_queryable[$ii] ."','". 
-								$this->wmc_layer_querylayer[$ii] ."','".
-								$this->wmc_layer_minscale[$ii]  ."','". 
-								$this->wmc_layer_maxscale[$ii]  ."');\n";
+								($this->wmc_layer_querylayer[$ii]!=""?$this->wmc_layer_querylayer[$ii]:$this->wmc_layer_queryable[$ii]) ."','".
+								($this->wmc_gui_layer_minscale[$ii]!=""?$this->wmc_gui_layer_minscale[$ii]:$this->wmc_layer_minscale[$ii]) ."','".
+								($this->wmc_gui_layer_maxscale[$ii]!=""?$this->wmc_gui_layer_maxscale[$ii]:$this->wmc_layer_maxscale[$ii]) ."','".
+								$this->wmc_layer_wfs_featuretype[$ii] . "');\n";
 	
 							if ($action == "merge") {
 								$wmc_string .= "\t}\n";
 							} 
 												
 							// if layer is queryable, add it to querylayerlist
-							if ($this->wmc_layer_queryable[$ii]) {
+							if (($this->wmc_layer_querylayer[$ii]!=""?$this->wmc_layer_querylayer[$ii]:$this->wmc_layer_queryable[$ii])) {
 								$cnt_query_layers++;
 								if (!in_array($this->wmc_layer_name[$ii], explode(",",$querylayerlist))) {
 									if ($querylayerlist == "") {$querylayerlist = $this->wmc_layer_name[$ii];} else {$querylayerlist .= "," . $this->wmc_layer_name[$ii];} 
@@ -1100,30 +1254,57 @@
 			$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, old_mapObj[i].width,  old_mapObj[i].height);\n"; 
+			$wmc_string .= "\t\t\t\t" . $target . "mb_registerMapObj('overview', old_mapObj[i].elementName, j, old_mapObj[i].width,  old_mapObj[i].width);\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].height);\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";
 			
-			$sql = "SELECT minx, miny, maxx, maxy FROM layer_epsg WHERE fkey_layer_id = $1 AND epsg = $2 LIMIT 1";
-			$v = array($this->wmc_layer_id[0], $this->wmc_bBox_SRS);
-			$t = array('i', 's');
-			$res = db_prep_query($sql, $v, $t);
-			$row = db_fetch_array($res);
-			if ($row["minx"] && $row["miny"] && $row["maxx"] && $row["maxy"]) {
-				$ov_bbox = array($row["minx"],$row["miny"],$row["maxx"],$row["maxy"]);
+			$ov_bbox = array();
+			// 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);
+				
+				// 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);
+				
+				$unionBox = Mapbender_bbox::union(array($ov_box, $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); 				
 			}
-			else if ($this->wmc_layer_id[0] && $this->wmc_bBox_SRS){
-				$ov_bbox = array($this->wmc_bBox_minx, $this->wmc_bBox_miny, $this->wmc_bBox_maxx, $this->wmc_bBox_maxy);
-			}
 			else {
-				$ov_bbox = array();
+/*
+				$sql = "SELECT minx, miny, maxx, maxy FROM layer_epsg WHERE fkey_layer_id = $1 AND epsg = $2 LIMIT 1";
+				$v = array($this->wmc_layer_id[0], $this->wmc_bBox_SRS);
+				$t = array('i', 's');
+				$res = db_prep_query($sql, $v, $t);
+				$row = db_fetch_array($res);
+				if ($row["minx"] && $row["miny"] && $row["maxx"] && $row["maxy"]) {
+					$ov_bbox = array($row["minx"],$row["miny"],$row["maxx"],$row["maxy"]);
+				}
+				else if ($this->wmc_layer_id[0] && $this->wmc_bBox_SRS){
+					$ov_bbox = array($this->wmc_bBox_minx, $this->wmc_bBox_miny, $this->wmc_bBox_maxx, $this->wmc_bBox_maxy);
+				}
+				else {
+*/
+					$ov_bbox = array(2412139.175257732, 5365000, 2767860.824742268, 5700000);		
+//				}
 			}
+			
 			$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, ";
@@ -1131,25 +1312,16 @@
 			$wmc_string .= $this->wmc_bBox_maxx .",".$this->wmc_bBox_maxy.");\n";
 			$wmc_string .= "\t}\n";
 			$wmc_string .= "\telse {\n";
-			if (count($ov_bbox)>0) {
-//				$wmc_string .= "alert('found bbox for ov: ".implode(',',$ov_bbox)."');";
-				$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";
-			}
-			else {
-//				$wmc_string .= "alert('no bbox found for ov: old bbox ".$this->wmc_bBox_minx." etc');";
-				$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\tvar ov_index = " . $target . "getMapObjIndexByName('overview');\n";
-//				$wmc_string .= "\t\t" . $target . "mb_mapObj[ov_index].extent = old_mapObj[i].extent;\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";
+			$wmc_string .= $target . "mb_execloadWmcSubFunctions();\n";
 		}
+//		$e = new mb_exception("js code: " . $wmc_string);
 		return $wmc_string;
 	}
 } 



More information about the Mapbender_commits mailing list