[Mapbender-commits] r9578 - trunk/mapbender/http/html

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Sep 7 05:42:40 PDT 2016


Author: armin11
Date: 2016-09-07 05:42:40 -0700 (Wed, 07 Sep 2016)
New Revision: 9578

Modified:
   trunk/mapbender/http/html/mod_treefolderPlain.php
Log:
Further functions to allow support of wms time dimension

Modified: trunk/mapbender/http/html/mod_treefolderPlain.php
===================================================================
--- trunk/mapbender/http/html/mod_treefolderPlain.php	2016-09-07 12:42:19 UTC (rev 9577)
+++ trunk/mapbender/http/html/mod_treefolderPlain.php	2016-09-07 12:42:40 UTC (rev 9578)
@@ -713,12 +713,10 @@
 	else{
 		setTimeout('setNodeImage("'+path+'", "closed_folder.png");', 100);
 	}
-
 	if(reset_lock){
 		lock_update=false;
 	}
 	handleSelectedWMS(path, true);
-
 }
 
 function handleSelectedWMS(path){
@@ -786,7 +784,49 @@
 	}
 }
 
+function setDimensionUserValue(j,k,l,dimensionIndex,userValue) {
+	if(!j && !k&& !l){
+		j=selectedMap;
+		k=selectedWMS;
+		l=selectedLayer;
+	}
+	var my = mb_mapObj[j].wms[k].objLayer[l];
+	var myWms = mb_mapObj[j].wms[k];
+	//delete all userValues from other layers of this wms
+	for (var k=0;k< myWms.objLayer.length;k++) {
+		for (var i=0;i< myWms.objLayer[k].layer_dimension.length;i++) {
+			myWms.objLayer[k].layer_dimension[i].userValue = "";
+		}
+	}
+	my.layer_dimension[dimensionIndex].userValue = userValue;
+	//openfolder = true;
+	treeState = getState();
+	reloadTree();
+}
 
