[Mapbender-commits] r3341 - branches/beck_dev/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Dec 16 07:14:51 EST 2008


Author: beck
Date: 2008-12-16 07:14:51 -0500 (Tue, 16 Dec 2008)
New Revision: 3341

Modified:
   branches/beck_dev/http/javascripts/mod_mapCookie.php
Log:


Modified: branches/beck_dev/http/javascripts/mod_mapCookie.php
===================================================================
--- branches/beck_dev/http/javascripts/mod_mapCookie.php	2008-12-16 10:17:30 UTC (rev 3340)
+++ branches/beck_dev/http/javascripts/mod_mapCookie.php	2008-12-16 12:14:51 UTC (rev 3341)
@@ -20,20 +20,20 @@
 require_once(dirname(__FILE__)."/../php/mb_validatePermission.php");
 ?>
 
-var mod_mapCookie_target         = '<?php echo trim(array_shift($e_target)); ?>';
-var mod_mapCookie_cookieLifetime = 7;
-var mod_mapCookie_cookieName     = 'stored_map_state';
+var mod_mapCookie_target             = '<?php echo trim(array_shift($e_target)); ?>';
+var mod_mapCookie_cookieLifetimeDays = 365;
+var mod_mapCookie_cookieName         = 'stored_map_state';
 
 eventInit.register(mod_mapCookie_restoreMapState);
-eventInit.register(mod_mapCookie_triggerUnload);
+eventInit.register(mod_mapCookie_triggerUnloadEvent);
 
 function mod_mapCookie_restoreMapState() {
 	if(!document.cookie) {
 		return;
 	}
 	
-	var currentMapState     = mb_mapObj[getMapObjIndexByName(mod_mapCookie_target)];
-	var cookieData          = document.cookie.split(';');
+	var currentMapState = mb_mapObj[getMapObjIndexByName(mod_mapCookie_target)];
+	var cookieData      = document.cookie.split(';');
 
 	for(var i = 0; i < cookieData.length; i++) {
 		var cookieName = new RegExp(mod_mapCookie_cookieName);
@@ -44,30 +44,37 @@
 		
 		var storedMapState = eval('(' + cookieData[i].replace(cookieName + '=','') + ')');
 		
-		if(storedMapState.frameName != mod_mapCookie_target) {
-			continue;
-		}
-		
 		currentMapState.epsg   = storedMapState.epsg;
 		currentMapState.extent = storedMapState.extent;
 		
-		for(j = 0; j < storedMapState.layers.length; j++) {
-			var storedLayerId           = storedMapState.layers[j][0];
-			var storedLayerVisibility   = storedMapState.layers[j][1];
-			var storedLayerQueryability = storedMapState.layers[j][2];
-			
-			for(var k = 0; k < currentMapState.wms.length; k++) {
-				if(currentMapState.wms[k].objLayer[storedLayerId] == undefined) {
-					continue;
+		var currentWmsLayers = [];
+		for(var j = 0; j < currentMapState.wms.length; j++) {
+			for(var k = 0; k < currentMapState.wms[j].objLayer.length; k++) {
+				currentWmsLayers.push(currentMapState.wms[j].objLayer[k]);
+			}
+		}
+		
+		for(var j = 0; j < currentWmsLayers.length; j++) {
+			for(k = 0; k < storedMapState.layers.length; k++) {
+				var storedWmsTitle           = storedMapState.layers[k][0];
+				var storedLayerId            = storedMapState.layers[k][1];
+				var storedLayerName          = storedMapState.layers[k][2];
+				var storedLayerVisibility    = storedMapState.layers[k][3];
+				var storedLayerQueryablility = storedMapState.layers[k][4];
+				
+				if(currentWmsLayers[j].layer_id == storedLayerId) {
+					currentWmsLayers[j].gui_layer_visible    = storedLayerVisibility;
+					currentWmsLayers[j].gui_layer_querylayer = storedLayerQueryablility;
+//					handleSelectedLayer(mod_mapCookie_target,storedWmsTitle,storedLayerName,'gui_layer_visible',storedLayerVisibility);
+//					handleSelectedLayer(mod_mapCookie_target,storedWmsTitle,storedLayerName,'gui_layer_querylayer',storedLayerVisibility);
+
 				}
-				
-				console.log('Layer ID: %s',currentMapState.wms[k].objLayer[storedLayerId].layer_id);
-				
-				currentMapState.wms[k].objLayer[storedLayerId].gui_layer_visible = storedLayerVisibility;
-				currentMapState.wms[k].objLayer[storedLayerId].layer_queryable   = storedLayerQueryability;
 			}
 		}
 	}
+	
+	setMapRequest(mod_mapCookie_target);
+	eventAfterLoadWMS.trigger();
 }
 
 function mod_mapCookie_storeMapState() {
@@ -75,29 +82,30 @@
 	var cookieData          = {};
 	var cookieExpires       = new Date();
 
-	cookieData.frameName = currentMapState.frameName;
-	cookieData.epsg      = currentMapState.epsg;
-	cookieData.extent    = currentMapState.extent;
-	cookieData.layers    = [];
+	cookieData.epsg   = currentMapState.epsg;
+	cookieData.extent = currentMapState.extent;
+	cookieData.layers = [];
 	
 	for(var i = 0; i < currentMapState.wms.length; i++) {
 		for(var j = 0; j < currentMapState.wms[i].objLayer.length; j++) {
-			var layers = [];
-			layers.push(
+			var currentLayers = [];
+			currentLayers.push(
+				currentMapState.wms[i].wms_title,
 				currentMapState.wms[i].objLayer[j].layer_id,
+				currentMapState.wms[i].objLayer[j].layer_name,
 				currentMapState.wms[i].objLayer[j].gui_layer_visible,
-				currentMapState.wms[i].objLayer[j].layer_queryable
+				currentMapState.wms[i].objLayer[j].gui_layer_querylayer
 			);
-			cookieData.layers.push(layers);
+			cookieData.layers.push(currentLayers);
 		}
 	}
 
-	cookieExpires.setTime(cookieExpires.getTime() + (parseInt(mod_mapCookie_cookieLifetime) * 24 * 60 * 60 * 1000));
+	cookieExpires.setTime(cookieExpires.getTime() + (parseInt(mod_mapCookie_cookieLifetimeDays) * 24 * 60 * 60 * 1000));
 
 	document.cookie = mod_mapCookie_cookieName + '=' + $.toJSON(cookieData) + ';expires=' + cookieExpires.toGMTString() + ';';
 }
 
-function mod_mapCookie_triggerUnload() {
+function mod_mapCookie_triggerUnloadEvent() {
 	if(ie) {
 		document.getElementById('body').onunload = function() {
 			var trigger = new Function ('','mod_mapCookie_storeMapState()');



More information about the Mapbender_commits mailing list