[Mapbender-commits] r3416 - in trunk/mapbender/http: classes javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Jan 8 09:41:46 EST 2009


Author: christoph
Date: 2009-01-08 09:41:46 -0500 (Thu, 08 Jan 2009)
New Revision: 3416

Modified:
   trunk/mapbender/http/classes/class_map.php
   trunk/mapbender/http/classes/class_wmc.php
   trunk/mapbender/http/classes/class_wmcToXml.php
   trunk/mapbender/http/classes/class_wms.php
   trunk/mapbender/http/javascripts/mod_initWmc.php
   trunk/mapbender/http/javascripts/mod_loadwmc.js
   trunk/mapbender/http/javascripts/mod_loadwmc.php
   trunk/mapbender/http/javascripts/mod_savewmc.php
   trunk/mapbender/http/php/mod_savewmc_server.php
Log:
WMC debugging

Modified: trunk/mapbender/http/classes/class_map.php
===================================================================
--- trunk/mapbender/http/classes/class_map.php	2009-01-08 12:44:12 UTC (rev 3415)
+++ trunk/mapbender/http/classes/class_map.php	2009-01-08 14:41:46 UTC (rev 3416)
@@ -272,11 +272,21 @@
 				$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_wms_id = $currentLayer->gui_layer_wms_id;
+//				$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;
+
+				if ($this->isOverview) {
+					preg_match_all("/LAYERS\=([^&]*)/", $jsMapObject->mapURL[0], $resultMatrix);
+					$layerList = $resultMatrix[1][0];
+					$layerListArray = explode(",", $layerList);
+					$newLayer->gui_layer_visible = (in_array($currentLayer->layer_name, $layerListArray)) ? 1 : 0;
+				}
+				else {
+					$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;
@@ -298,8 +308,8 @@
 				$newLayer->layer_style = array();
 				for ($z = 0; $z < count($currentLayer->layer_style); $z++) {
 					$newLayer->layer_style[$z] = array();
-					$newLayer->layer_style[$z]["name"] = $currentLayer->layer_style[$z]->name;
-					$newLayer->layer_style[$z]["title"] = $currentLayer->layer_style[$z]->title;
+					$newLayer->layer_style[$z]["name"] = $currentLayer->layer_style[$z]->name ? $currentLayer->layer_style[$z]->name : "default";
+					$newLayer->layer_style[$z]["title"] = $currentLayer->layer_style[$z]->title ? $currentLayer->layer_style[$z]->title : "default";
 					$newLayer->layer_style[$z]["legendurl"] = $currentLayer->layer_style[$z]->legendurl;
 					$newLayer->layer_style[$z]["legendurlformat"] = $currentLayer->layer_style[$z]->legendurlformat;
 				}

Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2009-01-08 12:44:12 UTC (rev 3415)
+++ trunk/mapbender/http/classes/class_wmc.php	2009-01-08 14:41:46 UTC (rev 3416)
@@ -146,7 +146,11 @@
 		$this->monitoringIsOn = true;
 		
 		$doc = wmc::getDocument($wmcId);
+		if ($doc === false) {
+			return false;
+		}
 		$this->createObjFromWMC_xml($doc);
+		return true;
 	}
 
 	public function createFromApplication ($appId) {
@@ -268,9 +272,9 @@
 	 * @param $id String the WMC id
 	 */
 	public static function getDocument ($id) {
-		$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1";
-		$v = array($id);
-		$t = array('s');
+		$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1 AND fkey_user_id = $2";
+		$v = array($id, $_SESSION["mb_user_id"]);
+		$t = array('s', 'i');
 		$res = db_prep_query($sql,$v,$t);
 		$row = db_fetch_array($res);
 		if ($row) {
@@ -345,19 +349,12 @@
 
 		// add WMS for main map frame
 		$wmsArray = $this->mainMap->getWmsArray();
-		// for all wms...
-		for ($i = 0; $i < count($wmsArray); $i++) {
-			// ..add wms and set properties
-			array_push($wmcJsArray, $wmsArray[$i]->createJsObjFromWMS_());
-		}
 
-		// delete existing map objects...
-		array_push($wmcJsArray, "mb_mapObj = [];");
-
-		// .. and add the overview map (if exists)
+		// find the WMS in the main map which is equal to the WMS
+		// in the overview map
+		$overviewWmsIndex = null;
+		$ovWmsArray = array();
 		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++) {
@@ -368,14 +365,48 @@
 					}
 				}
 			}
-			$wmcJsArray = array_merge($wmcJsArray, $this->overviewMap->toJavaScript($overviewWmsIndex));
+		}
 