+//function for buggy servers which do not support real iso8601 patterns for UTC :-(
+function makeDateTimeBetter(dateTimeIso) {
+	return dateTimeIso.replace('+00:00','Z');
+}
+
+function snapToDiscreteValue(userValue,extent) {
+	//call it via sync ajax call :-(
+	transformUrl = '../php/mod_transformTimeDimension.php?operation=snapToGrid&extent='+encodeURIComponent(extent)+'&userValue='+encodeURIComponent(userValue);
+	var response = $.ajax({
+		url: transformUrl,
+		type: "GET",
+        	async: false,
+    		success: function (data) {
+			return data;
+		},
+		error: function() {
+			alert("An error occured!");
+		}
+	}).responseText;
+	var jsonValue = JSON.parse(response);
+	return jsonValue.data[0].value;
+}
+
 function openDimensionSelectHtml(j,k,l,dimensionIndex) {
 	if(!j && !k&& !l){
 		j=selectedMap;
@@ -796,19 +836,18 @@
 	var my = mb_mapObj[j].wms[k].objLayer[l];
 	var myWms = mb_mapObj[j].wms[k];
 	//extract/calculate discrete values for time!
-	//alert(JSON.stringify(mb_mapObj[j].wms[k].objLayer[l].layer_dimension[dimensionIndex]));
-	//var userValue = encodeURI(mb_mapObj[j].wms[k].objLayer[l].layer_dimension[dimensionIndex].userValue); //not already defined in mapobj!!
-	var extent = encodeURI(mb_mapObj[j].wms[k].objLayer[l].layer_dimension[dimensionIndex].extent);
-	var dimdefault = encodeURI(mb_mapObj[j].wms[k].objLayer[l].layer_dimension[dimensionIndex].default);
-	//
+	var userValue = mb_mapObj[j].wms[k].objLayer[l].layer_dimension[dimensionIndex].userValue; //not already defined in mapobj!!
+	var extent = mb_mapObj[j].wms[k].objLayer[l].layer_dimension[dimensionIndex].extent;
+	var dimdefault = mb_mapObj[j].wms[k].objLayer[l].layer_dimension[dimensionIndex].default;
 	var dialogHtml = "<div id='timeline'></div>";
-	$("<div id='selectDimensionDialog' title='<?php echo _mb('Select layer dimension');?>'><?php echo _mb('Please select an additional dimension value');?>: </div>").dialog(
+	$("<div id='selectDimensionDialog' title='<?php echo _mb('Select layer dimension');?>'><?php echo _mb('Please select a value for TIME. One single element can be dragged on timeline after selection. Scale may be altered by scrollinng.');?>: </div>").dialog(
 		{
 			bgiframe: true,
 			autoOpen: true,
 			modal: false,
+			width: 400,
 			closeOnEscape: false,
-			//open: function(event, ui) { $(".ui-dialog-titlebar-close").hide()}, //hide closing x - but only for element with special id!!!
+			open: function(event, ui) { $( "div[aria-labelledby='ui-dialog-title-selectDimensionDialog']" ).children().children(".ui-dialog-titlebar-close").hide()}, //hide closing x - but only for element with special id!!!
 			buttons: {
 				"<?php echo _mb('Close');?>": function(){
 					$('selectDimensionDialog').remove();
@@ -820,9 +859,14 @@
 	);	
 	$(dialogHtml).appendTo("#selectDimensionDialog");
 	//fill timeline into div
+	if (userValue !== undefined && userValue !== false && userValue !== "" && userValue !== "undefined") {
+		userValue = makeDateTimeBetter(userValue);
+		transformUrl = '../php/mod_transformTimeDimension.php?extent='+encodeURIComponent(extent)+'&userValue='+encodeURIComponent(userValue)+'&default='+encodeURIComponent(dimdefault);
+	} else {
+		transformUrl = '../php/mod_transformTimeDimension.php?extent='+encodeURIComponent(extent)+'&default='+encodeURIComponent(dimdefault);
+	}
 	  $.ajax({
-    		//url: '../php/mod_transformTimeDimension.php?extent='+extent+'&userValue='+userValue+'&default='+dimdefault,
-		url: '../php/mod_transformTimeDimension.php?extent='+extent+'&default='+dimdefault,
+		url: transformUrl,
     		success: function (data) {
       			// hide the "loading..." message
      			//document.getElementById('loading').style.display = 'none';
@@ -834,19 +878,42 @@
       			var items = new vis.DataSet(data.data);
 
       			// Configuration for the Timeline
-      			//var options = {};
       			var options = data.options;
-      			options.onMove = function (item,callback) {item.content = item.start.toISOString(); myWms.gui_wms_dimension_time = item.start.toISOString()+'Z'; Mapbender.modules[mod_treeGDE_map].setMapRequest();; callback(item);};
+
+			//check if onclick or onmove should be enabled
+			if (data.options.editable.updateTime !== 'undefined' && data.options.editable.updateTime == true) {
+				options.onMove = function (item,callback) {
+					//calculate new value for item start based on snapping to period from extent
+					item.start = new Date(snapToDiscreteValue(item.start.toISOString(),extent));
+					item.content = item.start.toISOString();
+					myWms.gui_wms_dimension_time = makeDateTimeBetter(item.start.toISOString());
+					setDimensionUserValue(j,k,l,dimensionIndex,myWms.gui_wms_dimension_time);
+					Mapbender.modules[mod_treeGDE_map].setMapRequest();
+					callback(item);
+				};
+			} else {
+				options.editable = false;
+				
+			}
       			// Create a Timeline
       			var timeline = new vis.Timeline(container, items, options);
+			//if (data.options.editable.updateTime == 'undefined' || data.options.editable.updateTime == false) {
+				timeline.on('select', function (properties) {
+					if (properties.event.type == "tap") {
+						myWms.gui_wms_dimension_time = makeDateTimeBetter(timeline.itemsData._data[timeline.getSelection()].content);
+						setDimensionUserValue(j,k,l,dimensionIndex,myWms.gui_wms_dimension_time);
+						Mapbender.modules[mod_treeGDE_map].setMapRequest();
+					}
+				});
+			//}	
     		},
     		error: function (err) {
-      			console.log('Error', err);
+      			//console.log('Error', err);
       			if (err.status === 0) {
-        			alert('Failed to load data/basic.json.\nPlease run this example on a server.');
+        			alert('Failed to load json for configuration of timeline from server.\nPlease contact your portal administrator!');
       			}
       			else {
-        			alert('Failed to load data/basic.json.');
+        			alert('Failed to load json from server.');
       			}
     		}
   	});
@@ -968,18 +1035,26 @@
 												case "time":
 													timeDimensionAvailable = true;
 													timeDimensionIndex = dimensionIndex;
+													timeUserValue = mb_mapObj[i].wms[ii].objLayer[iii].layer_dimension[dimensionIndex].userValue;
 													break;
 												case "elevation":
 													elevationDimensionAvailable = true;
 													elevationDimensionIndex = dimensionIndex;
+													elevationUserValue = mb_mapObj[i].wms[ii].objLayer[iii].layer_dimension[dimensionIndex].userValue;
 													break;
 											} 
 										}
 										if (timeDimensionAvailable === true) {
 											text = JSON.stringify(mb_mapObj[i].wms[ii].objLayer[iii].layer_dimension[timeDimensionIndex]);
 											controls.push('<img onclick="openDimensionSelectHtml('+i+','+ii+','+iii+','+timeDimensionIndex+');" width="18" height="18" alt="'+msgObj.tooltipTimeDimension+'" title="'+msgObj.tooltipTimeDimension+'" src="'+imagedir+'/../gnome/preferences-system-time.png" />');	
+											if (timeUserValue !== undefined && timeUserValue !== false && timeUserValue !== "" && timeUserValue !== "undefined") {
+											controls.push('<b>'+timeUserValue+'</b>');
+											//set gui_wms_dimension_time to value of layer - only one layer of a wms should have the userValue defined - if more have this, the last one will overwrite all earlier!
+											mb_mapObj[i].wms[ii].gui_wms_dimension_time = timeUserValue;
+											}
 										}
 									}
+						
 									var groupedImageStyle ='';
 									if (temp.has_childs == true){
 										groupedImageStyle ='closed_folder.png';



More information about the Mapbender_commits mailing list