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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Aug 28 08:42:21 EDT 2009


Author: christoph
Date: 2009-08-28 08:42:21 -0400 (Fri, 28 Aug 2009)
New Revision: 4550

Modified:
   trunk/mapbender/http/javascripts/mod_addWMSgeneralFunctions.js
   trunk/mapbender/http/php/mod_createJSLayerObjFromXML.php
   trunk/mapbender/http/php/mod_createJSObjFromDBByWMS.php
   trunk/mapbender/http/php/mod_createJSObjFromXML.php
Log:
added AJAXified addWMS with a callback option (for messages etc)

Modified: trunk/mapbender/http/javascripts/mod_addWMSgeneralFunctions.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_addWMSgeneralFunctions.js	2009-08-28 12:41:23 UTC (rev 4549)
+++ trunk/mapbender/http/javascripts/mod_addWMSgeneralFunctions.js	2009-08-28 12:42:21 UTC (rev 4550)
@@ -6,34 +6,165 @@
 	var querylayers = "";
 	var ind = getMapObjIndexByName(obj);
 	//is the id valid?
-	for( var i=0; i<(wms.length-1); i++){
-		if(parseInt(wms[i].wms_id, 10) >= parseInt(wms[wms.length-1].wms_id, 10)){
-			wms[wms.length-1].wms_id = parseInt(mb_mapObj[ind].wms[i].wms_id, 10) + 1;
-		}
-	} 
+//	for( var i=0; i<(wms.length-1); i++){
+//		if(parseInt(wms[i].wms_id, 10) >= parseInt(wms[wms.length-1].wms_id, 10)){
+//			wms[wms.length-1].wms_id = parseInt(mb_mapObj[ind].wms[i].wms_id, 10) + 1;
+//		}
+//	} 
 	mb_mapObj[ind].wms[mb_mapObj[ind].wms.length] = wms[wms.length-1];
 	mb_mapObj[ind].layers[mb_mapObj[ind].layers.length] = layers;
 	mb_mapObj[ind].styles[mb_mapObj[ind].styles.length] = styles;
 	mb_mapObj[ind].querylayers[mb_mapObj[ind].querylayers.length] = querylayers;  
-	mb_execloadWmsSubFunctions();
+	var extArray = mb_mapObj[ind].extent.toString().split(",");
+	var newExt = new Extent(
+		parseFloat(extArray[0]),
+		parseFloat(extArray[1]),
+		parseFloat(extArray[2]),
+		parseFloat(extArray[3])
+	);
+	mb_mapObj[ind].setSrs({
+		srs: mb_mapObj[ind].epsg,
+		extent: new Extent(
+			parseFloat(newExt.minx),
+			parseFloat(newExt.miny),
+			parseFloat(newExt.maxx),
+			parseFloat(newExt.maxy)
+		),
+		displayWarning: true
+	});
 	return true; 
 }
 
