[Mapbender-commits] r1847 - branches/mapbender_sld/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Nov 23 09:23:25 EST 2007


Author: christoph
Date: 2007-11-23 09:23:24 -0500 (Fri, 23 Nov 2007)
New Revision: 1847

Modified:
   branches/mapbender_sld/http/javascripts/map.js
   branches/mapbender_sld/http/javascripts/map_obj.js
Log:
merged

Modified: branches/mapbender_sld/http/javascripts/map.js
===================================================================
--- branches/mapbender_sld/http/javascripts/map.js	2007-11-23 14:13:44 UTC (rev 1846)
+++ branches/mapbender_sld/http/javascripts/map.js	2007-11-23 14:23:24 UTC (rev 1847)
@@ -19,7 +19,111 @@
 var mb_offset_bottom = 0;
 var mb_offset_left = 0;
 var mb_log = null;
+var currentWmcExtensionData = {};
+var restoredWmcExtensionData = {};
 
+/*
+ ***************************************************************************************
+ *   register functions
+ ***************************************************************************************
+ */
+
+var mb_MapRequestSubFunctions = [];
+var mb_WfsReadSubFunctions = [];
+var mb_WfsWriteSubFunctions = [];
+var mb_MapRequestPreFunctions = [];
+var mb_FeatureInfoPreFunctions = [];
+var mb_InitFunctions = [];
+var mb_MapObjectSubFunctions = [];
+var mb_GetScalePreFunctions = [];
+var mb_loadWmsSubFunctions = [];
+var mb_l10nFunctions = [];
+
+function mb_registerInitFunctions(stringFunction){
+	mb_InitFunctions[mb_InitFunctions.length] = stringFunction;
+}
+function mb_registerPreFunctions(stringFunction){
+	mb_MapRequestPreFunctions[mb_MapRequestPreFunctions.length] = stringFunction;
+}
+function mb_registerFeatureInfoPreFunctions(stringFunction){
+	mb_FeatureInfoPreFunctions[mb_FeatureInfoPreFunctions.length] = stringFunction;
+}
+function mb_registerSubFunctions(stringFunction){
+	mb_MapRequestSubFunctions[mb_MapRequestSubFunctions.length] = stringFunction;
+}
+function mb_registerMapObjectSubFunctions(stringFunction){
+	mb_MapObjectSubFunctions[mb_MapObjectSubFunctions.length] = stringFunction;
+}
+function mb_registerGetScalePreFunctions(stringFunction){
+	mb_GetScalePreFunctions[mb_GetScalePreFunctions.length] = stringFunction;
+}
+function mb_registerloadWmsSubFunctions(stringFunction){
+	mb_loadWmsSubFunctions[mb_loadWmsSubFunctions.length] = stringFunction;
+}
+function mb_registerWfsReadSubFunctions(stringFunction){
+	mb_WfsReadSubFunctions[mb_WfsReadSubFunctions.length] = stringFunction;
+}
+function mb_registerWfsWriteSubFunctions(stringFunction){
+	mb_WfsWriteSubFunctions[mb_WfsWriteSubFunctions.length] = stringFunction;
+}
+function mb_registerL10nFunctions(stringFunction) {
+	mb_l10nFunctions[mb_l10nFunctions.length] = stringFunction;
+}
+function mb_removeFunctionFromArray(arrayname,stringFunction){
+	var length = eval(arrayname+".length");
+	for(var i=0; i<length; i++){
+		if(eval(arrayname+"["+i+"]") == stringFunction){
+			var newArray1 = eval(arrayname+".slice(0, "+(i-1)+")");
+			var newArray2 = eval(arrayname+".slice("+(i+1)+", "+length+")");
+			eval(arrayname + " = newArray1.concat(newArray2)");
+			i--;
+			length--;
+		}
+	}
+}
+
+
+function localize() {
+	for(var i=0; i<mb_l10nFunctions.length; i++){
+		eval(mb_l10nFunctions[i]); 	 
+	} 	 
+}
+function mb_execloadWmsSubFunctions(){
+	for(var i=0; i<mb_loadWmsSubFunctions.length; i++){
+		eval(mb_loadWmsSubFunctions[i]); 	 
+	} 	 
+}
+
+function mb_execWfsReadSubFunctions(geom) { 	 
+	for(var i=0; i<mb_WfsReadSubFunctions.length; i++){ 	 
+		mb_WfsReadSubFunctions[i](geom); 	 
+	} 	 
+}
+
+function mb_execWfsWriteSubFunctions() { 	 
+	for(var i=0; i<mb_WfsWriteSubFunctions.length; i++){
+		mb_WfsWriteSubFunctions[i](); 	 
+	} 	 
+}
+
+function mb_setWmcExtensionData(anArray) {
+	for (var i in anArray) {
+		if (typeof(anArray[i]) != "undefined") {
+			currentWmcExtensionData[i] = anArray[i];
+		}
+	}
+}
+
+function mb_getWmcExtensionData(arrayKey) {
+	for (var i in restoredWmcExtensionData) {
+		if (arrayKey == i) {
+			return restoredWmcExtensionData[i];
+		}
+	}
+	var e = new Mb_warning("mb_getWmcExtensionData: "+arrayKey+" not found. Maybe this GUI does not allow loading or saving WMC documents from/to the session");
+	return null;
+}
+
 var mb_PanSubElements = [];
 function mb_registerPanSubElement(elName){
 	var ind = mb_PanSubElements.length;
@@ -30,6 +134,9 @@
 function mb_registerVendorSpecific(stringFunction){
 	mb_vendorSpecific[mb_vendorSpecific.length] = stringFunction;
 }
+
+var mb_security_proxy = "http://wms1.ccgis.de/mapbender/tools/security_proxy.php?mb_ows_security_proxy=";
+
 var mb_trans = new Image; 
 mb_trans.src = "../img/transparent.gif";
 /*END OF GLOBALS*/
@@ -58,72 +165,80 @@
 }
 
 function mb_mapObj_const(frameName, elementName, width, height, wms_index){
+	this.width = width;
+	this.height = height;
+	this.frameName = frameName;
+	this.elementName = elementName;
+	this.layers = [];
+	this.styles = [];
+	this.querylayers = [];
+	this.geom = "";
+	this.gml = ""; 
 
-   this.width = width;
-   this.height = height;
-   this.frameName = frameName;
-   this.elementName = elementName;
-   this.layers = [];
-   this.styles = [];
-   this.querylayers = [];
-   this.geom = "";
-   this.gml = ""; 
-   if(wms_index != null){
-      this.wms = [];
-      this.wms[0] = wms[wms_index];
-      this.wms[0].mapURL = false;
-      var cnt_layers = 0;
-      var cnt_querylayers = 0;
-      var styles = "";
-      var layers = "";
-      var querylayers = "";
-      for(var ii=0; ii<this.wms[0].objLayer.length; ii++){
-         if(this.wms[0].objLayer[ii].gui_layer_visible == 1 && ii>0){
-            if(cnt_layers > 0){layers += ","; styles += ","; }
-            layers += this.wms[0].objLayer[ii].layer_name; 
-            styles += ""; 
-            cnt_layers++;
-         }   
-         if(this.wms[0].objLayer[ii].gui_layer_querylayer == 1 && ii>0){
-            if(cnt_querylayers > 0){querylayers += ",";}
-            querylayers += this.wms[0].objLayer[ii].layer_name; 
-            cnt_querylayers++;
-         }                      
-      }
-      this.layers[0] = layers;
-      this.styles[0] = styles;
-      this.querylayers[0] = querylayers;   
-   }
-   else{
-	this.wms = [];
-	for(i=0; i<wms.length; i++){
-		this.wms[i] = wms[i];
-		this.wms[i].mapURL = false;
+	if (wms_index !== null){
+		this.wms = [];
+		this.wms[0] = wms[wms_index];
+		this.wms[0].mapURL = false;
+		var cnt_layers = 0;
+		var cnt_querylayers = 0;
+		var styles = "";
+		var layers = "";
+		var querylayers = "";
+		for (var ii=0; ii<this.wms[0].objLayer.length; ii++){
+			if (this.wms[0].objLayer[ii].gui_layer_visible == 1 && ii>0){
+				if (cnt_layers > 0) {
+					layers += ","; styles += ","; 
+				}
+				layers += this.wms[0].objLayer[ii].layer_name; 
+				styles += ""; 
+				cnt_layers++;
+			}   
+			if (this.wms[0].objLayer[ii].gui_layer_querylayer == 1 && ii>0) {
+				if (cnt_querylayers > 0) {
+					querylayers += ",";
+				}
+				querylayers += this.wms[0].objLayer[ii].layer_name; 
+				cnt_querylayers++;
+			}                      
+		}
+		this.layers[0] = layers;
+		this.styles[0] = styles;
+		this.querylayers[0] = querylayers;   
 	}
-      for(var i=0; i< this.wms.length; i++){
-         var cnt_layers = 0;
-         var cnt_querylayers = 0;
-         var styles = "";
-         var layers = "";
-         var querylayers = "";
-         for(var ii=0; ii<this.wms[i].objLayer.length; ii++){
-            if(this.wms[i].objLayer[ii].gui_layer_visible == 1 && ii>0){
-               if(cnt_layers > 0){layers += ","; styles += ","; }
-               layers += wms[i].objLayer[ii].layer_name; 
-               styles += ""; 
-               cnt_layers++;
-            }            
-            if(this.wms[i].objLayer[ii].gui_layer_querylayer == 1 && ii>0){
-               if(cnt_querylayers > 0){querylayers += ",";}
-               querylayers += wms[i].objLayer[ii].layer_name; 
-               cnt_querylayers++;
-            }                          
-         }
-         this.layers[i] = layers;
-         this.styles[i] = styles;
-         this.querylayers[i] = querylayers;
-      }
-   }
+	else {
+		this.wms = [];
+		for(var i=0; i<wms.length; i++){
+			this.wms[i] = wms[i];
+			this.wms[i].mapURL = false;
+		}
+		for(i=0; i< this.wms.length; i++){
+			var cnt_layers = 0;
+			var cnt_querylayers = 0;
+			var styles = "";
+			var layers = "";
+			var querylayers = "";
+			for(var ii=0; ii<this.wms[i].objLayer.length; ii++){
+				if(this.wms[i].objLayer[ii].gui_layer_visible == 1 && ii>0){
+					if(cnt_layers > 0){
+						layers += ","; styles += ","; 
+					}
+					layers += wms[i].objLayer[ii].layer_name; 
+					styles += ""; 
+					cnt_layers++;
+				}            
+				if(this.wms[i].objLayer[ii].gui_layer_querylayer == 1 && ii>0){
+					if(cnt_querylayers > 0){
+						querylayers += ",";
+					}
+					querylayers += wms[i].objLayer[ii].layer_name; 
+					cnt_querylayers++;
+				}                          
+			}
+			this.layers[i] = layers;
+			this.styles[i] = styles;
+			this.querylayers[i] = querylayers;
+		}
+	}
    this.epsg = wms[0].gui_wms_epsg;
    this.extent = setExtent(this.width,this.height,this.epsg);
    this.mapURL = [];
@@ -342,11 +457,63 @@
 	 * @type integer  
 	 */
 	this.getScale = function(){
+		var scale;
 		var bbox = this.extent.split(",");
-		var xtenty =  parseFloat(bbox[3]) - parseFloat(bbox[1]);
-		var scale = (xtenty / this.height) * (mb_resolution * 100);
+		var xtenty;
+		if(this.epsg=="EPSG:4326"){
+			var pxLenx = (parseFloat(bbox[2])-parseFloat(bbox[0]))/this.width;
+			var pxLeny = (parseFloat(bbox[3])-parseFloat(bbox[1]))/this.height;
+			var lat_from = ((parseFloat(bbox[3])-parseFloat(bbox[1])/2)*Math.PI)/180;
+			var lat_to = ((parseFloat(bbox[3])-parseFloat(bbox[1])/2+pxLeny)*Math.PI)/180;
+			var lon_from = ((parseFloat(bbox[2])-parseFloat(bbox[0])/2)*Math.PI)/180;
+			var lon_to = ((parseFloat(bbox[2])-parseFloat(bbox[0])/2+pxLeny)*Math.PI)/180;
+			var dist=6371229*Math.acos(Math.sin(lat_from)*Math.sin(lat_to)+Math.cos(lat_from)*Math.cos(lat_to)*Math.cos(lon_from-lon_to));
+			scale = (dist/Math.SQRT2) * (mb_resolution * 100);
+		}else{
+			xtenty =  parseFloat(bbox[3]) - parseFloat(bbox[1]);
+			scale = (xtenty / this.height) * (mb_resolution * 100);
+		}
 		return Math.round(scale);
 	};
+	/**
+	 * move a wms or layer 
+	 *
+	 * @param int wms_id id of wms to move
+	 * @param int layer_id id of layer to move
+	 * @return true of successful
+	 * @type boolean
+	 */
+	this.move = function(wms_id, layer_id, moveUp){
+		var i,j;
+		for(i=0;i<this.wms.length;i++){
+			if(wms_id==this.wms[i].wms_id)
+				break;
+		}
+		
+		//check if only one wms is affected?
+		if(layer_id&&layer_id!=this.wms[i].objLayer[0].layer_id)
+			return this.wms[i].moveLayer(layer_id, moveUp);
+		
+		//else swap wms
+		j = i + (moveUp?-1:1);
+		if (!(i != j && i >= 0 && i < this.wms.length && j >= 0 && j < this.wms.length))
+			return false;
+		
+		upper = this.wms[i];
+		this.wms[i] = this.wms[j];
+		this.wms[j] = upper;
+		var upperLayers = this.layers[i];
+		var upperStyles = this.styles[i];
+		var upperQuerylayers = this.querylayers[i];
+		this.layers[i] = this.layers[j];
+		this.styles[i] = this.styles[j];
+		this.querylayers[i] = this.querylayers[j];
+		this.layers[j] = upperLayers;
+		this.styles[j] = upperStyles;
+		this.querylayers[j] = upperQuerylayers;
+		
+		return true;
+	}
 	
    for(var i=0; i<mb_MapObjectSubFunctions.length; i++){
       eval(mb_MapObjectSubFunctions[i]);
@@ -555,23 +722,32 @@
 	for(var i=0; i<mb_mapObj.length; i++){
 		var newMapRequest = "";
 		if(mb_mapObj[i].frameName == frameName){
-			//for the new class-methods:
-			mb_mapObj[i].getMapRequests();
 			for(var ii=0; ii<mb_mapObj[i].wms.length; ii++){
 				if(mb_mapObj[i].wms[ii].gui_wms_visible > 0){
 					var myDivId = "div_" + ii;          
 					var myMapId = "map_" + ii;
 					//disable Layer which are out of scale
-					var str_LayerStyles = mb_checkScale(frameName,i,ii);
-					if(mb_mapObj[i].layers[ii] != "" && str_LayerStyles[0] != ''){
+					var validLayers = mb_checkScale(frameName,i,ii);
+					var layerNames = validLayers.toString();
+					if(mb_mapObj[i].layers[ii] != "" && validLayers != ''){
 						var newMapURL = "";
 
-// replaced by opacity version 
-//						newMapRequest += "<div id='"+myDivId+"' style='position:absolute; top:0px; left:0px; z-index:'"+ii+"'>";
+						if (mb_mapObj[i].wms[ii].gui_wms_mapopacity != 1) {
+ 							var cadenaOpacity = "opacity:"+mb_mapObj[i].wms[ii].gui_wms_mapopacity+"; Filter: Alpha(Opacity="+mb_mapObj[i].wms[ii].gui_wms_mapopacity*100+"); -moz-opacity:"+mb_mapObj[i].wms[ii].gui_wms_mapopacity+" ; -khtml-opacity:"+mb_mapObj[i].wms[ii].gui_wms_mapopacity;
+	 						newMapRequest += "<div id='"+myDivId+"' style=\"position:absolute; top:0px; left:0px; z-index:"+ii+";"+cadenaOpacity+"\">";
+						
+						}
+						// IE problem: layers that are already transparent (defined in map file) 
+						// are sabotaged by the Mapbender opacity setting...
+						// this solution helps to display these layers correctly if no opacity
+						// manipulation is taking place in Mapbender
+						//
+						// solution needed for both WMS and Mapbender transparency in IE
+						// see: 
+						else {
+							newMapRequest += "<div id='"+myDivId+"' style='position:absolute; top:0px; left:0px; z-index:'"+ii+"'>";
+						}
 
- 						var cadenaOpacity = "opacity:"+mb_mapObj[i].wms[ii].gui_wms_mapopacity+"; Filter: Alpha(Opacity="+mb_mapObj[i].wms[ii].gui_wms_mapopacity*100+"); -moz-opacity:"+mb_mapObj[i].wms[ii].gui_wms_mapopacity+" ; -khtml-opacity:"+mb_mapObj[i].wms[ii].gui_wms_mapopacity;
- 						newMapRequest += "<div id='"+myDivId+"' style=\"position:absolute; top:0px; left:0px; z-index:"+ii+";"+cadenaOpacity+"\">";
-
 						newMapRequest += "<img id='"+myMapId+"' name='mapimage' src='";
 						newMapURL += mb_mapObj[i].wms[ii].wms_getmap;   
 						
@@ -580,9 +756,21 @@
 						if(mb_mapObj[i].wms[ii].wms_version == "1.0.0"){newMapURL += "WMTVER="+mb_mapObj[i].wms[ii].wms_version+"&REQUEST=map&";}
 						if(mb_mapObj[i].wms[ii].wms_version != "1.0.0"){newMapURL += "VERSION="+mb_mapObj[i].wms[ii].wms_version+"&REQUEST=GetMap&SERVICE=WMS&";} 
 						
-						newMapURL += "LAYERS="+str_LayerStyles[0]+"&";
-						newMapURL += "STYLES="+str_LayerStyles[1]+"&";
-		
+						newMapURL += "LAYERS="+layerNames+"&";
+						newMapURL += "STYLES=";
+						var layer = layerNames.split(",");
+						for(var j=0; j<layer.length; j++){
+							if(j>0){
+								newMapURL  += ",";
+							}
+							if(mb_mapObj[i].wms[ii].getCurrentStyleByLayerName(layer[j])==false){
+								newMapURL  += "";
+							}
+							else{
+								newMapURL  += mb_mapObj[i].wms[ii].getCurrentStyleByLayerName(layer[j]);
+							}
+						}
+						newMapURL += "&";
 						newMapURL += "SRS="+mb_mapObj[i].epsg+"&";
 						newMapURL += "BBOX="+mb_mapObj[i].extent+"&";
 						newMapURL += "WIDTH="+mb_mapObj[i].width+"&";
@@ -636,6 +824,7 @@
 					}
 				}
 			}
+			//console.log(newMapRequest);
 			//prompt("",newMapRequest);
 			writeTag(mb_mapObj[i].frameName,mb_mapObj[i].elementName,newMapRequest);
 		}
@@ -646,12 +835,13 @@
 }
 function setSingleMapRequest(frameName,wms_id){
 	var functionName = 'setSingleMapRequest';
+	
 	var ts = mb_timestamp();	
 	
 	for(var i=0; i<mb_MapRequestPreFunctions.length; i++){
 		eval(mb_MapRequestPreFunctions[i]);
 	}	
-	for(var i=0; i<mb_mapObj.length; i++){
+	for(i=0; i<mb_mapObj.length; i++){
 		var newMapRequest = "";
 		if(mb_mapObj[i].frameName == frameName){
 			for(var ii=0; ii<mb_mapObj[i].wms.length; ii++){ 
@@ -668,9 +858,23 @@
 					if(mb_mapObj[i].wms[ii].wms_version != "1.0.0"){newMapURL += "VERSION="+mb_mapObj[i].wms[ii].wms_version+"&REQUEST=GetMap&SERVICE=WMS&";}             
 					
 					//disable Layer which are out of scale
+					var validLayers = mb_checkScale(frameName,i,ii);
+					var layerNames = validLayers.toString();
 					var str_LayerStyles = mb_checkScale(frameName,i,ii); 
 
-					newMapURL += "LAYERS="+str_LayerStyles[0]+"&";
+					newMapURL += "LAYERS="+layerNames+"&";
+					var layer = layerNames.split(",");
+					for(var j=0; j<layer.length; j++){
+						if(j>0){
+							newMapURL  += ",";
+						}
+						if(mb_mapObj[i].wms[ii].getCurrentStyleByLayerName(layer[j])==false){
+							newMapURL  += "";
+						}
+						else{
+							newMapURL  += mb_mapObj[i].wms[ii].getCurrentStyleByLayerName(layer[j]);
+						}
+					}
 					newMapURL += "STYLES="+str_LayerStyles[1]+"&";
          
 					newMapURL += "SRS="+mb_mapObj[i].epsg+"&";
@@ -707,8 +911,10 @@
 						var temp = "&SLD=" + escape(mb_mapObj[i].wms[ii].gui_wms_sldurl) + "&";
 						newMapURL += temp;
 					}
+
 					//prompt("",newMapURL);
-					if(mb_mapObj[i].layers[ii] != "" && str_LayerStyles[0] != ""){
+					if(mb_mapObj[i].layers[ii] != ""){
+//					if(mb_mapObj[i].layers[ii] != "" && str_LayerStyles[0] != ""){
 						newMapRequest += newMapURL;
 						mb_mapObj[i].mapURL[ii] = newMapURL;
 						mb_mapObj[i].wms[ii].mapURL = newMapURL;
@@ -720,6 +926,7 @@
 						newMapRequest = "<img id='"+myMapId+"' name='mapimage' src='" + mb_trans.src;
 						newMapRequest += "' width='"+mb_mapObj[i].width+"' height='"+mb_mapObj[i].height+"' border='0'>";
 					}        
+
 					//prompt("",newMapRequest);
 					if(mb_log){
 						var tmp = eval(mb_log + "('" + newMapURL + "','" + ts + "')");
@@ -729,6 +936,7 @@
 			}           
 		}      
 	}   
+	
 	for(var i=0; i<mb_MapRequestSubFunctions.length; i++){
 		eval(mb_MapRequestSubFunctions[i]);
 	}  
@@ -744,14 +952,14 @@
 			var styles = "";
 			var querylayers = "";
 			for(var ii=0; ii<mb_mapObj[ind].wms[i].objLayer.length; ii++){
-				if(mb_mapObj[ind].wms[i].objLayer[ii].gui_layer_visible == 1 && ii>0){
+				if(mb_mapObj[ind].wms[i].objLayer[ii].gui_layer_visible == 1 && !mb_mapObj[ind].wms[i].objLayer[ii].has_childs){
 					if(cnt_layers > 0){layers += ","; styles += ","; }
 					layers += mb_mapObj[ind].wms[i].objLayer[ii].layer_name;
 					//alert(mb_mapObj[ind].wms[i].objLayer[ii].layer_name); 
 					styles += ""; 
 					cnt_layers++;
 				}            
-				if(mb_mapObj[ind].wms[i].objLayer[ii].gui_layer_querylayer == 1 && ii>0){
+				if(mb_mapObj[ind].wms[i].objLayer[ii].gui_layer_querylayer == 1 && !mb_mapObj[ind].wms[i].objLayer[ii].has_childs){
 					if(cnt_querylayers > 0){querylayers += ",";}
 					querylayers += mb_mapObj[ind].wms[i].objLayer[ii].layer_name; 
 					cnt_querylayers++;
@@ -810,12 +1018,13 @@
 	return str_layerstyles;
 }
 function setFeatureInfoRequest(fName,x,y, path) {
+	var functionName = 'setFeatureInfoRequest';
 	var ts = mb_timestamp();
 	for(var i=0; i<mb_FeatureInfoPreFunctions.length; i++){
 		eval(mb_FeatureInfoPreFunctions[i]);
 	}   
 	var cnt_fi = 0;
-	for(var i=0; i<mb_mapObj.length; i++){
+	for(i=0; i<mb_mapObj.length; i++){
 		if(mb_mapObj[i].frameName == fName){
 			for(var ii=0; ii<mb_mapObj[i].wms.length; ii++){
 				var newfeatureInfoRequest = "";
@@ -865,14 +1074,25 @@
             	}
 				else if(path && validation){
 					newfeatureInfoRequest += requestParams
-					window.open(path + "?url=" + escape(newfeatureInfoRequest)+"&"+mb_nr, "" , "width=300,height=400,scrollbars=yes,resizable=yes");
+					try{
+						var p = new mb_popup("Feature Info","url:"+path + "?url=" + escape(newfeatureInfoRequest)+"&"+mb_nr,300,400);
+						p.show();
+					}catch(e){
+						window.open(path + "?url=" + escape(newfeatureInfoRequest)+"&"+mb_nr, "" , "width=300,height=400,scrollbars=yes,resizable=yes");
+					}
 					cnt_fi++;
 				}
 				else if(validation){
 					newfeatureInfoRequest += requestParams;
-					window.open(newfeatureInfoRequest, "" , "width=300,height=400,scrollbars=yes,resizable=yes");
-					cnt_fi++;          
-				}      
+					try{
+						var p = new  mb_popup("Feature Info","url:"+newfeatureInfoRequest,300,400);
+						p.show();
+					}
+					catch(e){
+						window.open(newfeatureInfoRequest, "" , "width=300,height=400,scrollbars=yes,resizable=yes");					
+					}
+					cnt_fi++;
+				}    
 			}
 		}
 	}
@@ -1510,7 +1730,15 @@
 				alert(message);
 			}
 			else if (log_js == "console") {
-				console.log("%s", message);
+				if (level == "warning") {
+					console.warn("%s", message);
+				}
+				else if (level == "error") {
+					console.error("%s", message);
+				}
+				else {
+					console.log("%s", message);
+				}
 			}
 		}
 	};
@@ -1523,7 +1751,7 @@
  * @param message the message that is being logged
  */	
 function Mb_exception(message) {
-	var level = "error";
+	 var level = "error";
 	this.throwException(message, level);
 }
 Mb_exception.prototype = new Mb_log();
@@ -1533,13 +1761,13 @@
  *
  * @extends {@link Mb_log}
  * @param message the message that is being logged
- */	
+ */
 function Mb_warning(message) {
 	var level = "warning";
 	this.throwException(message, level);
 }
 Mb_warning.prototype = new Mb_log();
-
+ 
 /**
  *  class for notice logging
  *
@@ -1570,7 +1798,7 @@
 		mb_ajaxWrap_get(url, param, callback);
 	}
 	catch(e) {
-		alert('map.php: mb_ajax_get:'+e);
+		var error = new Mb_exception('map.php: mb_ajax_get:'+e);
 	}
 }	
 
@@ -1586,7 +1814,7 @@
 		mb_ajaxWrap_post(url, param, callback);
 	}
 	catch(e) {
-		alert('map.php: mb_ajax_post:'+e);
+		var error = new Mb_exception('map.php: mb_ajax_post:'+e);
 	}
 }	
 	
@@ -1602,7 +1830,7 @@
 		mb_ajaxWrap_json(url, param, callback);
 	}
 	catch(e) {
-		alert('map.php: mb_ajax_json:'+e);
+		var error = new Mb_exception('map.php: mb_ajax_json:'+e);
 	}
 }	
 	
@@ -1722,6 +1950,30 @@
       }
    }
 }
+function updateButtonTooltips(obj) {
+//	console.log("begin tooltip update");
+	for(var i=0; i<mb_button.length; i++){
+//		console.log("button %i", i);
+		for(var j=0; j<obj.length; j++){
+//			console.log("%s %s", mb_button[i].elName, obj[j].id);
+			if (mb_button[i].elName == obj[j].id) {
+				if (mb_button[i].frameName != "") {
+					window.frames[mb_button[i].frameName].document.getElementById(mb_button[i].elName).title = obj[j].title;
+				}
+				else {
+					document.getElementById(mb_button[i].elName).title = obj[j].title;
+				}
+				
+			}
+		}
+	}
+}
+function mb_localizeButtons() {
+	mb_ajax_json("../php/mod_button_tooltips.php", function(obj, status){
+		updateButtonTooltips(obj);
+	});
+}
+mb_registerInitFunctions("mb_registerL10nFunctions('mb_localizeButtons()');");
 
 /*
  ***************************************************************************************
@@ -1854,80 +2106,6 @@
 
 
 /*
- ***************************************************************************************
- *   register functions
- ***************************************************************************************
- */
-
-var mb_MapRequestSubFunctions = [];
-var mb_WfsReadSubFunctions = [];
-var mb_WfsWriteSubFunctions = [];
-var mb_MapRequestPreFunctions = [];
-var mb_FeatureInfoPreFunctions = [];
-var mb_InitFunctions = [];
-var mb_MapObjectSubFunctions = [];
-var mb_GetScalePreFunctions = [];
-var mb_loadWmsSubFunctions = [];
-
-function mb_registerInitFunctions(stringFunction){
-	mb_InitFunctions[mb_InitFunctions.length] = stringFunction;
-}
-function mb_registerPreFunctions(stringFunction){
-	mb_MapRequestPreFunctions[mb_MapRequestPreFunctions.length] = stringFunction;
-}
-function mb_registerFeatureInfoPreFunctions(stringFunction){
-	mb_FeatureInfoPreFunctions[mb_FeatureInfoPreFunctions.length] = stringFunction;
-}
-function mb_registerSubFunctions(stringFunction){
-	mb_MapRequestSubFunctions[mb_MapRequestSubFunctions.length] = stringFunction;
-}
-function mb_registerMapObjectSubFunctions(stringFunction){
-	mb_MapObjectSubFunctions[mb_MapObjectSubFunctions.length] = stringFunction;
-}
-function mb_registerGetScalePreFunctions(stringFunction){
-	mb_GetScalePreFunctions[mb_GetScalePreFunctions.length] = stringFunction;
-}
-function mb_registerloadWmsSubFunctions(stringFunction){
-	mb_loadWmsSubFunctions[mb_loadWmsSubFunctions.length] = stringFunction;
-}
-function mb_registerWfsReadSubFunctions(stringFunction){
-	mb_WfsReadSubFunctions[mb_WfsReadSubFunctions.length] = stringFunction;
-}
-function mb_registerWfsWriteSubFunctions(stringFunction){
-	mb_WfsWriteSubFunctions[mb_WfsWriteSubFunctions.length] = stringFunction;
-}
-function mb_removeFunctionFromArray(arrayname,stringFunction){
-	var length = eval(arrayname+".length");
-	for(var i=0; i<length; i++){
-		if(eval(arrayname+"["+i+"]") == stringFunction){
-			var newArray1 = eval(arrayname+".slice(0, "+(i-1)+")");
-			var newArray2 = eval(arrayname+".slice("+(i+1)+", "+length+")");
-			eval(arrayname + " = newArray1.concat(newArray2)");
-			i--;
-			length--;
-		}
-	}
-}
- 
-function mb_execloadWmsSubFunctions(){
-	for(var i=0; i<mb_loadWmsSubFunctions.length; i++){
-		eval(mb_loadWmsSubFunctions[i]); 	 
-	} 	 
-}
-
-function mb_execWfsReadSubFunctions(geom) { 	 
-	for(var i=0; i<mb_WfsReadSubFunctions.length; i++){ 	 
-		mb_WfsReadSubFunctions[i](geom); 	 
-	} 	 
-}
-
-function mb_execWfsWriteSubFunctions() { 	 
-	for(var i=0; i<mb_WfsWriteSubFunctions.length; i++){
-		mb_WfsWriteSubFunctions[i](); 	 
-	} 	 
-}
-
-/*
  * first draft of a redesign
  *
 var FunctionArray = function() {

Modified: branches/mapbender_sld/http/javascripts/map_obj.js
===================================================================
--- branches/mapbender_sld/http/javascripts/map_obj.js	2007-11-23 14:13:44 UTC (rev 1846)
+++ branches/mapbender_sld/http/javascripts/map_obj.js	2007-11-23 14:23:24 UTC (rev 1847)
@@ -96,11 +96,13 @@
    
 	if (!wms_id) {
 		var id_ok = false;
-		while (id_ok == false) {
+		while (id_ok === false) {
 			wms_id = "a"+Math.round(10000*Math.random());
 			id_ok = true;
-			for (var i=0; i < wms.length && id_ok == true; i++) {
-				if (wms_id == wms[i].wms_id) id_ok = false;
+			for (var i=0; i < wms.length && id_ok === true; i++) {
+				if (wms_id == wms[i].wms_id) { 
+					id_ok = false;
+				}
 			}
 		}
 	}
@@ -141,7 +143,6 @@
  * @type String
  */
 wms_const.prototype.getMapRequest = function(mapObj){	
-	console.log()
 	//check visible layers first
 	var layers = this.getLayers(mapObj);
 	if(!layers){
@@ -166,7 +167,7 @@
 	rq += "&FORMAT=" + this.gui_wms_mapformat;
 	rq += "&EXCEPTIONS=" + this.gui_wms_exceptionformat;
 	//Todo: error occurs:
-	var throwNotice = new Mb_notice("getMapRequest: " + rq);
+	//var throwNotice = new Mb_notice("getMapRequest: " + rq);
 	//window.console.log("getMapRequest: " + rq);
 	return rq;
 };
@@ -211,7 +212,7 @@
 	rq += "&EXCEPTIONS=application/vnd.ogc.se_xml";
 	rq += "&X=" + clickPoint.x;
 	rq += "&Y=" + clickPoint.y;
-	console.log(rq);
+	//console.log(rq);
 	return rq;
 };
 
@@ -223,6 +224,7 @@
  */
 wms_const.prototype.getLayers = function(mapObj){
 	
+	try {
 	//visibility of the wms
 	var wmsIsVisible = (this.gui_wms_visible > 0);
 	if(!wmsIsVisible){
@@ -230,7 +232,9 @@
 	}
 	visibleLayers = [];
 	for(var i=0; i< this.objLayer.length; i++){
-		if(this.objLayer[i].gui_layer_visible === 1 && this.objLayer[i].layer_parent !== ''){
+		var isVisible = (this.objLayer[i].gui_layer_visible === 1);
+		var hasNoChildren = (!this.objLayer[i].has_childs);
+		if (isVisible && hasNoChildren){
 			if(this.objLayer[i].checkScale(mapObj)){
 				//console.log("checkLayer: " + this.objLayer[i].layer_name);
 				visibleLayers.push(this.objLayer[i].layer_name);
@@ -241,9 +245,12 @@
 		return false;
 	}
 	return visibleLayers;
+	}
+	catch (e) {
+		alert(e);
+	}
 };
 
-
 /**
  * get the actual style of all visible layers
  *
@@ -256,11 +263,11 @@
 	var styles = [];
 	if(layers){
 		for(i = 0; i < layers.length; i++){
-			var style = this.getStyleByLayerName(layers[i]);
+			var style = this.getCurrentStyleByLayerName(layers[i]);
 			if(!style){
 				style = '';
 			}
-			styles.push(style)
+			styles.push(style);
 		}
 		return styles;
 	}
@@ -268,13 +275,81 @@
 };
 
 /**
- * get the style of the layer
+ * check if layer is parentLayer
  *
  * @param layername
+ * @return the parent value of the given layer
+ * @type integer
+ */
+wms_const.prototype.checkLayerParentByLayerName = function(layername){
+	for(var i=0; i< this.objLayer.length; i++){
+		if(this.objLayer[i].layer_name == layername){
+			return this.objLayer[i].layer_parent;
+		}
+	}
+};
+
+/**
+ * get the title of the current layer
+ *
+ * @param layername
+ * @return the title of the given layer
+ * @type string
+ */
+wms_const.prototype.getTitleByLayerName = function(layername){
+	for(var i=0; i< this.objLayer.length; i++){
+		if(this.objLayer[i].layer_name == layername){
+			return this.objLayer[i].layer_title;
+		}
+	}
+};
+
+/**
+ * get the current style of the layer
+ *
+ * @param layername
  * @return the stylename of the given layer
  * @type string
  */
-wms_const.prototype.getStyleByLayerName = function(layername){
+wms_const.prototype.getCurrentStyleByLayerName = function(layername){
+	for(var i=0; i< this.objLayer.length; i++){
+		if(this.objLayer[i].layer_name == layername){
+			if(this.objLayer[i].gui_layer_style === '' || this.objLayer[i].gui_layer_style === null){
+				return false;
+			}
+			else{
+				return this.objLayer[i].gui_layer_style;	
+			}
+		}
+	}
+};
+
+/**
+ * get the legendurl of the gui layer style
+ *
+ * @param stylename
+ * @return the legendurl of the given style
+ * @type string
+ */
+wms_const.prototype.getLegendUrlByGuiLayerStyle = function(layername,guiLayerStyle){
+	for(var i=0; i< this.objLayer.length; i++){
+		if(this.objLayer[i].layer_name == layername){
+			if(this.objLayer[i].layer_style.length === 0){
+				return false;
+			}
+			for(var k=0; k< this.objLayer[i].layer_style.length; k++){
+				if(this.objLayer[i].layer_style[k].name == guiLayerStyle){
+					var legendUrl = this.objLayer[i].layer_style[k].legendurl;
+					if(legendUrl !=='' && legendUrl !== null && typeof(legendUrl) != 'undefined'){
+						return legendUrl;
+					}
+					else {
+						return false;
+					}
+				}
+			}
+		}
+	}
 	return false;
 };
 
@@ -287,7 +362,7 @@
 wms_const.prototype.getQuerylayers = function(){
 	queryLayers = [];
 	for(var i=0; i< this.objLayer.length; i++){
-		if(this.objLayer[i].gui_layer_querylayer === 1 && this.objLayer[i].layer_parent !== '' ){
+		if(this.objLayer[i].gui_layer_querylayer === 1 && ! this.objLayer[i].has_childs ){
 			queryLayers.push(this.objLayer[i].layer_name);
 		}
 	}
@@ -297,7 +372,188 @@
 	return queryLayers;
 };
 
+/**
+ * get a layer Object by layer_pos
+ * 
+ * @param int payer_pos layer_pos of layer you want to get
+ * @return object layer
+ */
 
+wms_const.prototype.getLayerByLayerPos = function(layer_pos){
+	for(var i=0;i<this.objLayer.length;i++){
+		if(this.objLayer[i].layer_pos == layer_pos) {
+			return this.objLayer[i];
+		}
+	}
+	return null;
+};
+/**
+ * get the state of sublayers from a specified layer
+ * 
+ * @param int layer_id of the parent layer
+ * @param String type "visible" or "querylayer"
+ * @return int -1 if state differs else the state
+ */
+
+wms_const.prototype.getSublayerState = function(layer_id, type){
+	var i;
+	var state=-1,value;
+	for(i = 0; i < this.objLayer.length; i++){
+		if(this.objLayer[i].layer_id==layer_id) {
+			break;
+		}
+	}
+	
+	//go throught sublayers
+	for(var j = i+1; j < this.objLayer.length; j++){
+		if(this.objLayer[i].parent_layer == this.objLayer[j].parent_layer) {
+			break;
+		}
+		if(type == "visible") {
+			value = this.objLayer[j].gui_layer_visible;
+		}
+		else if(type == "querylayer") {
+			value = this.objLayer[j].gui_layer_querylayer;
+		}
+		if(state == -1) {
+			state = value;
+		}
+		if(state != value) {
+			return -1;
+		}
+	}
+	
+	return state;
+};
+/**
+ * handle change of visibility / quaryability of a layer
+ * 
+ * @param string layer_name of layer to handle
+ * @param string type of change ("visible" or "querylayer")
+ * @param int value of the change
+ */
+wms_const.prototype.handleLayer = function(layer_name, type, value){
+	var i;
+	for(i = 0; i < this.objLayer.length; i++){
+		if(this.objLayer[i].layer_name==layer_name) {
+			break;
+		}
+	}
+	
+	//Set visibility/queryability of Layer and Sublayers
+	for(var j = i; j < this.objLayer.length; j++){
+		if (i != j && this.objLayer[i].layer_parent == this.objLayer[j].layer_parent) {
+			break;
+		}
+		if(type == "visible") {
+			this.objLayer[j].gui_layer_visible = parseInt(value);
+		}
+		else if(type=="querylayer") {
+			this.objLayer[j].gui_layer_querylayer = parseInt(value);
+		}
+	}
+
+	//Update visibility/queryability of parent layer
+	var parentLayer = this.getLayerByLayerPos(this.objLayer[i].layer_parent);
+	if(parentLayer){
+		var state = this.getSublayerState(parentLayer.layer_id, type);
+		if(state!=-1){
+			if(type == "visible") {
+				this.objLayer[j].gui_layer_visible = state;
+			}
+			else if(type=="querylayer") {
+				this.objLayer[j].gui_layer_querylayer = state;
+			}
+		}		
+	}
+};
+
+
+/**
+ * move a layer (with his sublayers) up or down
+ * 
+ * @param int layerId layer_id of layer to move
+ * @param boolean moveUp true to move up or false to move down
+ * @return boolean success
+ */
+
+wms_const.prototype.moveLayer = function(layerId, moveUp){
+	var iLayer=-1;
+	var i;
+	
+	//find layer to move
+	for(i=0;i<this.objLayer.length;i++){
+		if(this.objLayer[i].layer_id==layerId){
+			iLayer=i;
+			break;
+		}
+	}
+	if(iLayer==-1) {
+		return false;
+	}
+	
+	var upperLayer = -1;
+	var lowerLayer = -1;
+	
+	//find layer to swap position with
+	var parentLayer = this.objLayer[iLayer].layer_parent;	
+	if(moveUp){
+		lowerLayer = iLayer;
+		
+		//find previous layer on same level
+		for(i=iLayer-1;i>0;i--){
+			if(parentLayer == this.objLayer[i].layer_parent){
+				upperLayer = i;
+				break;
+			}
+		}
+		if(upperLayer == -1){
+			//alert("The Layer you selected is already on top of parent Layer/WMS");
+			return false;
+		}
+	}
+	else{
+		upperLayer = iLayer;
+		
+		//find next layer on same level
+		for(i=iLayer+1;i<this.objLayer.length;i++){
+			if(parentLayer == this.objLayer[i].layer_parent){
+				lowerLayer = i;
+				break;
+			}
+		}
+		if(lowerLayer == -1){
+			//alert("The Layer you selected is already on bottom of parent Layer/WMS");
+			return false;
+		}
+	}
+	
+	//calc number of layers to move down
+	var layersDown = lowerLayer - upperLayer;
+	
+	//get number of layers to move up
+	for(i=lowerLayer+1; i<this.objLayer.length; i++){
+		if(parentLayer == this.objLayer[i].layer_parent){
+			break;
+		}
+	}
+	var layersUp = i - lowerLayer;
+	
+	//do moving
+	var temp = [];
+	for(i=0;i<layersDown+layersUp;i++){
+		temp[temp.length]=this.objLayer[upperLayer+i];
+	}
+	for(i=0;i<layersUp;i++){
+		this.objLayer[upperLayer+i]=temp[i+layersDown];
+	}
+	for(i=0;i<layersDown;i++){
+		this.objLayer[upperLayer+layersUp+i]=temp[i];
+	}
+
+	return true;
+};
+
 function wms_add_data_type_format(datatype,dataformat){
 	var insertDataFormat = true;
 	for (var i = 0 ; i < wms[wms.length-1].data_type.length ; i ++) {
@@ -305,7 +561,7 @@
 			insertDataFormat = false;
 		}
 	}
-	if (insertDataFormat == true) {
+	if (insertDataFormat === true) {
 		wms[wms.length-1].data_type[wms[wms.length-1].data_type.length] = datatype;
 		wms[wms.length-1].data_format[wms[wms.length-1].data_format.length] = dataformat;
 	}
@@ -320,11 +576,11 @@
 function wms_addLayerStyle(styleName, styleTitle, count, layerCount, styleLegendUrl, styleLegendUrlFormat){
 	var currentLayer = wms[wms.length-1].objLayer[layerCount]; 
 	if (currentLayer) {
-		currentLayer.layer_style[count] = [];
-		currentLayer.layer_style[count]["name"] = styleName;
-		currentLayer.layer_style[count]["title"] = styleTitle;
-		currentLayer.layer_style[count]["legendurl"] = styleLegendUrl;
-		currentLayer.layer_style[count]["legendurlformat"] = styleLegendUrlFormat;
+		currentLayer.layer_style[count] = {};
+		currentLayer.layer_style[count].name = styleName;
+		currentLayer.layer_style[count].title = styleTitle;
+		currentLayer.layer_style[count].legendurl = styleLegendUrl;
+		currentLayer.layer_style[count].legendurlformat = styleLegendUrlFormat;
 	}
 }
 //TODO: add layerstyle handling....
@@ -342,6 +598,7 @@
 			layer_metadataurl,
 			gui_layer_wms_id,
 			gui_layer_status,
+			gui_layer_style,
 			gui_layer_selectable,
 			gui_layer_visible,
 			gui_layer_queryable,
@@ -363,6 +620,7 @@
 											layer_metadataurl,
 											gui_layer_wms_id,
 											gui_layer_status,
+											gui_layer_style,
 											parseInt(gui_layer_selectable),
 											parseInt(gui_layer_visible),
 											parseInt(gui_layer_queryable),
@@ -370,17 +628,21 @@
 											parseInt(gui_layer_minscale),
 											parseInt(gui_layer_maxscale),
 											gui_layer_wfs_featuretype );
+	var parentLayer = wms[wms.length-1].getLayerByLayerPos(parseInt(layer_parent));
+	if(parentLayer) {
+		parentLayer.has_childs = true;
+	}
 }
 function layer_addEpsg(epsg,minx,miny,maxx,maxy){
 	var j = wms[wms.length-1].objLayer.length-1;
 	var k = wms[wms.length-1].objLayer[j].layer_epsg.length;
 	var currentLayer = wms[wms.length-1].objLayer[j];
-	currentLayer.layer_epsg[k]=[];
-	currentLayer.layer_epsg[k]["epsg"]=epsg;
-	currentLayer.layer_epsg[k]["minx"]=minx;
-	currentLayer.layer_epsg[k]["miny"]=miny;
-	currentLayer.layer_epsg[k]["maxx"]=maxx;
-	currentLayer.layer_epsg[k]["maxy"]=maxy;
+	currentLayer.layer_epsg[k]={};
+	currentLayer.layer_epsg[k].epsg = epsg;
+	currentLayer.layer_epsg[k].minx = minx;
+	currentLayer.layer_epsg[k].miny = miny;
+	currentLayer.layer_epsg[k].maxx = maxx;
+	currentLayer.layer_epsg[k].maxy = maxy;
 }
 function wms_layer(
 			layer_parent,
@@ -395,6 +657,7 @@
 			layer_metadataurl,
 			gui_layer_wms_id,
 			gui_layer_status,
+			gui_layer_style,
 			gui_layer_selectable,
 			gui_layer_visible,
 			gui_layer_queryable,
@@ -422,8 +685,10 @@
 	this.gui_layer_querylayer = gui_layer_querylayer;
 	this.gui_layer_minscale = gui_layer_minscale;
 	this.gui_layer_maxscale = gui_layer_maxscale;
+	this.gui_layer_style = gui_layer_style;
 	this.gui_layer_wfs_featuretype = gui_layer_wfs_featuretype;
-	this.gui_layer_style;
+	this.gui_layer_style = null;
+	this.has_childs = false;
 	this.layer_style = [];
 	wms_layer_count++;
 }
@@ -435,14 +700,32 @@
  * @type boolean
  */
 wms_layer.prototype.checkScale = function(mapObj){
-	var minScale = this.gui_layer_minscale;
-	var maxScale = this.gui_layer_maxscale;
-	var currentScale = mapObj.getScale();
+	var minScale = parseInt(this.gui_layer_minscale);
+	var maxScale = parseInt(this.gui_layer_maxscale);
+	var currentScale = parseInt(mapObj.getScale());
 	if(minScale === 0 && maxScale === 0){
 		return true;
 	}
-	if(minScale < currentScale || maxScale > currentScale){
+	if(minScale > currentScale || (maxScale !== 0 && maxScale < currentScale)) {
 		return false;
 	}	
 	return true;
+};
+/**
+ * set visibility of the layer
+ * @param boolean visible visibility on/off
+ */
+wms_layer.prototype.setVisible = function(visible){
+	this.gui_layer_visible = parseInt(visible);
+	//console.log("setVisible(%i) for Layer %s",visible, this.layer_name);
+};
+
+/**
+ * set queryability of the layer
+ * @param boolean queryable queryability on/off
+ */
+
+wms_layer.prototype.setQueryable = function(queryable){
+	this.gui_layer_querylayer = parseInt(queryable);
+	//console.log("setQueryable(%i) for Layer %s",queryable, this.layer_name);
 };
\ No newline at end of file



More information about the Mapbender_commits mailing list