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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Jul 1 11:18:28 PDT 2013


Author: armin11
Date: 2013-07-01 11:18:27 -0700 (Mon, 01 Jul 2013)
New Revision: 8666

Modified:
   trunk/mapbender/http/javascripts/mod_featureInfo.php
Log:
Possibility to change order of LAYERS values in GetFeatureInfo requests - useful if layertree is in natural order -> GetFeatureInfo result will then also be top->down. Element var reverseInfo must be set to true.

Modified: trunk/mapbender/http/javascripts/mod_featureInfo.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_featureInfo.php	2013-07-01 18:13:42 UTC (rev 8665)
+++ trunk/mapbender/http/javascripts/mod_featureInfo.php	2013-07-01 18:18:27 UTC (rev 8666)
@@ -31,6 +31,7 @@
 	var featureInfoPopupWidth = '270';
 if(typeof(featureInfoPopupPosition)==='undefined')
 	var featureInfoPopupPosition = 'center';
+var reverseInfo = typeof reverseInfo === "undefined" ? "false" : reverseInfo;
 
 var mod_featureInfo_elName = "<?php echo $e_id;?>";
 var mod_featureInfo_frameName = "";
@@ -60,6 +61,39 @@
 		};
 	});
 });
+
+/**
+ * some things from http://stackoverflow.com/a/10997390/11236
+ * function changes the order of cs-values for a given get parameter 
+ */
+function changeURLValueOrder(url, param){
+    var newAdditionalURL = "";
+    var tempArray = url.split("?");
+    var baseURL = tempArray[0];
+    var additionalURL = tempArray[1];
+    var temp = "";
+    if (additionalURL) {
+        tempArray = additionalURL.split("&");
+        for (i=0; i<tempArray.length; i++){
+            	if(tempArray[i].split('=')[0] != param){
+                	newAdditionalURL += temp + tempArray[i];
+                	temp = "&";
+            	} else {
+			//get value and sort it in other direction
+			var oldValue = tempArray[i].split('=')[1];
+			var oldValueArray = oldValue.split(",");
+			var newValue = '';
+			for (var j = 0; j < oldValueArray.length; j++) {
+				newValue = newValue+oldValueArray[oldValueArray.length - (j+1)]+',';
+			}
+			newValue = newValue.replace(/,+$/,'');
+		}
+        }
+    }
+    var rows_txt = temp + "" + param + "=" + newValue;
+    return baseURL + "?" + newAdditionalURL + rows_txt;
+}
+
 function mod_featureInfo_click(){   
 	var el = mod_featureInfo_mapObj.getDomElement();
 	
@@ -81,7 +115,7 @@
 	
 	eventBeforeFeatureInfo.trigger({"fName":mod_featureInfo_target});
 	
-//TODO that code should go to featureInfo Redirect module
+	//TODO that code should go to featureInfo Redirect module
 	if(document.getElementById("FeatureInfoRedirect")){
 		//fill the frames
 		for(var i=0; i<mod_featureInfo_mapObj.wms.length; i++){
@@ -93,8 +127,12 @@
 	else{
 		urls = mod_featureInfo_mapObj.getFeatureInfoRequests(point, ignoreWms);
 		if(urls){
-			for(var i=0;i<urls.length;i++){
+			for(var i=0;i<urls.length;i++){ //To change order : var i=urls.length-1; i>=0; i--
+				//TODO: also rewind the LAYERS parameter for a single WMS FeatureInfo REQUEST if needed?
 				var cnt = i;
+				if (reverseInfo == 'true') {
+					urls[i] = changeURLValueOrder(urls[i], 'LAYERS');
+				}
 				if(featureInfoPopupPosition.length == 2 && !isNaN(featureInfoPopupPosition[0]) && !isNaN(featureInfoPopupPosition[1])) {
 					var dialogPosition = [];
 					dialogPosition[0] = featureInfoPopupPosition[0]+cnt*25;
@@ -120,9 +158,9 @@
 					}).parent().css({position:"fixed"});
 				}
 				else
-					window.open(urls[i], "" , "width="+featureInfoPopupWidth+",height="+featureInfoPopupHeight+",scrollbars=yes,resizable=yes");
-			}
-		}
+					window.open(urls[i], "" , "width="+featureInfoPopupWidth+",height="+featureInfoPopupHeight+",scrollbars=yes,resizable=yes");		
+			} //end for
+		} //end if urls
 		else
 			alert(unescape("Please select a layer! \n Bitte waehlen Sie eine Ebene zur Abfrage aus!"));
 	}



More information about the Mapbender_commits mailing list