[fusion-commits] r1998 - in trunk: . layers/MapServer
layers/MapServer/php lib
svn_fusion at osgeo.org
svn_fusion at osgeo.org
Mon Nov 30 17:28:16 EST 2009
Author: pdeschamps
Date: 2009-11-30 17:28:16 -0500 (Mon, 30 Nov 2009)
New Revision: 1998
Added:
trunk/layers/MapServer/php/RestoreState.php
Modified:
trunk/config_dist.json
trunk/layers/MapServer/MapServer.js
trunk/lib/Map.js
Log:
implemented the restoreState= session loading functionality
Modified: trunk/config_dist.json
===================================================================
--- trunk/config_dist.json 2009-11-30 09:18:05 UTC (rev 1997)
+++ trunk/config_dist.json 2009-11-30 22:28:16 UTC (rev 1998)
@@ -41,6 +41,10 @@
web-accessible temporary legend images. */
"legendIconCacheDir":"/ms4w/tmp/ms_tmp",
/* The file system path to where the maps are stored. */
- "mapFileRoot":"/ms4w/apps/"
+ "mapFileRoot":"/ms4w/apps/",
+ /*The file system path where the saved map sessions are stored.*/
+ "mapRestoreState":"/opt/fgs/apps/savedSession/",
+ /*The file system path where the php sessions are stored.*/
+ "mapRestoreStateSession":"/opt/fgs/tmp/"
}
}
Modified: trunk/layers/MapServer/MapServer.js
===================================================================
--- trunk/layers/MapServer/MapServer.js 2009-11-30 09:18:05 UTC (rev 1997)
+++ trunk/layers/MapServer/MapServer.js 2009-11-30 22:28:16 UTC (rev 1998)
@@ -42,6 +42,8 @@
layerMetadataKeys: null,
oMaptip:null,
bMapTipFired: false,
+ bRestoreMapState: false,
+ oRestoredState: {},
//the map file
sMapFile: null,
@@ -63,6 +65,16 @@
Fusion.queryParams['theme'] = null;
}
+ var restoreMapState = Fusion.getQueryParam('restoreState');
+ if (restoreMapState != '') {
+ //clear the query param after it has been used once
+ this.oRestoredState.id = restoreMapState;
+ Fusion.queryParams['restoreState'] = null;
+ // set flag to true so we can restore the map from a saved session.
+ this.bRestoreMapState = true;
+ }
+
+
this.mapMetadataKeys = mapTag.extension.MapMetadata ? mapTag.extension.MapMetadata[0] : null;
this.layerMetadataKeys = mapTag.extension.LayerMetadata ? mapTag.extension.LayerMetadata[0] : null;
@@ -118,12 +130,55 @@
Fusion.initializeLocale(locale[0]);
break;
}
- this.triggerEvent(Fusion.Event.MAP_SESSION_CREATED);
+
+ /* Session is created, Check to see if we are going to restore a saved
+ map state and restore it if set to true.
+ */
+ if(this.bRestoreMapState == true){
+ var that = this;
+ var sl = Fusion.getScriptLanguage();
+ var scriptURL = 'layers/' + this.arch + '/' + sl + '/RestoreState.' + sl;
+
+ var params = {
+ parameters: OpenLayers.Util.getParameterString({
+ session: this.session[0] ,
+ id: this.oRestoredState.id
+ }),
+ onComplete: function(xhr) {
+ var o;
+ eval('o='+xhr.responseText);
+ that.restoreStateCB(o);
+ }
+ };
+ Fusion.ajaxRequest(scriptURL,params);
+ }
+ else
+ {
+ // done with session create, fire the event.
+ this.triggerEvent(Fusion.Event.MAP_SESSION_CREATED);
+ }
+
}
},
+ restoreStateCB: function(oResponse){
+ if(oResponse.error){
+ Fusion.reportError(new Fusion.Error(Fusion.Error.WARNING, "Error Restoring Map State - "+oResponse.error));
+ }
+ else
+ {
+ this.oRestoredState = oResponse;
+ }
+ // done with session create, fire the event.
+ this.triggerEvent(Fusion.Event.MAP_SESSION_CREATED);
+ },
+
mapSessionCreated: function() {
- if (this.sMapFile != '') {
+ // restore the mapfile from a saved state.
+ if(this.bRestoreMapState === true && this.oRestoredState.loadmap ){
+ this.loadMap(this.oRestoredState.loadmap);
+ }
+ else if (this.sMapFile != '') {
this.loadMap(this.sMapFile);
}
window.setInterval(OpenLayers.Function.bind(this.pingServer, this),
@@ -278,7 +333,6 @@
this.mapWidget.addMap(this);
this.mapWidget.oMapOL.units = this.oLayerOL.units;
}
-
this.bMapLoaded = true;
}
else
@@ -402,31 +456,35 @@
},
mapLayersReset: function(aLayerIndex,r) {
- if (r.status == 200) {
var o;
eval('o='+r.responseText);
- if (o.success) {
- var layerCopy = $A(this.aLayers);
- var nLayers = layerCopy.length -1;
-
- //Mapserver has list of layers reversed from MapGuide
- aLayerIndex.reverse();
-
- this.aLayers = [];
- this.aVisibleLayers = [];
+ if (o.success) {
+ var layerCopy = $A(this.aLayers);
+ console.dir(layerCopy);
+ var nLayers = layerCopy.length -1;
+ console.log("nLayers:"+nLayers);
- for (var i=0; i<aLayerIndex.length; ++i) {
- this.aLayers.push( layerCopy[ nLayers - aLayerIndex[i] ] );
- if (this.aLayers[i].visible) {
- this.aVisibleLayers.push(this.aLayers[i].layerName);
+ //Mapserver has list of layers reversed from MapGuide
+ //aLayerIndex.reverse();
+
+ this.aLayers = [];
+ this.aVisibleLayers = [];
+
+ for (var i=0; i<aLayerIndex.length; ++i) {
+ this.aLayers.push( layerCopy[aLayerIndex[i] ] );
+ console.log("INDEX:"+(aLayerIndex[i]));
+ console.log(layerCopy[aLayerIndex[i]].layerName);
+ if (this.aLayers[i].visible) {
+ this.aVisibleLayers.push(this.aLayers[i].layerName);
+ }
}
- }
- //this.layerRoot.clear();
+ console.dir(this.aLayers);
+ //this.layerRoot.clear();
- this.drawMap();
- this.triggerEvent(Fusion.Event.MAP_LAYER_ORDER_CHANGED);
+ this.drawMap();
+ this.triggerEvent(Fusion.Event.MAP_LAYER_ORDER_CHANGED);
}
- }
+
},
parseMapLayersAndGroups: function(o) {
Added: trunk/layers/MapServer/php/RestoreState.php
===================================================================
--- trunk/layers/MapServer/php/RestoreState.php (rev 0)
+++ trunk/layers/MapServer/php/RestoreState.php 2009-11-30 22:28:16 UTC (rev 1998)
@@ -0,0 +1,191 @@
+<?php
+ini_set("memory_limit","64M");
+dl('zip.so');
+ /* set up the session */
+include(dirname(__FILE__).'/Common.php');
+include('../../../common/php/Utilities.php');
+
+header('Content-type: application/json');
+header('X-JSON: true');
+
+isset($_REQUEST["session"])?$szSessionID = $_REQUEST["session"]:$szSessionID = NULL ;
+isset($_REQUEST["id"])?$loadSessionID = $_REQUEST["id"]:$loadSessionID = NULL ;
+
+$oReturn = NULL;
+
+if (isset($_SESSION['fusionConfig'])) {
+
+ $szStoreSessionPath = $_SESSION['fusionConfig']->mapserver->mapRestoreState;
+ $szFilePhpSession = $_SESSION['fusionConfig']->mapserver->mapRestoreStateSession;
+
+ $szDestination = $szFilePhpSession."/sess_".$szSessionID."/";
+
+ $szTmpFileName = $_FILES["sessionFile"]["tmp_name"];
+ $szZipFilename = $szStoreSessionPath."/ss_".$loadSessionID.".zip";
+ $szControlFile = $szStoreSessionPath."/".$loadSessionID.".dat";
+
+ if (file_exists($szZipFilename) && file_exists($szControlFile)){
+
+ $aData = readSessionSaveControlFile($szControlFile);
+ $bSuccessfull = unzip($szZipFilename, $szDestination, $create_zip_name_dir=true, $overwrite=true);
+
+ if($aData && $bSuccessfull === TRUE){
+ $oReturn->success = TRUE;
+ $oReturn->mapname = $aData["mapname"];
+ $oReturn->extents = $aData["_afCurrentExtents"];
+ $oReturn->vislayers = $aData["aVisibleLayers"];
+ $oReturn->sessionname = $aData["sessionName"];
+ $oReturn->loadmap = $szDestination."/".$oReturn->mapname.'.map';
+
+ $oMap = ms_newMapObj($oReturn->loadmap);
+ checkForGMLLayers($szDestination);
+ $oMap->save($oReturn->loadmap);
+ echo var2json($oReturn);
+ }
+ else
+ {
+ die("{'error':'Could not load session control file ".$loadSessionID. ".dat.'}");
+ }
+ }
+ else
+ {
+ die("{'error':'map state ".$loadSessionID. " does not exist.'}");
+ }
+ }
+ else
+ {
+ die("{'error':'PHP Session path is invalid.'}");
+ }
+
+function checkForGMLLayers($szDestination){
+ global $oMap;
+ @$oLayer = $oMap->getLayerByName("LWEGML-Point");
+ if($oLayer){
+ $oLayer->set("connection", $szDestination."/features.gml");
+ }
+ @$oLayer = $oMap->getLayerByName("LWEGML-Line");
+ if($oLayer){
+ $oLayer->set("connection", $szDestination."/features.gml");
+ }
+ @$oLayer = $oMap->getLayerByName("LWEGML-Polygon");
+ if($oLayer){
+ $oLayer->set("connection", $szDestination."/features.gml");
+ }
+ @$oLayer = $oMap->getLayerByName("LWEGML-Annotation");
+ if($oLayer){
+ $oLayer->set("connection", $szDestination."/features.gml");
+ }
+}
+
+function readSessionSaveControlFile($szFileName){
+
+$handle = @fopen($szFileName, "r");
+
+if($handle)
+ {
+ $szData = fread($handle, filesize($szFileName));
+ fclose($handle);
+ }
+
+return unserialize($szData);
+}
+
+function unzip($src_file, $dest_dir=false, $create_zip_name_dir=true, $overwrite=true)
+{
+ if(function_exists("zip_open"))
+ {
+ if(!is_resource(zip_open($src_file)))
+ {
+ $src_file=dirname($_SERVER['SCRIPT_FILENAME'])."/".$src_file;
+ }
+
+ if (is_resource($zip = zip_open($src_file)))
+ {
+ $splitter = ($create_zip_name_dir === true) ? "." : "/";
+ if ($dest_dir === false) $dest_dir = substr($src_file, 0, strrpos($src_file, $splitter))."/";
+
+ // Create the directories to the destination dir if they don't already exist
+ create_dirs($dest_dir);
+
+ // For every file in the zip-packet
+ while ($zip_entry = zip_read($zip))
+ {
+ // Now we're going to create the directories in the destination directories
+
+ // If the file is not in the root dir
+ $pos_last_slash = strrpos(zip_entry_name($zip_entry), "/");
+ if ($pos_last_slash !== false)
+ {
+ // Create the directory where the zip-entry should be saved (with a "/" at the end)
+ create_dirs($dest_dir.substr(zip_entry_name($zip_entry), 0, $pos_last_slash+1));
+ }
+
+ // Open the entry
+ if (zip_entry_open($zip,$zip_entry,"r"))
+ {
+
+ // The name of the file to save on the disk
+ $file_name = $dest_dir.zip_entry_name($zip_entry);
+
+ // Check if the files should be overwritten or not
+ if ($overwrite === true || $overwrite === false && !is_file($file_name))
+ {
+ // Get the content of the zip entry
+ $fstream = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
+
+ if(!is_dir($file_name))
+ file_put_contents($file_name, $fstream );
+ // Set the rights
+ if(file_exists($file_name))
+ {
+ chmod($file_name, 0755);
+ //echo "<span style=\"color:#1da319;\">file saved: </span>".$file_name."<br />";
+ }
+ else
+ {
+ //echo "<span style=\"color:red;\">file not found: </span>".$file_name."<br />";
+ }
+ }
+
+ // Close the entry
+ zip_entry_close($zip_entry);
+ }
+ }
+ // Close the zip-file
+ zip_close($zip);
+ }
+ else
+ {
+ return false;
+ }
+
+ return true;
+ }
+ else
+ {
+ if(version_compare(phpversion(), "5.2.0", "<"))
+ $infoVersion="(use PHP 5.2.0 or later)";
+ die("error:'You need to install/enable the php_zip.dll extension $infoVersion'");
+ }
+}
+
+function create_dirs($path)
+{
+ if (!is_dir($path))
+ {
+ $directory_path = "";
+ $directories = explode("/",$path);
+ array_pop($directories);
+
+ foreach($directories as $directory)
+ {
+ $directory_path .= $directory."/";
+ if (!is_dir($directory_path))
+ {
+ mkdir($directory_path);
+ chmod($directory_path, 0777);
+ }
+ }
+ }
+}
+?>
\ No newline at end of file
Property changes on: trunk/layers/MapServer/php/RestoreState.php
___________________________________________________________________
Added: svn:keywords
+ Id
Modified: trunk/lib/Map.js
===================================================================
--- trunk/lib/Map.js 2009-11-30 09:18:05 UTC (rev 1997)
+++ trunk/lib/Map.js 2009-11-30 22:28:16 UTC (rev 1998)
@@ -41,7 +41,7 @@
Fusion.Event.MAP_RELOADED = Fusion.Event.lastEventId++;
Fusion.Event.MAP_SESSION_CREATED = Fusion.Event.lastEventId++;
Fusion.Event.MAP_MAPTIP_REQ_FINISHED = Fusion.Event.lastEventId++;
-Fusion.Event.MAP_MAPGROUPLOADED = Fusion.Event.lastEventId++;
+Fusion.Event.MAP_MAP_GROUP_LOADED = Fusion.Event.lastEventId++;
Fusion.Constant.LAYER_POINT_TYPE = 0;
@@ -169,7 +169,7 @@
this.registerEventID(Fusion.Event.MAP_SELECTION_ON);
this.registerEventID(Fusion.Event.MAP_SELECTION_OFF);
this.registerEventID(Fusion.Event.MAP_MAPTIP_REQ_FINISHED);
- this.registerEventID(Fusion.Event.MAP_MapGroupLoaded);
+ this.registerEventID(Fusion.Event.MAP_MAP_GROUP_LOADED);
this.registerForEvent(Fusion.Event.MAP_LOADED, OpenLayers.Function.bind(this.mapLoaded,this));
@@ -232,7 +232,7 @@
}
this.aMaps[i].registerForEvent(Fusion.Event.LAYER_LOADED, OpenLayers.Function.bind(this.layerLoaded,this));
}
- this.triggerEvent(Fusion.Event.MAP_MapGroupLoaded);
+ this.triggerEvent(Fusion.Event.MAP_MAP_GROUP_LOADED);
},
layerLoaded: function() {
@@ -245,8 +245,23 @@
if (this.aMaps.length == 1) {
this.oMapOL.setBaseLayer(this.aMaps[0].oLayerOL);
}
+ /*
+ Are we restoring a saved map state?
+ */
+ if(this.aMaps[0].bRestoreMapState && this.aMaps[0].bRestoreMapState === true && typeof(this.aMaps[0].oRestoredState.extents) !=="undefined"){
+ var a = this.aMaps[0].oRestoredState.extents.split(',');
+ a[0] = parseFloat(a[0]);
+ a[1] = parseFloat(a[1]);
+ a[2] = parseFloat(a[2]);
+ a[3] = parseFloat(a[3]);
+ this.setExtents(new OpenLayers.Bounds(a[0], a[1], a[2], a[3]));
+ }
+ else
+ {
var initialExtent = this.setInitialExtents();
this.setExtents(initialExtent);
+ }
+
this.triggerEvent(Fusion.Event.MAP_LOADED);
},
More information about the fusion-commits
mailing list