-function mod_addWMS_load(caps){
-	var capUrl = "../php/mod_createJSObjFromXML.php?" + mb_session_name + "=" + mb_nr + "&caps=" + encodeURIComponent(caps);
-	window.frames['loadData'].document.location.href = capUrl;
+function mod_addWMS_load(caps, param) {
+
+	var options = {
+		caps: caps,
+		noHtml: 1
+	};
+	
+	options[mb_session_name] = mb_nr;
+	
+	$.get("../php/mod_createJSObjFromXML.php", options, function (js, status) {
+		var opt = {};
+		
+		if (typeof param !== "undefined") {
+			opt = {
+				callback: typeof param.callback === "function" ? param.callback : function(){
+				},
+				options: {
+					visible: typeof param.visible === "number" ? param.visible : 0,
+					zoomToExtent: typeof param.zoomToExtent === "number" ? param.zoomToExtent : 0
+				}
+			};
+		}
+		mod_addWms_general(js, opt);
+	});
+	
 }
 
-function mod_addLayer_load(caps,layer_name){
-	var url = "../php/mod_createJSLayerObjFromXML.php?caps=" + encodeURIComponent(caps) + "&layer_name=" + encodeURIComponent(layer_name);
-	window.frames['loadData'].document.location.href = url;
+function mod_addLayer_load(caps, layer_name, param){
+	var options = {
+		caps: caps,
+		layerName: layer_name,
+		noHtml: 1
+	};
+	
+	options[mb_session_name] = mb_nr;
+	
+	$.get("../php/mod_createJSLayerObjFromXML.php", options, function (js, status) {
+
+		var opt = {};
+		
+		if (typeof param !== "undefined") {
+			opt = {
+				callback: typeof param.callback === "function" ? param.callback : function () {},
+				options: {
+					visible: typeof param.visible === "number" ? param.visible : 0,
+					zoomToExtent: typeof param.zoomToExtent === "number" ? 
+						param.zoomToExtent : 0
+				}
+			};
+		}
+		mod_addWms_general(js, opt);
+	});
 }
 
 function mod_addWMSById_load(gui_id, wms_id){
 	window.frames['loadData'].document.location.href = "../php/mod_createJSObjFromDBByWMS.php?wms_id=" + wms_id + "&gui_id=" + gui_id;
 }
 
+var mod_addWms_general = function (js, param) {
+	var success = false;
+	if (js) {
+		var oldWmsCount = wms.length;
+		eval(js);
+		var newWmsCount = wms.length;
+		if (newWmsCount > oldWmsCount) {
+			success = true;
+			mb_mapObjaddWMS('mapframe1');
+		}
+	}
+	if (typeof param === "object" 
+		&& typeof param.callback === "function" 
+		&& typeof param.options === "object"
+		) {
+		param.options.success = success;
+		param.callback(param.options);
+	}
+	mb_execloadWmsSubFunctions();
+}
+
+function mod_addWMSById_ajax (gui_id, wms_id, param) {
+	var options = {
+		wms_id: wms_id,
+		gui_id: gui_id,
+		noHtml: 1
+	};
+	
+	// abort if WMS is already loaded
+	var map = getMapObjByName('mapframe1');
+	var wms = map.getWmsById(wms_id);
+	if (wms !== null) {
+		try {
+			var msg = "Der folgende Dienst befindet sich bereits unter " + 
+				"'Aktive Dienste', und wird nicht erneut hinzugefügt:" + 
+				"<br><br><b>" + wms.wms_title + "</b>";
+			Mapbender.modules.dialogManager.openDialog({
+				content: msg,
+				modal: false,
+				effectShow: 'puff'
+			});
+		}
+		catch (e) {
+			new Mb_warning(e.message + ". " + msg);
+		}
+		return;		
+	}
+
+	
+	options[mb_session_name] = mb_nr;
+	
+	$.get("../php/mod_createJSObjFromDBByWMS.php", options, function (js, status) {
+		var opt = {};
+		
+		if (typeof param !== "undefined") {
+			opt = {
+				callback: typeof param.callback === "function" ? param.callback : function(){
+				},
+				options: {
+					wmsId: wms_id,
+					appId: gui_id,
+					visible: typeof param.visible === "number" ? param.visible : 0,
+					zoomToExtent: typeof param.zoomToExtent === "number" ? param.zoomToExtent : 0
+				}
+			};
+		}
+		mod_addWms_general(js, opt);
+	});
+}
+
 function mod_addWMS_refresh(){
-	mb_mapObjaddWMS('mapframe1')
+	mb_mapObjaddWMS('mapframe1');
+	mb_execloadWmsSubFunctions();
 	zoom('mapframe1', true, 0.999);
-}
\ No newline at end of file
+}

Modified: trunk/mapbender/http/php/mod_createJSLayerObjFromXML.php
===================================================================
--- trunk/mapbender/http/php/mod_createJSLayerObjFromXML.php	2009-08-28 12:41:23 UTC (rev 4549)
+++ trunk/mapbender/http/php/mod_createJSLayerObjFromXML.php	2009-08-28 12:42:21 UTC (rev 4550)
@@ -19,28 +19,59 @@
 
 require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
 require_once(dirname(__FILE__)."/../classes/class_wms.php");
-?>
+require_once(dirname(__FILE__)."/../classes/class_administration.php");
+
+$capabilitiesURL = $_REQUEST['caps'];
+$layerName = $_REQUEST['layerName'];
+$noHtml = intval($_GET["noHtml"]);
+
+$output = "";
+$charset = CHARSET;
+
+$mywms = new wms();
+$mywms->createObjFromXML($capabilitiesURL);
+
+$errorMessage = _mb("Error: The Capabilities Document could not be accessed. " . 
+	"Please check whether the server is responding and accessible to " . 
+	"Mapbender.");
+if (!$mywms->wms_status) { 
+	$output .= "try {" . 
+		"Mapbender.Modules.dialogManager.openDialog({" . 
+		"content: '" . $errorMessage . "<br><br><b>" . $capabilitiesURL . 
+		"', modal: false, effectShow: 'puff'});" . 
+		"} catch (e) {" . 
+		"prompt('" . $errorMessage . "', '" . $capabilitiesURL . "');" . 
+		"}";
+}
+else {
+	$output .= $mywms->createJsLayerObjFromWMS("TRUE", $layerName);
+}
+
+$js = administration::convertOutgoingString($output);
+unset($output);
+
+if ($noHtml) {
+	echo $js;
+}
+else {
+/*
+	$js .= "parent.mod_addWMS_refresh();";
+	echo <<<HTML
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
 <head>
+<title>Load WMS</title>
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="expires" content="0">
-<?php
-echo '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">';	
-?>
-<title>Load WMS with one layer</title>
-<?php
-echo "<script type='text/javascript'>";
-$mywms = new wms();
-$mywms->createObjFromXML(html_entity_decode($_REQUEST['caps']));
-if(!$mywms->wms_status){ echo "alert('Error: The Capabilities Document " . html_entity_decode($_REQUEST['caps']) . " could not be accessed. Please check whether the server is responding and accessible to Mapbender.'); </script>"; die; }
-$mywms->createJsLayerObjFromWMS("TRUE", $_REQUEST['layer_name']);
-echo "parent.mod_addWMS_refresh();";
-echo "</script>";
-?>
+<meta http-equiv="Content-Type" content="text/html; charset='$charset'">	
+<script type='text/javascript'>
+$js
+</script>
 </head>
-<body bgcolor='#ffffff'>
-
+<body>
 </body>
-</html>
\ No newline at end of file
+</html>
+HTML;
+*/
+}

Modified: trunk/mapbender/http/php/mod_createJSObjFromDBByWMS.php
===================================================================
--- trunk/mapbender/http/php/mod_createJSObjFromDBByWMS.php	2009-08-28 12:41:23 UTC (rev 4549)
+++ trunk/mapbender/http/php/mod_createJSObjFromDBByWMS.php	2009-08-28 12:42:21 UTC (rev 4550)
@@ -22,19 +22,11 @@
 require_once(dirname(__FILE__)."/../classes/class_administration.php");
 
 $wms_id = $_GET["wms_id"];
-$user_id = Mapbender::session()->get("mb_user_id");
+$gui_id = $_GET["gui_id"];
+$user_id = $_SESSION["mb_user_id"];
+$noHtml = intval($_GET["noHtml"]);
 
-?>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
-<head>
-<meta http-equiv="cache-control" content="no-cache">
-<meta http-equiv="pragma" content="no-cache">
-<meta http-equiv="expires" content="0">
-<meta http-equiv="Content-Type" content="text/html; charset='<?php echo CHARSET;?>'">	
-<title>Load WMS with one layer</title>
-<script language="JavaScript" type="text/javascript">
-<?php
+$js = "";
 // check if user is allowed to access this wms
 $admin = new administration();
 if ($admin->getWmsPermission($wms_id, $user_id)) {
@@ -46,16 +38,38 @@
 		$mywms->createObjFromDBNoGui($wms_id);	
 	}
 	$output = $mywms->createJsObjFromWMS_(true);
-	echo administration::convertOutgoingString($output);
+	$js .= administration::convertOutgoingString($output);
 	unset($output);
-	echo "parent.mod_addWMS_refresh();";
 }
 else {
 	$e = new mb_exception("You are not allowed to access this WMS (WMS ID " . $wms_id . ").");
 }
