[Mapbender-commits] r9593 - in trunk/mapbender/http: html javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Sep 12 20:36:50 PDT 2016


Author: armin11
Date: 2016-09-12 20:36:50 -0700 (Mon, 12 Sep 2016)
New Revision: 9593

Modified:
   trunk/mapbender/http/html/mod_treefolderPlain.php
   trunk/mapbender/http/javascripts/mod_savewmc.js
   trunk/mapbender/http/php/mod_savewmc_server.php
Log:
New possibility to check identity of last stored mapset when storage to session is activated. This prohibit the storage of the same mapset more than once.

Modified: trunk/mapbender/http/html/mod_treefolderPlain.php
===================================================================
--- trunk/mapbender/http/html/mod_treefolderPlain.php	2016-09-12 12:22:45 UTC (rev 9592)
+++ trunk/mapbender/http/html/mod_treefolderPlain.php	2016-09-13 03:36:50 UTC (rev 9593)
@@ -889,10 +889,7 @@
 					item.content = item.start.toISOString();
 					myWms.gui_wms_dimension_time = makeDateTimeBetter(item.start.toISOString());
 					setDimensionUserValue(j,k,l,dimensionIndex,myWms.gui_wms_dimension_time);
-					//lock_maprequest = true; //done to prohibit save wmc for each wms
-					Mapbender.modules[mod_treeGDE_map].setMapRequest();
-					//Mapbender.modules[mod_treeGDE_map].setSingleMapRequest(mod_treeGDE_map,k);
-					//lock_maprequest = false;
+					Mapbender.modules[mod_treeGDE_map].setSingleMapRequest(mod_treeGDE_map,mb_mapObj[j].wms[k].wms_id);
 					callback(item);
 				};
 			} else {
@@ -906,11 +903,7 @@
 					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);
-						//lock_maprequest = true;
-						Mapbender.modules[mod_treeGDE_map].setMapRequest();
-						//Mapbender.modules[mod_treeGDE_map].setSingleMapRequest(mod_treeGDE_map,k);
-						//alert("wms_id: "+k);
-						//lock_maprequest = false;
+						Mapbender.modules[mod_treeGDE_map].setSingleMapRequest(mod_treeGDE_map,mb_mapObj[j].wms[k].wms_id);
 					}
 				});
 			//}	

Modified: trunk/mapbender/http/javascripts/mod_savewmc.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_savewmc.js	2016-09-12 12:22:45 UTC (rev 9592)
+++ trunk/mapbender/http/javascripts/mod_savewmc.js	2016-09-13 03:36:50 UTC (rev 9593)
@@ -109,6 +109,23 @@
 //
 var $this = $(this);
 
+String.prototype.hashCode = function() {
+
+    if (Array.prototype.reduce) {
+        return this.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);   
+    } else {
+
+        var hash = 0, i, chr, len;
+        if (this.length == 0) return hash;
+        for (i = 0, len = this.length; i < len; i++) {
+        chr   = this.charCodeAt(i);
+        hash  = ((hash << 5) - hash) + chr;
+        hash |= 0; // Convert to 32bit integer
+        }
+        return hash;
+    }
+};
+
 var SaveWmcApi = function () {
 	var that = this;
 
@@ -134,7 +151,7 @@
 			return this;
 		}
 		if (obj.session === true) {
-			sendMapDataToServer("session", 1, function(result, status) {}, lzwCompressed);
+			sendMapDataToServer("session", 1, function(result, status) {Mapbender.lastStoredMapsetHash = result.mapHash;}, lzwCompressed);
 			return this;
 		}
 		if (typeof obj.attributes === "object" && typeof obj.callback === "function") {
@@ -144,7 +161,7 @@
 	};
 
 	var sendMapDataToServer = function (attributes, storeInSession, callbackFunction, beLzwCompressed) {
-		var	extensionDataString = "";
+		var extensionDataString = "";
 		if (that.extensionData !== null) {
 			extensionDataString = $.toJSON(that.extensionData);
 		}
@@ -177,7 +194,13 @@
                     mb_mapObj[0].kmlOrder = null;
                 }
             }
-
+		//***** 
+		var mapObjWithoutHistory = mb_mapObj;
+		//set history and hash itself to null to identify same object and store the hash in a special field 
+		mapObjWithoutHistory[0].mb_MapHistoryObj = null;
+		that.mapObjHashWithoutHistory = $.toJSON(mapObjWithoutHistory).hashCode();
+		//*****
+		//send mapObj without 
 	    	var mapObjectToSend = $.toJSON(mb_mapObj);
 		//if compression is demanded see http://rosettacode.org/wiki/LZW_compression#JavaScript
 		if (beLzwCompressed == 'true') { //
@@ -197,11 +220,18 @@
 			  mapObject:mapObjectToSend
 			},
 	        callback: function(result, status, message) {
+				//new 2016 - check hashed mapset of mapframe1 against last storage
+				result.mapHash = that.mapObjHashWithoutHistory;
 				callbackFunction(result, status, message);
 				that.events.saved.trigger();
 			}
 	    });
-	    req.send();
+	    //new 2016 - check hashed mapset of mapframe1 against last storage
+	    if (Mapbender.lastStoredMapsetHash !== that.mapObjHashWithoutHistory) {
+	    	req.send();
+	    } else {
+		//alert("Configuration already saved before: "+Mapbender.lastStoredMapsetHash);
+	    }
 
 		//
 		// reversal of above WORKAROUND

Modified: trunk/mapbender/http/php/mod_savewmc_server.php
===================================================================
--- trunk/mapbender/http/php/mod_savewmc_server.php	2016-09-12 12:22:45 UTC (rev 9592)
+++ trunk/mapbender/http/php/mod_savewmc_server.php	2016-09-13 03:36:50 UTC (rev 9593)
@@ -12,6 +12,19 @@
 require_once(dirname(__FILE__)."/../classes/class_wmc.php");
 require_once(dirname(__FILE__)."/../classes/class_json.php");
 require_once(dirname(__FILE__)."/../classes/class_lzw_decompress.php");
+
+//usefull for debugging purposes
+function logit($text){
+	$time = microtime();
+	if($h = fopen("/tmp/".$time."_savewmc_server.log","a")){
+		$content = $text .chr(13).chr(10);
+		if(!fwrite($h,$content)){
+			#exit;
+		}
+		fclose($h);
+	}
+}
+
 //require_once(dirname(__FILE__)."/../classes/class_cache.php");
 $admin = new administration();
 
@@ -44,8 +57,14 @@
 	//$filename = TMPDIR."/formerly_uncompressed_json.txt";//will be set to new one cause ?
 }
 //file_put_contents($filename, $mapObject);
-//$e = new mb_exception('mod_savewmc_server.php: mapObject is here ;-)');
+
 $mapObject = $json->decode($mapObject);
+//******for debugging of mapobject you can activate following lines
+//store mapObjects as pretty print to tmp folder for debug purpose!!
+/*$mapObjLog = json_encode($mapObject, JSON_PRETTY_PRINT);
+logit($mapObjLog);*/
+//******
+
 $e = new mb_notice('mod_savewmc_server.php: mapObject has been decoded from json');
 // create WMC object
 $wmc = new wmc();



More information about the Mapbender_commits mailing list