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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Aug 28 08:48:22 EDT 2009


Author: christoph
Date: 2009-08-28 08:48:22 -0400 (Fri, 28 Aug 2009)
New Revision: 4554

Modified:
   trunk/mapbender/http/javascripts/mod_addWMSfromfilteredList_ajax.php
Log:
now uses new addWMS API

Modified: trunk/mapbender/http/javascripts/mod_addWMSfromfilteredList_ajax.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_addWMSfromfilteredList_ajax.php	2009-08-28 12:47:21 UTC (rev 4553)
+++ trunk/mapbender/http/javascripts/mod_addWMSfromfilteredList_ajax.php	2009-08-28 12:48:22 UTC (rev 4554)
@@ -19,6 +19,13 @@
 
 require_once(dirname(__FILE__)."/../php/mb_validatePermission.php");
 
+$sql = "SELECT e_target FROM gui_element WHERE e_id = $1 AND fkey_gui_id = $2";
+$v = array($e_id, $gui_id);
+$t = array("s", "s");
+$res = db_prep_query($sql, $v, $t);
+$row = db_fetch_array($res);
+$e_target = explode(",", ((string) $row["e_target"]));
+
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
@@ -38,6 +45,8 @@
 	option_dbgui      = (typeof(option_dbgui) !== 'undefined')      ? option_dbgui      : '0';
 	capabilitiesInput = (typeof(capabilitiesInput) !== 'undefined') ? capabilitiesInput : '1';
 	gui_list          = (typeof(gui_list) !== 'undefined')          ? gui_list          : '';
+	addwms_showWMS = 0;
+	addwms_zoomToExtent = 0;
 
 	var guis = gui_list.split(',');
 	
@@ -51,28 +60,138 @@
 	// Load service
 
 	function mod_addWMSfromDB(gui_id,wms_id) {
-		parent.mod_addWMSById_load(gui_id,wms_id);
+		mod_addWMSById_load(gui_id,wms_id);
 	}
 