+
+
+		// for all wms...
+		for ($i = 0; $i < count($wmsArray); $i++) {
+			// ..use settings from ov if available
+			if ($overviewWmsIndex !== null && $this->overviewMap !== null && 
+				$overviewWmsIndex == $i && count($ovWmsArray) > $i) {
+				array_push($wmcJsArray, $ovWmsArray[$i]->createJsObjFromWMS_());
+			}
+			else {
+				// ..otherwise use data from mapframe1
+				array_push($wmcJsArray, $wmsArray[$i]->createJsObjFromWMS_());
+			}			
 		}
 
+		// delete existing map objects...
+		array_push($wmcJsArray, "mb_mapObj = [];");
+
+		// .. and add the overview map (if exists) and set map request
+		if ($this->overviewMap !== null) {
+			$wmcJsArray = array_merge($wmcJsArray, $this->overviewMap->toJavaScript($overviewWmsIndex));
+		}
+
 		// .. and add main map ..
 		$wmcJsArray = array_merge($wmcJsArray, $this->mainMap->toJavaScript(null));
 
-		// Finally, request the maps
+		// set visibility of main map WMS (may be different from overview)
+		if ($this->overviewMap !== null) {
+			for ($i = 0; $i < count($wmsArray[$overviewWmsIndex]->objLayer); $i++) {
+				$visStr = "mb_mapObj[1].wms[" .$overviewWmsIndex . "].handleLayer(" . 
+					"'" . $wmsArray[$overviewWmsIndex]->objLayer[$i]->layer_name . "', " . 
+					"'visible', " . 
+					($wmsArray[$overviewWmsIndex]->objLayer[$i]->gui_layer_visible ? 1 : 0) . ");";
+				array_push($wmcJsArray, $visStr);
+			}
+			array_push($wmcJsArray, "mb_mapObj[1].restateLayers(" . $wmsArray[$overviewWmsIndex]->wms_id . ");");
+		}
+		
+
+		// .. request the map
 		array_push($wmcJsArray, "setMapRequest('" . $this->mainMap->getFrameName() . "');");
 		if ($this->overviewMap !== null) {
 			array_push($wmcJsArray, "setMapRequest('" . $this->overviewMap->getFrameName() . "');");
@@ -696,7 +727,7 @@
 						 }
 					 }
 					 elseif ($stylelist) {
-						 if ($style) {
+						if ($style) {
 							$index = count($currentLayer["style"]) - 1;
 							if ($tag == "STYLE" && $type == "close") {
 								$style = false;
@@ -718,10 +749,10 @@
 							}
 							else {
 								if ($tag == "NAME"){
-									$currentLayer["style"][$index]["name"] = $value;
+									$currentLayer["style"][$index]["name"] = $value ? $value : "default";
 								}
 								if ($tag == "TITLE") {
-									$currentLayer["style"][$index]["title"] = $value;
+									$currentLayer["style"][$index]["title"] = $value ? $value : "default";
 								}
 								if ($legendurl) {
 									if ($tag == "LEGENDURL" && $type == "close") {
@@ -820,7 +851,7 @@
 		// set WMS data
 		
 		$layerlistCompleteArray = array_merge($layerlistArray["main"], $layerlistArray["overview"]);
-		
+
 		for ($i = 0; $i < count($layerlistCompleteArray); $i++) {
 			$this->setLayerData($layerlistCompleteArray[$i]);
 		}
@@ -956,7 +987,7 @@
 			$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_wms_id = $currentLayer["extension"]["WMS_ID"];
 			$wms->objLayer[0]->gui_layer_status = 1;
 			$wms->objLayer[0]->gui_layer_selectable = 1; 
 			$wms->objLayer[0]->gui_layer_visible = 1;
@@ -1053,8 +1084,6 @@
 		$wmcToXml = new WmcToXml($this);
 		$this->xml = $wmcToXml->getXml();
 	}
-
-	
 } 
 
 /**

Modified: trunk/mapbender/http/classes/class_wmcToXml.php
===================================================================
--- trunk/mapbender/http/classes/class_wmcToXml.php	2009-01-08 12:44:12 UTC (rev 3415)
+++ trunk/mapbender/http/classes/class_wmcToXml.php	2009-01-08 14:41:46 UTC (rev 3416)
@@ -364,7 +364,7 @@
 		$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["wms_id"] = $currentLayer->gui_layer_wms_id;
 		$layerExtensionData["querylayer"] = $currentLayer->gui_layer_querylayer;
 		$layerExtensionData["gui_selectable"] = $currentLayer->gui_layer_selectable;
 		$layerExtensionData["gui_queryable"] = $currentLayer->gui_layer_queryable;
@@ -436,10 +436,10 @@
 					$e_layer_style->setAttribute("current", "1");
 				}
 
-				$e_layer_style_name = $this->doc->createElement("Name", $currentStyle->name);
+				$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_title = $this->doc->createElement("Title", $currentStyle["title"]);
 				$e_layer_style->appendChild($e_layer_style_title);
 				
 				
@@ -456,7 +456,7 @@
 				$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_or->setAttribute("xlink:href", $currentStyle["legendurl"]);
 				$e_layer_style_legendurl->appendChild($e_layer_style_legendurl_or);
 				$e_layer_style->appendChild($e_layer_style_legendurl);
 			}

Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php	2009-01-08 12:44:12 UTC (rev 3415)
+++ trunk/mapbender/http/classes/class_wms.php	2009-01-08 14:41:46 UTC (rev 3416)
@@ -857,7 +857,7 @@
 		$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_wms_id = $currentLayer["extension"]["WMS_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"];
@@ -911,14 +911,13 @@
 		//
 		// set layer style
 		//
-		for ($i = 0; $i < count($currentLayer["format"]); $i++) {
+		for ($i = 0; $i < count($currentLayer["style"]); $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"];
+			$newLayer->layer_style[$layerStyleIndex]["name"] = $currentLayer["style"][$i]["name"];
+			$newLayer->layer_style[$layerStyleIndex]["title"] = $currentLayer["style"][$i]["title"];	
+			$newLayer->layer_style[$layerStyleIndex]["legendurl"] = $currentLayer["style"][$i]["legendurl"];
+			$newLayer->layer_style[$layerStyleIndex]["legendurl_format"] = $currentLayer["style"][$i]["legendurl_type"];
 		}
 	}
 	

Modified: trunk/mapbender/http/javascripts/mod_initWmc.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_initWmc.php	2009-01-08 12:44:12 UTC (rev 3415)
+++ trunk/mapbender/http/javascripts/mod_initWmc.php	2009-01-08 14:41:46 UTC (rev 3416)
@@ -61,43 +61,36 @@
 	
 //WMC
 if (isset($wmc_id)) {
-	if ($adm->getWmcById($wmc_id) != false) {
+	$myInitWmc = new wmc();
+	$success = $myInitWmc->createFromDb($wmc_id);
+	if ($success) {
 
-		$valid_wmcs = $adm->getWmcByOwner($user);
-		if (in_array($wmc_id, $valid_wmcs)) {
-			echo "var wmc_id = false;";
-			echo "wmc_id = '".$wmc_id."';";
-			$wmc = new wmc();
-			$wmc->createFromDb($wmc_id);
-			$js_wmc .= $wmc->createJsObjFromWMC("", $e_target[0], $action);
+		$js_wmc = implode("", $myInitWmc->toJavaScript());
+		new mb_exception("WMC JS: " . $js_wmc);
+		
+		if (!empty($x) && !empty($y) && !empty($icon)) {
 			
-			if (!empty($x) && !empty($y) && !empty($icon)) {
-				
-				$js_kml .= "var myPoint = realToMap('".$e_target[0]."', new Point(".$x.",".$y."));\n";
+			$js_kml .= "var myPoint = realToMap('".$e_target[0]."', new Point(".$x.",".$y."));\n";
 
-				// 7 is half the width of pin.png
-				$js_kml .= "myPoint.x -= 7;";
-				// 20 is the height of pin.png
-				$js_kml .= "myPoint.y -= 20;";
+			// 7 is half the width of pin.png
+			$js_kml .= "myPoint.x -= 7;";
+			// 20 is the height of pin.png
+			$js_kml .= "myPoint.y -= 20;";
 
-				$js_kml .= "var meetingPointLogoStyle = {'position':'absolute', 'top':0, 'left':0, 'z-index':100, 'font-size':'10px'};\n"; 
-				$js_kml .= "meetingPointLogoTag = new DivTag('meeting_logo', '".$e_target[0]."', meetingPointLogoStyle);\n";
-				$js_img .= "<img id='meeting_img' border='0' src='".$icon."' title='".$alt."'>";
-				if ($url) {
-					$js_img = "<a href='".$url."' target='_blank'>" . $js_img . "</a>";
-				}
-				$js_kml .= "var meetingPointLogoText = \"" . $js_img . "\";\n";
-				$js_kml .= "meetingPointLogoTag.write(meetingPointLogoText);\n";
-				$js_kml .= "var meeting_img = window.frames['".$e_target[0]."'].document.getElementById('meeting_img');";
-				$js_kml .= "meeting_img.style.position = 'absolute';";
-				$js_kml .= "meeting_img.style.top = myPoint.y;";
-				$js_kml .= "meeting_img.style.left = myPoint.x;";
-				$js_kml .= "mb_registerPanSubElement('meeting_logo');";
+			$js_kml .= "var meetingPointLogoStyle = {'position':'absolute', 'top':0, 'left':0, 'z-index':100, 'font-size':'10px'};\n"; 
+			$js_kml .= "meetingPointLogoTag = new DivTag('meeting_logo', '".$e_target[0]."', meetingPointLogoStyle);\n";
+			$js_img .= "<img id='meeting_img' border='0' src='".$icon."' title='".$alt."'>";
+			if ($url) {
+				$js_img = "<a href='".$url."' target='_blank'>" . $js_img . "</a>";
 			}
+			$js_kml .= "var meetingPointLogoText = \"" . $js_img . "\";\n";
+			$js_kml .= "meetingPointLogoTag.write(meetingPointLogoText);\n";
+			$js_kml .= "var meeting_img = window.frames['".$e_target[0]."'].document.getElementById('meeting_img');";
+			$js_kml .= "meeting_img.style.position = 'absolute';";
+			$js_kml .= "meeting_img.style.top = myPoint.y;";
+			$js_kml .= "meeting_img.style.left = myPoint.x;";
+			$js_kml .= "mb_registerPanSubElement('meeting_logo');";
 		}
-		else {
-			$js_error .= "alert('".$adm->getUserNameByUserId($user)." is not allowed to access WMC ".$wmc_id.". Default GUI will be loaded instead.');"; 
-		}
 	}
 	else {
 		$js_error .= "alert('WMC id ".$wmc_id." is not valid. Default GUI will be loaded instead.');"; 
@@ -111,7 +104,6 @@
 
 echo "function addFlag() {";
 echo $js_kml;
-echo $js_error;
 echo "}";
 
 

Modified: trunk/mapbender/http/javascripts/mod_loadwmc.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_loadwmc.js	2009-01-08 12:44:12 UTC (rev 3415)
+++ trunk/mapbender/http/javascripts/mod_loadwmc.js	2009-01-08 14:41:46 UTC (rev 3416)
@@ -281,4 +281,4 @@
 			$tr.fadeIn("slow");
 		}());
 	}
-}
\ No newline at end of file
+}

Modified: trunk/mapbender/http/javascripts/mod_loadwmc.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_loadwmc.php	2009-01-08 12:44:12 UTC (rev 3415)
+++ trunk/mapbender/http/javascripts/mod_loadwmc.php	2009-01-08 14:41:46 UTC (rev 3416)
@@ -29,11 +29,11 @@
 		$e = new mb_notice("wmc not set, generating from app: " . $_SESSION["mb_user_gui"]);
 		$wmc->createFromApplication($_SESSION["mb_user_gui"]);		
 		$_SESSION["mb_wmc"] = $wmc->toXml();
-		$e = new mb_exception("initial WMC: " . $_SESSION["mb_wmc"]);
+//		$e = new mb_exception("initial WMC: " . $_SESSION["mb_wmc"]);
 	}
 
 	if (isset($_SESSION['mb_wmc'])) {
-		$e = new mb_notice("merging with WMC.");
+		$e = new mb_exception("merging with WMC.");
 
 		if ($wmc->createFromXml($_SESSION['mb_wmc'])) {
 	

Modified: trunk/mapbender/http/javascripts/mod_savewmc.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_savewmc.php	2009-01-08 12:44:12 UTC (rev 3415)
+++ trunk/mapbender/http/javascripts/mod_savewmc.php	2009-01-08 14:41:46 UTC (rev 3416)
@@ -71,7 +71,12 @@
 	}
 
 	if (storeInSession) {
-		$.ajaxSetup({async:false}); //TODO: find out why async doesn't work onunload
+		$.ajaxSetup({async:false}); 
 	}
-	$.post("../php/mod_savewmc_server.php", {"saveInSession":storeInSession, "generalTitle":generalTitle, "extensionData":extensionDataString, "mapObject":$.toJSON(mb_mapObj)}, callbackFunction);
+	$.post("../php/mod_savewmc_server.php", {
+		"saveInSession":storeInSession, 
+		"generalTitle":generalTitle, 
+		"extensionData":extensionDataString, 
+		"mapObject":$.toJSON(mb_mapObj)
+	}, callbackFunction);
 }

Modified: trunk/mapbender/http/php/mod_savewmc_server.php
===================================================================
--- trunk/mapbender/http/php/mod_savewmc_server.php	2009-01-08 12:44:12 UTC (rev 3415)
+++ trunk/mapbender/http/php/mod_savewmc_server.php	2009-01-08 14:41:46 UTC (rev 3416)
@@ -35,7 +35,7 @@
 $wmc = new wmc();
 $wmc->createFromJs($mapObject, $generalTitle, $extensionData);
 
-if ($saveInSession) {
+if ($saveInSession === 1) {
 	// store XML in session
 	$_SESSION["mb_wmc"] = $wmc->xml;
 	$_SESSION["epsg"] = $mapObject->epsg;



More information about the Mapbender_commits mailing list