[OpenLayers-Commits] r3147 - sandbox/ominiverdi/openlayers/lib/OpenLayers/Control

commits at openlayers.org commits at openlayers.org
Sun May 13 09:57:27 EDT 2007


Author: ominiverdi
Date: 2007-05-13 09:57:27 -0400 (Sun, 13 May 2007)
New Revision: 3147

Modified:
   sandbox/ominiverdi/openlayers/lib/OpenLayers/Control/WMSManager.js
Log:
WMSManager (ticket #687): 
added:
WMS layer infos panel,
WMS select swith up and down to manager Layers WMS request,
extent control for multiple layers selection,

bugs:
IE support broken once again... the layers select is no more shown,
Layout problem: the maximize button for the panel disappears.

Modified: sandbox/ominiverdi/openlayers/lib/OpenLayers/Control/WMSManager.js
===================================================================
--- sandbox/ominiverdi/openlayers/lib/OpenLayers/Control/WMSManager.js	2007-05-10 10:20:52 UTC (rev 3146)
+++ sandbox/ominiverdi/openlayers/lib/OpenLayers/Control/WMSManager.js	2007-05-13 13:57:27 UTC (rev 3147)
@@ -67,6 +67,8 @@
     /** @type Array */
     aWMSServer: null,
 	
+	aWMSLayers: [],//Name:Title:Abstract:BoundingBox:LegendURL
+	
     //others
    
     /** @type Boolean */
@@ -717,10 +719,7 @@
 		
 		//alert('1');
 		//get Extent (to implent BoundingBox alternative) 
-		/*
-		 * this part drammatically need to set the right extent, somehow to every layer.
-		 * for the moment it catches the first bbox available.
-		 */
+		//this is a generical catch for a bbox the refining comes when layers are parsed
 		var bbox = xml.getElementsByTagName('LatLonBoundingBox')[0];
 		if(!bbox) bbox = xml.getElementsByTagName('BoundingBox')[0];
 		this.extent = [bbox.getAttribute('minx'),bbox.getAttribute('miny'),bbox.getAttribute('maxx'),bbox.getAttribute('maxy')];
@@ -765,11 +764,53 @@
 		//var opt = new Option( 'select a Layer', '', true, true );
 		//select[j++] = opt;
 		for(i=0;i<aLayers.length;i++){
+			try{
 			var nameNode = this.findChildByName(aLayers[i],'Name');
 			var titleNode = this.findChildByName(aLayers[i],'Title');
-			var name =(nameNode.textContent)? nameNode.textContent:nameNode.text;
-			var title =(titleNode.textContent)? titleNode.textContent:titleNode.text;
-			select[j++] = new Option(title,name,false,false);
+			var Name =(nameNode.textContent)? nameNode.textContent:nameNode.text;
+			var Title =(titleNode.textContent)? titleNode.textContent:titleNode.text;
+			var abstractNode =  this.findChildByName(aLayers[i],'Abstract');
+			if(abstractNode) var Abstract =(abstractNode.textContent)? abstractNode.textContent:abstractNode.text;
+			else var Abstract = null;
+			
+			select[j++] = new Option(Title,Name,false,false);
+			select.options[i].Title = Title;
+			select.options[i].Name = Name;
+			select.options[i].Abstract = Abstract;
+			select.options[i].onclick = function(){
+									var outObj = $('wmsLayerListOutput');
+									var mess = '<b>Layer Name:</b><br>'+this.Name +'<br><br><b>Layer Title:</b><br>'+this.Title +'<br><br><b>Abstract:</b><br>'+this.Abstract;
+									outObj.innerHTML = mess;
+								};				
+			
+			
+			
+			//Legend sta dentro Style
+			var legendNode = this.findChildByName(aLayers[i],'LegendURL');
+			if(legendNode) var LegendURL =(legendNode.textContent)? legendNode.textContent:legendNode.text;
+			else var LegendURL = null;
+			
+			
+			var bboxNode = this.findChildByName(aLayers[i],'BoundingBox');
+			var latbboxNode = this.findChildByName(aLayers[i],'LatLonBoundingBox');
+			
+			if (latbboxNode){
+				 var bbox = latbboxNode;
+				 var BoundingBox = [bbox.getAttribute('minx'),bbox.getAttribute('miny'),bbox.getAttribute('maxx'),bbox.getAttribute('maxy')];
+			} else if(bboxNode){
+				var bbox = bboxNode;
+				var BoundingBox = [bbox.getAttribute('minx'),bbox.getAttribute('miny'),bbox.getAttribute('maxx'),bbox.getAttribute('maxy')];
+			} else if(this.extent){
+				var BoundingBox = this.extent;
+			}
+			else  return alert('no bbox defined, check getCapabilities configuration');
+			
+			
+			//alert('61: '+Name+','+Title+','+Abstract+','+BoundingBox+','+LegendURL);
+			this.aWMSLayers.push([Name,Title,Abstract,BoundingBox,LegendURL]);
+			}
+			catch(e){alert(e);}
+			
 		}
 		formObj.appendChild(select);
 		
@@ -821,11 +862,98 @@
 		var layerBox = document.createElement('div');
 		layerBox.id = 'wmsLayerBox';
 		
+		//Buttons to switch layers up and down
+		var aSwitchUp = document.createElement("a");
+				aSwitchUp.innerHTML = '<span>&uarr;</span>';
+				aSwitchUp.className = 'olWMSLayerSwitch';
+				aSwitchUp.select = select;
+				aSwitchUp.onclick = function(){
+									var obj =  this.select;
+									//alert(obj[obj.selectedIndex].value);
+									var sel = new Array();
+									for (var i=0; i<obj.length; i++) {
+										if (obj[i].selected == true) {
+											sel[sel.length] = i;
+										}
+									}
+									for (i in sel) {
+										if (sel[i] != 0 && !obj[sel[i]-1].selected) {
+											var tmp = new Array((document.body.innerHTML ? obj[sel[i]-1].innerHTML : obj[sel[i]-1].text), obj[sel[i]-1].value, obj[sel[i]-1].style.color, obj[sel[i]-1].style.backgroundColor, obj[sel[i]-1].className, obj[sel[i]-1].id);
+											if (document.body.innerHTML) obj[sel[i]-1].innerHTML = obj[sel[i]].innerHTML;
+											else obj[sel[i]-1].text = obj[sel[i]].text;
+											obj[sel[i]-1].value = obj[sel[i]].value;
+											obj[sel[i]-1].style.color = obj[sel[i]].style.color;
+											obj[sel[i]-1].style.backgroundColor = obj[sel[i]].style.backgroundColor;
+											obj[sel[i]-1].className = obj[sel[i]].className;
+											obj[sel[i]-1].id = obj[sel[i]].id;
+											if (document.body.innerHTML) obj[sel[i]].innerHTML = tmp[0];
+											else obj[sel[i]].text = tmp[0];
+											obj[sel[i]].value = tmp[1];
+											obj[sel[i]].style.color = tmp[2];
+											obj[sel[i]].style.backgroundColor = tmp[3];
+											obj[sel[i]].className = tmp[4];
+											obj[sel[i]].id = tmp[5];
+											obj[sel[i]-1].selected = true;
+											obj[sel[i]].selected = false;
+										}
+									}
+								}
+		var aSwitchDown = document.createElement("a");
+				aSwitchDown.innerHTML = '<span>&darr;</span>';
+				aSwitchDown.className = 'olWMSLayerSwitch';
+				aSwitchDown.select = select;
+				aSwitchDown.onclick = function(){
+									var obj =  this.select;
+									//alert(obj[obj.selectedIndex].value);
+									var sel = new Array();
+									for (var i=obj.length-1; i>-1; i--) {
+										if (obj[i].selected == true) {
+											sel[sel.length] = i;
+										}
+									}
+									for (i in sel) {
+										if (sel[i] != obj.length-1 && !obj[sel[i]+1].selected) {
+											var tmp = new Array((document.body.innerHTML ? obj[sel[i]+1].innerHTML : obj[sel[i]+1].text), obj[sel[i]+1].value, obj[sel[i]+1].style.color, obj[sel[i]+1].style.backgroundColor, obj[sel[i]+1].className, obj[sel[i]+1].id);
+											if (document.body.innerHTML) obj[sel[i]+1].innerHTML = obj[sel[i]].innerHTML;
+											else obj[sel[i]+1].text = obj[sel[i]].text;
+											obj[sel[i]+1].value = obj[sel[i]].value;
+											obj[sel[i]+1].style.color = obj[sel[i]].style.color;
+											obj[sel[i]+1].style.backgroundColor = obj[sel[i]].style.backgroundColor;
+											obj[sel[i]+1].className = obj[sel[i]].className;
+											obj[sel[i]+1].id = obj[sel[i]].id;
+											if (document.body.innerHTML) obj[sel[i]].innerHTML = tmp[0];
+											else obj[sel[i]].text = tmp[0];
+											obj[sel[i]].value = tmp[1];
+											obj[sel[i]].style.color = tmp[2];
+											obj[sel[i]].style.backgroundColor = tmp[3];
+											obj[sel[i]].className = tmp[4];
+											obj[sel[i]].id = tmp[5];
+											obj[sel[i]+1].selected = true;
+											obj[sel[i]].selected = false;
+										}
+									}
+								}	
+								
+								
+		//div to show layer info
+		var div = document.createElement('div');
+		div.id = 'wmsLayerListOutput';
+		div.style.padding = '10px';
+		div.style.height = '100px';
+		div.style.width = '200px';
+		div.style.overflow = 'auto';
+		div.style.border = '1px solid white';
+		div.innerHTML = 'Click on a layer to have details';
+		
+		layerBox.appendChild(aSwitchUp);
+		layerBox.appendChild(aSwitchDown);
 		layerBox.appendChild(radioSoverlay);
 		layerBox.appendChild(radioS);
 		layerBox.appendChild(br);
 		layerBox.appendChild(button);
+		layerBox.appendChild(div);
 		
+		
 		formObj.appendChild(layerBox);
 		
 
@@ -841,11 +969,12 @@
      */
     findChildByName: function(n,name) {
 		var x = n.firstChild;
-		while (x.nodeName!=1 && x.nodeName!=name)
+		while (x.nodeName!=1)
 	    {
-	    x=x.nextSibling;
+	    	if(x.nodeName==name) return x;
+			else x=x.nextSibling;
+			if(x==n.lastChild)return null;
 	    }
-	  return x;
 	},
 	
 	/** 
@@ -929,6 +1058,11 @@
 		 		var options = {resolutions: aResolutions, maxresolution: aResolutions[0], minResolution: minRes};
 		 		this.WMSManager.map.setOptions(options) ;
 			}
+			
+		//SRS - OL default srs is EPSG:4326 
+		/*var options = {srs: 'EPSG:4326'};
+				this.WMSManager.map.setOptions(options) ;	
+		*/
 		
 		if(overlayButton.checked){
 			var layer = new OpenLayers.Layer.WMS( title, 
@@ -952,8 +1086,27 @@
 		 * need to set the exact extent of the layer and not 
 		 * just the first extent of the getCapabilites response
 		 */
-		var ext = this.WMSManager.extent;
-		var bounds = new OpenLayers.Bounds(ext[0], ext[1], ext[2], ext[3]);  
+		var aExtents = [];
+		for(i=0;i<layerA.length;i++){
+			for(j=0;j<this.WMSManager.aWMSLayers.length;j++){
+				var checkedLayer = layerA[i];
+				var listedLayer = this.WMSManager.aWMSLayers[j];
+				if(checkedLayer==listedLayer[0]) aExtents.push(listedLayer[3]); 
+			}
+		}
+		//var ext = this.WMSManager.extent;
+		var bounds = null;
+		for(i=0;i<aExtents.length;i++){
+			var ext = aExtents[i];
+			if(!bounds) {
+				bounds = new OpenLayers.Bounds(ext[0], ext[1], ext[2], ext[3]); 
+			} 
+			else {
+				var nBounds = new OpenLayers.Bounds(ext[0], ext[1], ext[2], ext[3]); 
+				bounds.extend(nBounds);
+				
+			}
+		}
 		this.WMSManager.map.zoomToExtent(bounds);
 		
     },



More information about the Commits mailing list