Select to view content in your preferred language

Save session state

3854
19
04-08-2010 11:23 AM
DouglasGuess
Occasional Contributor
I'm looking to modify the SFV to handle saving a users session state.  More specifically, I would like to be able to save what layers in the LiveMapsWidget are on, extent the map is at, etc....  So, when that user leaves the map, maybe a prompt asking if they would like to "save their settings".  Then, when they return, another prompt asking if they would like to "restore their settings" and everything is as it was, visible layers, extent, etc... something like that.

Has anyone implemented something like this?  Casey Bentz sent me some sample code (thanks Casey!) but it's not using the SFV and I'm having some difficulty getting this to work.  I believe this can be accomplished using SharedObjects but not exactly sure how to get it to work with the SFV.

I read at http://forums.esri.com/Thread.asp?c=158&f=2421&t=284721&mc=27#msgid883724 that Robert Scheitlin has an implementation for this. Robert, any help would be great!

Thanks.
Tags (2)
0 Kudos
19 Replies
RobertScheitlin__GISP
MVP Emeritus
Doug,

  This is far from complete but it saves the extent and all layers visibility when the SFV is closed and reloads those when the SFV opens. It uses the Flash Player shared objects. One of the big problems is that the LiveMapsWidget's TOC does not update based on programmatic changes to layers visibility. There are many things left to do like ask if the user wants to load the last state when the SFV opens.
0 Kudos
DouglasGuess
Occasional Contributor
Thanks Robert.  However, when I try to download the zip file, I get an error stating that the file is corrupt.  Would you mind posting another zip file?  Or, you could just email me the files (dguess@lancaster.ne.gov)

Thanks again!
0 Kudos
MattiasEkström
Regular Contributor
I wanted this functionality in my customized FlexViewer 2.1, and thought I could try this code from Robert. I copied the changes that Robert made to the files, and pasted the into the corresponding places in my code and then step by step got rid of the errors (caused by using SFV 1.3 code in SFV 2.1).
Then I was actually surprised to see that it seems to be working fine; extent, turned on layers and even the check-boxes in my TOC.

I would also like to be able to save which widget that are open, does anyone know how to do that? I'm guessing the first thing I need to know is how to programatically identify which widget that are opened and closed and then programatically open widgets.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Mattias,

   You need to do something along this line in the mapManager

for(var w:int=0; w<configData.widgetContainers.length; w++)
    {
     for(var wig:int=0; wig<configData.widgetContainers.widgets.length; wid++)
     {
      var wgt:Object = configData.widgetContainers.widgets[wid];
      var preload:String  = wgt.preload;
      var label:String    = wgt.label;
      var icon:String     = wgt.icon;
      var config:String   = wgt.config;
      var url:String      = wgt.url;
      var headless:String = wgt.headless;
     }
    }
0 Kudos
DanielLewis
New Contributor II
Robert,

Sorry for bringing up an old thread, but I'm trying to implement your code you provided in this thread to allow session state to be saved.  I've copied your changes to my index.mxml, mapmanager.mxml and index.html, compiled and copied the new index.html and index.swf to the website and the state is not being restored. 

Is the index.swf and index.html the only post-build files that will need to be copied over? 

What triggers the function to save the state at the sfv close (clicking on the web browser close button?).
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Daniel,

   Yes it is the browser window closing that fires the save code. The below code is triggered from the index.html. So one of the first things to do is look for this line in the index.html that you are putting on the server. As far as which files need to be moved to the server I would think just the index.swf and index.html, but I normally just grab them all.

window.onbeforeunload = clean_up;
0 Kudos
DanielLewis
New Contributor II
Daniel,

   Yes it is the browser window closing that fires the save code. The below code is triggered from the index.html. So one of the first things to do is look for this line in the index.html that you are putting on the server. As far as which files need to be moved to the server I would think just the index.swf and index.html, but I normally just grab them all.

window.onbeforeunload = clean_up;


Robert,

Thanks again for your help.  I'll give that a try and report back. 

Also, can you tell me how to do the equivalent of a wscript.echo type statement so I can place that type of statement in the code and have it show a popup at that point so I can see if it is making it into specific routines for debugging/troubleshooting.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Daniel,

   If you are talking about the javascript code than it is

alert('hello');
.

  If you are talking the ActionScript code then it is

import mx.controls.Alert;
Alert.show("Hello");
0 Kudos
DanielLewis
New Contributor II
Daniel,

   Yes it is the browser window closing that fires the save code. The below code is triggered from the index.html. So one of the first things to do is look for this line in the index.html that you are putting on the server. As far as which files need to be moved to the server I would think just the index.swf and index.html, but I normally just grab them all.

window.onbeforeunload = clean_up;


I confirmed that my indexl.html does have that line:

<html lang="en">
<!-- 
////////////////////////////////////////////////////////////////////////////////
//
// Copyright © 2008 - 2009 ESRI
//
// All rights reserved under the copyright laws of the United States.
// You may freely redistribute and use this software, with or
// without modification, provided you include the original copyright
// and use restrictions.  See use restrictions in the file:
// <install location>/FlexViewer/License.txt
//
////////////////////////////////////////////////////////////////////////////////
// -->

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="keywords" content="ESRI, ArcGIS, Flex, Flex SDK, Viewer, GeoWeb"/>
  <meta name="description" content="Flex Viewer to demonstrate the best practice to develop GeoWeb application by leveraging the power of spatial technologies"/>
  <meta name="revised" content="version 1.0, Nov 14, 2008" />
  
  <title>Viewer</title>

  <script src="AC_OETags.js" language="javascript"></script>

  <style>
    body { margin: 0px; overflow:hidden }
  </style>
  
</head>



<body scroll='no'>
<script language="JavaScript" type="text/javascript">
<!--
  AC_FL_RunContent(
     "src", "index",
     "width", "100%",
     "height", "100%",
     "align", "middle",
     "id", "index",
     "quality", "high",
     "bgcolor", "#6e6e6e",
     "name", "index",
     "allowScriptAccess","sameDomain",
     "type", "application/x-shockwave-flash",
     "pluginspage", "http://www.adobe.com/go/getflashplayer"
 );
// -->
</script>


<!--New JavaScript function for State-->
<script language="JavaScript" type="text/javascript">

 window.onbeforeunload = clean_up;

 function clean_up()
 {
  var flex = document.${application} || window.${application};
  flex.savesettings();
 }
</SCRIPT>
<!--End New JavaScript function for State-->


<noscript>
 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
   id="index" width="100%" height="100%"
   codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
   <param name="movie" value="index.swf" />
   <param name="quality" value="high" />
   <param name="bgcolor" value="#6e6e6e" />
   <param name="allowScriptAccess" value="sameDomain" />
   <embed src="index.swf" quality="high" bgcolor="#6e6e6e"
    width="100%" height="100%" name="index" align="middle"
    play="true"
    loop="false"
    quality="high"
    allowScriptAccess="sameDomain"
    type="application/x-shockwave-flash"
    pluginspage="http://www.adobe.com/go/getflashplayer">
   </embed>
 </object>
</noscript>
</body>
</html>


And, I've double-checked to make sure that all of the changes you listed in your files are in mine.
0 Kudos