-	function mod_addWMSfromfilteredList(pointer_name,version){
-		//TODO: load active
-		var load                 = false;
-		var conjunctionCharacter = parent.mb_getConjunctionCharacter(pointer_name);
+	var loadWmsAndZoomCallback = function (opt) {
+		if (typeof opt === "object" && opt.success) {
+			
+			var wmsId = parseInt(opt.wmsId, 10);
+			var map = parent.getMapObjByName('<?php echo $e_target[1]; ?>');
+			var wms = map.wms[map.wms.length - 1];
+			
+			if (wms === null) {
+				opt.msg = "Ein unbekannter Fehler ist aufgetreten.";
+			}
+			else {
+				// activate
+				if (typeof opt.visible === "number" && opt.visible === 1) {
+					if (typeof addwms_showWMS === "number" 
+						&& addwms_showWMS < wms.objLayer.length) {
+						
+						if (addwms_showWMS > 0) {
+						
+							try {
+								var msg = "Der hinzugeladene Kartendienst " +
+								"verfügt über mehr als " +
+								addwms_showWMS +
+								" Ebenen. Die Ebenen des Dienstes werden " +
+								"<b>nicht</b> aktiviert.";
+								
+								parent.Mapbender.modules.dialogManager.openDialog({
+									content: msg,
+									modal: false,
+									effectShow: 'puff'
+								});
+							} 
+							catch (e) {
+								new parent.Mb_warning(e.message + ". " + msg);
+							}
+						}
+					}
+					else {
+						var wmsId = wms.wms_id;
+						parent.handleSelectedWms(map.elementName, wmsId, "visible", 1)
+					}
+				}
+				
+				if (typeof opt.zoomToExtent === "number" && opt.zoomToExtent === 1) {
+					// zoom to bbox
+					var bbox_minx, bbox_miny, bbox_maxx, bbox_maxy;
+					for (var i = 0; i < wms.gui_epsg.length; i++) {
+						if (map.epsg == wms.gui_epsg[i]) {
+							bbox_minx = parseFloat(wms.gui_minx[i]);
+							bbox_miny = parseFloat(wms.gui_miny[i]);
+							bbox_maxx = parseFloat(wms.gui_maxx[i]);
+							bbox_maxy = parseFloat(wms.gui_maxy[i]);
+							if (bbox_minx === null || bbox_miny === null || bbox_maxx === null || bbox_maxy === null) {
+								continue;
+							}
+							
+							map.calculateExtent(new parent.Extent(bbox_minx, bbox_miny, bbox_maxx, bbox_maxy));
+							map.setMapRequest();
+							break;
+						}
+					}
+				}
+			}
+		}
+		loadWmsCallback(opt);
+
+	};
+
+	var loadWmsCallback = function (opt) {
+		var msg = typeof opt.msg === "string" ? opt.msg : "";
 		
-		if(version == '1.0.0') {
-			load = pointer_name + conjunctionCharacter + 'REQUEST=capabilities&WMTVER=1.0.0';
+		if (typeof opt !== "object" || !opt.success) {
+			msg = "Ein unbekannter Fehler ist aufgetreten.";
+		} 
+		else {
+			var map = parent.getMapObjByName('<?php echo $e_target[1]; ?>');
+			var wms = map.wms[map.wms.length - 1];
+			
+			if (wms !== null) {
+				msg = "Der folgende Dienst wurde zu 'Aktive Dienste' " + 
+					"hinzugefügt:<br><br>";
+				msg += "<b>" + wms.wms_title + "</b>";
+			}
+			else {
+				msg = "Ein unbekannter Fehler ist aufgetreten.";
+			}
 		}
-		else if(version == '1.1.0' || version == '1.1.1') {
-			load = pointer_name + conjunctionCharacter + 'REQUEST=GetCapabilities&SERVICE=WMS&VERSION=' + version;
+		try {
+			parent.Mapbender.modules.dialogManager.openDialog({
+				content: msg,
+				modal: false,
+				effectShow: 'puff'
+			});
 		}
-		if(load !== false) {
-			parent.mod_addWMS_load(load);
+		catch (e) {
+			new parent.Mb_warning(e.message + ". " + msg);
 		}
+	};
+
+
+	function mod_addWMSfromfilteredList(pointer_name, version, options){
+	
+		pointer_name=pointer_name + parent.mb_getConjunctionCharacter(pointer_name);
+		if (version == '1.0.0'){
+			var cap = pointer_name + "REQUEST=capabilities&WMTVER=1.0.0";
+			var load = cap;
+		}
+		else if (version == '1.1.0'){
+			var cap = pointer_name + "REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.0";
+			var load = cap;
+		}
+		else if (version == '1.1.1'){
+			var cap = pointer_name + "REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1";
+			var load = cap;
+		}  
+		if(load){
+			parent.mod_addWMS_load(load, options);
+		}
 	}
-
+	
 	function mod_addWmsfromURL(){
 		var capabilities = document.getElementById('CapURL').value;
-		parent.mod_addWMS_load(capabilities);
+		var zoomToExtent = document.getElementById('addwms-zoom').checked ? 1 : 0;
+		var showLayers = document.getElementById('addwms-show').checked ? 1 : 0;
+
+		parent.mod_addWMS_load(capabilities, {
+			zoomToExtent: zoomToExtent,
+			visible: showLayers,
+			callback: loadWmsAndZoomCallback
+		});
 	}
 
 	// Retrieve data
@@ -190,6 +309,17 @@
 		document.getElementById("resultString").innerHTML = noResultText;
 	}
 
+	function setDefaults () {
+		if (typeof addwms_showWMS === "number" && addwms_showWMS > 0) {
+			document.getElementById("addwms-show").checked = "checked";
+		}
+		if (typeof addwms_zoomToExtent === "number" 
+			&& addwms_zoomToExtent === 1) {
+			
+			document.getElementById("addwms-zoom").checked = "checked";
+		}
+	}
+
 	function setButtons() {
 		var containerCapabilities = document.getElementById('container_capabilities');
 		var containerButtons      = document.getElementById('container_buttons');
@@ -283,10 +413,25 @@
 			for (var i = 0; i < wmsArray.length; i++) {
 
 				if (global_source == "db" && typeof(guiId) !== "undefined" ) {
-					var onClick = "mod_addWMSfromDB('" + guiId + "', '" + wmsArray[i].id + "')";
+					var onClick = "parent.mod_addWMSById_ajax(" + 
+						"'" + guiId + "', '" + wmsArray[i].id + "', {" + 
+							"callback: function (opt) {" + 
+								"if (typeof opt === 'object' && opt.success) {" + 
+									"var wmsId = parseInt(opt.wmsId, 10);" + 
+									"var map = getMapObjByName('<?php echo $e_target[0]; ?>');" + 
+									"handleSelectedWms(map.elementName, wmsId, 'visible', 0);" + 
+									"handleSelectedWms(map.elementName, wmsId, 'querylayer', 0);" + 
+								"}" + 
+								"loadWmsCallback(opt);}});";
 				}		
 				else {
-					var onClick = "mod_addWMSfromfilteredList('" + wmsArray[i].getCapabilitiesUrl + "', '" + wmsArray[i].version + "')";
+					var onClick = "mod_addWMSfromfilteredList(\"" + 
+					wmsArray[i].getCapabilitiesUrl + "\",\"" + 
+					wmsArray[i].version+"\", {" + 
+					"zoomToExtent: 0, " + 
+					"visible: 0, " + 
+					"callback: loadWmsCallback" + 
+					"});";
 				}
 				addTableRow(wmsArray[i].title, wmsArray[i].abstract, onClick);
 			}
@@ -313,7 +458,7 @@
 
 </head>
 
-<body onLoad="setButtons();">
+<body onLoad="setButtons();setDefaults();">
 <h1><?php echo _mb("Add WMS"); ?></h1>
 <p><?php echo _mb("Enter a Capabilities-URL of a WMS or select one or more WMS from list."); ?></p>
 <p><em><?php echo _mb("Notice: Be aware of the scale hints. Possibly you need to zoom in to display the added service."); ?></em></p>
@@ -324,8 +469,16 @@
 	<p>
 		<label for="CapURL"><?php echo _mb("Capabilities-URL"); ?>:</label> 
 		<input type="text" id="CapURL" name="CapURL" /> 
-		<input type="button" id="addCapURL" name="addCapURL" value="<?php echo _mb("Add WMS"); ?>" onclick="mod_addWmsfromURL();" />
+		<input type="button" id="addCapURL" name="addCapURL" value="<?php echo _mb("Add WMS"); ?>" onclick="mod_addWmsfromURL();" /><br />
 	</p>
+	<p style="padding:0 0 4px 0;">
+		<input style="margin-left: 12em;" type="checkbox" id="addwms-show" />
+		<label style='display:inline;float:none;cursor:pointer' for="addwms-show">Ebenen des Kartendienstes aktivieren</label>
+	</p>
+	<p style="padding:0 0 4px 0;">
+		<input style="margin-left: 12em;" type="checkbox" id="addwms-zoom" />
+		<label style='display:inline;float:none;cursor:pointer' for="addwms-zoom">Auf Ebenenausdehnung des Kartendienstes heranzoomen</label> 
+	</p>
 </fieldset>
 </form>
 
@@ -359,4 +512,4 @@
 </table>
 </body>
 
-</html>
\ No newline at end of file
+</html>



More information about the Mapbender_commits mailing list