-?>
+
+if ($noHtml) {
+	echo $js;
+}
+else {
+	$js .= "parent.mod_addWMS_refresh();";
+	
+	$charset = CHARSET;
+	echo <<<HTML
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<meta http-equiv="cache-control" content="no-cache">
+<meta http-equiv="pragma" content="no-cache">
+<meta http-equiv="expires" content="0">
+<meta http-equiv="Content-Type" content="text/html; charset='$charset'">	
+<title>Load WMS with one layer</title>
+<script language="JavaScript" type="text/javascript">
+$js
 </script>
 </head>
 <body bgcolor='#ffffff'>
 </body>
 </html>
+HTML;
+}
+
+

Modified: trunk/mapbender/http/php/mod_createJSObjFromXML.php
===================================================================
--- trunk/mapbender/http/php/mod_createJSObjFromXML.php	2009-08-28 12:41:23 UTC (rev 4549)
+++ trunk/mapbender/http/php/mod_createJSObjFromXML.php	2009-08-28 12:42:21 UTC (rev 4550)
@@ -21,8 +21,41 @@
 require_once(dirname(__FILE__)."/../classes/class_wms.php");
 require_once(dirname(__FILE__)."/../classes/class_administration.php");
 
-$capabilitiesURL = html_entity_decode($_REQUEST['caps']);
-?>
+$capabilitiesURL = $_REQUEST['caps'];
+$noHtml = intval($_GET["noHtml"]);
+
+$output = "";
+$charset = CHARSET;
+
+$mywms = new wms();
+$mywms->createObjFromXML($capabilitiesURL);
+
+$errorMessage = _mb("Error: The Capabilities Document could not be accessed. " . 
+	"Please check whether the server is responding and accessible to " . 
+	"Mapbender.");
+if (!$mywms->wms_status) { 
+	$output .= "try {" . 
+		"Mapbender.Modules.dialogManager.openDialog({" . 
+		"content: '" . $errorMessage . "<br><br><b>" . $capabilitiesURL . 
+		"', modal: false, effectShow: 'puff'});" . 
+		"} catch (e) {" . 
+		"prompt('" . $errorMessage . "', '" . $capabilitiesURL . "');" . 
+		"}";
+}
+else {
+	$output .= $mywms->createJsObjFromWMS_(true);
+}
+$js = administration::convertOutgoingString($output);
+unset($output);
+
+if ($noHtml) {
+
+	echo $js;
+}
+else {
+/*
+	$js .= "parent.mod_addWMS_refresh();";
+	echo <<<HTML
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
 <head>
@@ -30,26 +63,14 @@
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="expires" content="0">
-<meta http-equiv="Content-Type" content="text/html; charset='<?php echo CHARSET;?>'">	
+<meta http-equiv="Content-Type" content="text/html; charset='$charset'">	
 <script type='text/javascript'>
-<?php
-
-$mywms = new wms();
-$mywms->createObjFromXML($capabilitiesURL);
-
-$errorMessage = "Error: The Capabilities Document could not be accessed. Please check whether the server is responding and accessible to Mapbender.";
-if (!$mywms->wms_status) { 
-	echo "prompt('" . $errorMessage . "', '" . $capabilitiesURL . "');"; 
-	die; 
-}
-$output = $mywms->createJsObjFromWMS_(true);
-echo administration::convertOutgoingString($output);
-unset($output);
-?>
-
-parent.mod_addWMS_refresh();
+$js
 </script>
 </head>
-<body bgcolor='#ffffff'>
+<body>
 </body>
 </html>
+HTML;
+*/
+}



More information about the Mapbender_commits mailing list