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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Mar 28 04:47:01 EDT 2007


Author: christoph
Date: 2007-03-28 04:47:01 -0400 (Wed, 28 Mar 2007)
New Revision: 1245

Modified:
   trunk/mapbender/http/javascripts/mod_initWmc.php
Log:
now using class DivTag
refactoring

Modified: trunk/mapbender/http/javascripts/mod_initWmc.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_initWmc.php	2007-03-28 08:45:37 UTC (rev 1244)
+++ trunk/mapbender/http/javascripts/mod_initWmc.php	2007-03-28 08:47:01 UTC (rev 1245)
@@ -1,11 +1,16 @@
 <?php
 session_start();
+$wmc_id = $_SESSION['mb_myWmc'];
+$user = $_SESSION['mb_user_id'];
+$meetingPointId = $_SESSION['mb_myKml'];
+
 require_once("../classes/class_wmc.php");
 require_once("../classes/class_kml.php");
 require_once("../classes/class_administration.php");
 
 $con = db_connect($DBSERVER,$OWNER,$PW);
 db_select_db(DB,$con);
+
 $sql = "SELECT e_target FROM gui_element WHERE e_id = 'initWmc' AND fkey_gui_id = $1";
 $v = array($gui_id);
 $t = array('s');
@@ -16,25 +21,23 @@
 	$e_target = explode(",",$row["e_target"]);
 	$cnt++;
 }
-if($cnt > 1){
-	echo "alert('digitize_button: ID not unique!');";
+if ($cnt > 1 || $cnt == 0){
+	echo "alert('initWMC: ID not unique!');";
 }
 
-$wmc_id = $_SESSION['mb_myWmc'];
-$user = $_SESSION['mb_user_id'];
-$x;
-$y;
-$icon;
-$alt;
-$url;
+$x = false;
+$y = false;
+$icon = false;
+$alt = false;
+$url = false;
 
 $adm = new administration();
 
 
 //KML
-if ($_SESSION['mb_myKml']) {
+if (isset($meetingPointId)) {
 	$sql = "SELECT * FROM mb_meetingpoint WHERE mb_meetingpoint_id = $1";
-	$v = array($_SESSION['mb_myKml']);
+	$v = array($meetingPointId);
 	$t = array('s');
 	$res = db_prep_query($sql,$v,$t);
 	if($row = db_fetch_array($res)){
@@ -64,12 +67,12 @@
 		}
 	}
 	else {
-		$js_error .= "alert('Meetingpoint ID id ".$_SESSION['mb_myKml']." is not valid. Default GUI will be loaded instead.');"; 
+		$js_error .= "alert('Meetingpoint ID id ".$meetingPointId." is not valid. Default GUI will be loaded instead.');"; 
 	}
 }
 	
 //WMC
-if ($wmc_id) {
+if (isset($wmc_id)) {
 	if ($adm->getWmcById($wmc_id) != false) {
 
 		$valid_wmcs = $adm->getWmcByOwner($user);
@@ -80,47 +83,36 @@
 			$wmc->createObjFromWMC_id($wmc_id);
 			$js_wmc .= $wmc->createJsObjFromWMC("", $e_target[0], "load");
 			
-			if ($x && $y && $icon) {
+			if (!empty($x) && !empty($y) && !empty($icon)) {
+				
 				$js_kml .= "var myPoint = realToMap('".$e_target[0]."', new Point(".$x.",".$y."));\n";
-				$js_kml .= "var poleheight = 100;";
-				$js_kml .= "myPoint.y -= poleheight;";
-				$js_kml .= "var attributes = new Array();\n";
-				$js_kml .= "attributes[0] = new Array();\n";
-				$js_kml .= "attributes[0][0] = 'style';\n";
-				$js_kml .= "attributes[0][1] = 'position:absolute; top:'+myPoint.y+'px; left:'+myPoint.x+'px; z-index:100; font-size:10px';\n"; 
-				$js_kml .= "node = mb_checkTag('".$e_target[0]."', 'div', 'meeting_pole', 'body', attributes);\n";
-				$js_kml .= "if (node == false) {\n";
-				$js_kml .= "\talert('Fatal error: Element id is already taken!');\n";
-				$js_kml .= "}\n";
-				$js_kml .= "else {\n";
-				$js_kml .= "node.innerHTML = \"<table cellspacing=0 cellpadding=0><tr><td bgcolor=#000000><img width=0 height=100 border=1></td></tr></table>\";";
-				$js_kml .= "}\n";
-				$js_kml .= "myPoint.x -= 36;";
-				$js_kml .= "myPoint.y -= 6;";
-				$js_kml .= "var attributes = new Array();\n";
-				$js_kml .= "attributes[0] = new Array();\n";
-				$js_kml .= "attributes[0][0] = 'style';\n";
-				$js_kml .= "attributes[0][1] = 'position:absolute; top:'+myPoint.y+'px; left:'+myPoint.x+'px; z-index:100; font-size:10px';\n"; 
-				$js_kml .= "node = mb_checkTag('".$e_target[0]."', 'div', 'meeting_logo', 'body', attributes);\n";
-				$js_kml .= "if (node == false) {\n";
-				$js_kml .= "\talert('Fatal error: Element id is already taken!');\n";
-				$js_kml .= "}\n";
-				$js_kml .= "else {\n";
-				$js_kml .= "node.innerHTML = \"";
-				$js_img .= "<img border='0' src='".$icon."' title='".$alt."'>";
+
+				// 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 .= $js_img . "</td></tr></table>\";";
-				$js_kml .= "}\n";
+				$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($_SESSION["mb_user_id"])." is not allowed to access WMC ".$_SESSION['mb_myWmc'].". Default GUI will be loaded instead.');"; 
+			$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 ".$_SESSION['mb_myWmc']." is not valid. Default GUI will be loaded instead.');"; 
+		$js_error .= "alert('WMC id ".$wmc_id." is not valid. Default GUI will be loaded instead.');"; 
 	}
 }
 echo "function mod_initWMC_init() {";
@@ -141,5 +133,4 @@
 function mod_initWMC(){
 	mod_initWMC_init();
 	mb_registerSubFunctions('addFlag()');
-	mb_registerPanSubElement('meeting_pole');
 } 



More information about the Mapbender_commits mailing list