Select to view content in your preferred language

How to reset the timeslider (ex. when widgets closes/when at the end of timeline)

3357
7
Jump to solution
03-19-2012 03:42 AM
LeenD_hondt
Occasional Contributor
Hi,

I saw in all examples I could find that the folowing is used when the timeslider widget is closed:

 protected function widgetClosedHandler(event:Event):void             {                 timeSlider.pause();                 map.timeSlider = null;                 map.timeExtent = null;             }


However, when the widget is reopened afterwards, the timeslider is not reset to the startdate (as paused).

I am trying to find a way that, when the widget is closed, and then reopened, the timeslider is reset to the startdate automatically.

Any tips? (In the API Reference I could not find any attribute which to set - I do not want to 'replay' automatically but just put the slider on the startdate when the widget opens every time)

Thanks in advance,
Kindly,
Leen
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Leen,

   Sure it should be as simple as this:

timeSlider.thumbIndexes = [timeSlider.timeStops.length - 1];


Don't forget to click the top arrow (promote) as shown below:

View solution in original post

0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Emeritus
Leen,

   Sure, this now you do it:

timeSlider.slider.setThumbValueAt(timeSlider.thumbCount - 1, 0)


Don't forget to click the Mark as answer check on this post and to click the top arrow (promote) as shown below:
0 Kudos
LeenD_hondt
Occasional Contributor
I had found that code but did not understand it however, in this context I do. It works!

You are really helping me out! Thanks again!!
Leen


Leen,

   Sure, this now you do it:

timeSlider.slider.setThumbValueAt(timeSlider.thumbCount - 1, 0)


Don't forget to click the Mark as answer check on this post and to click the top arrow (promote) as shown below:
0 Kudos
LeenD_hondt
Occasional Contributor
Hi, I have a question related to the former one. Any help would be great..

I want that after the user closes the widget, that he can re-open it and play it as before. However, with the codeline below, the timeslider is set to the startingpoint but my widget is not working anymore (the slider is working but the data behind are not showing anymore).

Beneath how I configured my mxml:

<viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009"
       xmlns:s="library://ns.adobe.com/flex/spark"
       xmlns:mx="library://ns.adobe.com/flex/mx"
       xmlns:viewer="com.esri.viewer.*"
       xmlns:esri="http://www.esri.com/2008/ags"
       widgetConfigLoaded="init()"> 


...

   protected function init():void
   {
    trace ("init view track");
    if (configXML)
    {
     layerNAM= configXML.layername; 
     if (layerNAM != null) 
     {
      for each (var layer:Layer in map.layers)
      {
       if (layer.id==configXML.layername) { 
        fLayer=layer as ArcGISDynamicMapServiceLayer;
        
        if (fLayer.visible==false) {
         fLayer.visible=true;
        }
        timeInfo=fLayer.timeInfo;
        map.timeSlider = myTimeSlider;
        myTimeSlider.createTimeStopsByTimeInterval(timeInfo.timeExtent,1,TimeInfo.UNIT_MINUTES); 
        break;
       }
      } 
     }     
    }
   } 


...

protected function widgetOpenedHandler(event:Event):void
   {
    init();
   }

   
protected function widgetClosedHandler(event:Event):void
   {

    myTimeSlider.pause();
    map.timeSlider = null;
    map.timeExtent = null;
    myTimeSlider.slider.setThumbValueAt(myTimeSlider.thumbCount - 1, 0); //reset to starting position
    myTimeSlider.createTimeStopsByTimeInterval(timeInfo.timeExtent,1,TimeInfo.UNIT_MINUTES); //reset to 1 min interval
    fLayer.visible=false; 
   }



<viewer:WidgetTemplate id="timeTrack" 
         width="580" height="250"
         closed="widgetClosedHandler(event)"
         open="widgetClosedHandler(event)">


So when my widget opens, I want him to redo my process but that is not working. Any tips?


I had found that code but did not understand it however, in this context I do. It works!

You are really helping me out! Thanks again!!
Leen
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Leen,

   I don't believe that you need to go to the extent that you are in the widgetClosedHandler.

            protected function widgetClosedHandler(event:Event):void
            {
                timeSlider.pause();
                map.timeSlider = null;
                map.timeExtent = null;
            }


But you do need to do something different in the widgetOpenedHandler:

            protected function widgetOpenedHandler(event:Event):void
            {
                map.timeSlider = timeSlider;
                if(timeInfo){
                    timeSlider.slider.setThumbValueAt(timeSlider.thumbCount - 1, 0);
                    myTimeSlider.createTimeStopsByTimeInterval(timeInfo.timeExtent,1,TimeInfo.UNIT_MINUTES);                
                }
            }


Don't forget to click the top arrow (promote) on this post as shown below:


By the way it is always better to start a new thread and not just add on questions to existing questions that have already been answered.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Leen,

   It turns out after talking to Dasa from the Flex API team this week while I am at the Dev Summit I was making this more complicated than it needed to be. All you have to do is this one line:

timeSlider.thumbIndexes = [0];
and that resets the time extent and the slider back to the beginning.
0 Kudos
LeenD_hondt
Occasional Contributor
Dear Robert, thanks.

Just in case: Do you maybe have the same easy solution to set the time slider to the end?
(I work with user defined intervals, so I cannot use the methodology with timestops to set the end value of the slider)
I tried 
timeSlider.slider.setThumbValueAt(timeSlider.thumbCount - 1, timeSlider.slider.maximum);
but without succes..

Thanks for all your support!
Leen

Leen,

   It turns out after talking to Dasa from the Flex API team this week while I am at the Dev Summit I was making this more complicated than it needed to be. All you have to do is this one line:

timeSlider.thumbIndexes = [0];
and that resets the time extent and the slider back to the beginning.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Leen,

   Sure it should be as simple as this:

timeSlider.thumbIndexes = [timeSlider.timeStops.length - 1];


Don't forget to click the top arrow (promote) as shown below:
0 Kudos