[Mapbender-commits] r8539 - branches/2.7/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Jan 10 05:09:10 PST 2013


Author: verenadiewald
Date: 2013-01-10 05:09:10 -0800 (Thu, 10 Jan 2013)
New Revision: 8539

Modified:
   branches/2.7/http/javascripts/mod_setBackground.php
Log:
Bugfix: SetBackground after load WMC (taken from trunk)

Modified: branches/2.7/http/javascripts/mod_setBackground.php
===================================================================
--- branches/2.7/http/javascripts/mod_setBackground.php	2013-01-10 11:02:59 UTC (rev 8538)
+++ branches/2.7/http/javascripts/mod_setBackground.php	2013-01-10 13:09:10 UTC (rev 8539)
@@ -34,43 +34,64 @@
 Mapbender.events.setBackgroundIsReady = new Mapbender.Event();
 
 var mod_setBackground_active = false;
-function mod_setBackground_init(){
+
+function mod_setBackground_init() {
 	var map = Mapbender.modules[mod_setBackground_target];
 	var setBackgroundSelectBox = document.setBackground.mod_setBackground_list;
-	var ind = setBackgroundSelectBox.options[0].value;
-	var cnt = 0;
-	var selInd;
+    var selected = false;
+    var firstHidden = false;
 
-	setBackgroundSelectBox.options[setBackgroundSelectBox.length - 1] = null;
-	for(var i=0; i<map.wms.length; i++){
-		if(map.wms[i].gui_wms_visible == '0'){
-			var title = map.wms[i].wms_title;
-			var newO = new Option(title, i, false,false);
-
-			setBackgroundSelectBox.options[setBackgroundSelectBox.length] = newO;
-			if (ind == i) {
-				selInd = cnt;
-			}
-			cnt++;
+    /* REMOVE ALL OPTIONS FROM SELECTBOX */
+    setBackgroundSelectBox.options.length = 0;
+	
+    /* ADD NEW OPTIONS TO SELECTBOX */
+	for(var i=0; i<map.wms.length; i++) {
+        var visibility = map.wms[i].gui_wms_visible;
+        var title = map.wms[i].wms_title;
+        
+        /* IS BACKGROUND? */
+		if(visibility == '0' || visibility == '2') {
+            if(firstHidden === false) {
+                firstHidden = i;
+            }
+        
+            if(visibility == '0') {
+                var newOption = new Option(title, i, false, false);
+            } else {
+                /* SELECTED */
+                var newOption = new Option(title, i, false, true);
+                selected = i;
+            }
+            
+            /* ADD NEW BACKGROUND OPTION */
+			setBackgroundSelectBox.options[setBackgroundSelectBox.length] = newOption;
 		}
 	}
-	
+    
+    /* SET FIRST WMS AS OVERVIEW */
 	if(Mapbender.modules['overview']) {
 		Mapbender.modules['overview'].wms[0].gui_wms_visible = 1;
-		setSingleMapRequest('overview',Mapbender.modules['overview'].wms[0].wms_id);
+		setSingleMapRequest('overview', Mapbender.modules['overview'].wms[0].wms_id);
 	}
-	 
-	if (cnt >0){
-		map.wms[ind].gui_wms_visible = 2;
-		setBackgroundSelectBox.selectedIndex = selInd;
-		setSingleMapRequest(mod_setBackground_target,map.wms[ind].wms_id);
-	}
-	mod_setBackground_active = ind;
-
-        Mapbender.events.setBackgroundIsReady.trigger();
+	
+    var newBackground = 0;
+    
+    if(selected === false && firstHidden !== false) {
+        newBackground = firstHidden;
+		map.wms[firstHidden].gui_wms_visible = 2;
+    } else if(selected !== false) {
+        newBackground = selected;
+    }
+    
+    /* SET BACKGROUND */
+    setBackgroundSelectBox.selectedIndex = newBackground;
+    setSingleMapRequest(mod_setBackground_target,map.wms[newBackground].wms_id);
+    mod_setBackground_active = newBackground;
+    
+    Mapbender.events.setBackgroundIsReady.trigger();
 }
 
-function mod_setBackground_change(obj){	
+function mod_setBackground_change(obj) {
 	var map = Mapbender.modules[mod_setBackground_target];
 	map.wms[mod_setBackground_active].gui_wms_visible = 0;
 	map.wms[obj.value].gui_wms_visible = 2;



More information about the Mapbender_commits mailing list