How to work with the time slider control

The ArcGIS Runtime SDK for Java provides a JTimeSlider component in the Toolkit library that simplifies the process of visualizing temporal data. Using the time slider, you can filter the map to display cumulative data up to a point in time, a single point in time, or data that falls within a time range. The benefits of using the time slider are that it filters time-aware layers to only display data for the current time extent and can play back changes over time.

You should not use the time slider with feature layers in the "on demand" mode because it can result in too many requests to the server. If you're not working with a large amount of data, you can use an ArcGISFeatureLayer in snapshot mode. If your dataset is large, consider using an ArcGISDynamicMapServiceLayer instead.

Steps:
  1. Add the time slider to the user interface of your application:
    JTimeSlider jTimeSlider = new JTimeSlider();
    jComponent.add(jTimeSlider, BorderLayout.SOUTH);
    

  2. Create the time-aware layer. In the following code example, a feature layer represents a feature service that contains earthquakes at a specific time and location:
    ArcGISFeatureLayer earthquakesLayer = new ArcGISFeatureLayer(
    "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/Since_1970/MapServer/0");
    
  3. Setup the time slider using one of two options:

    Setup the time-slider from a layer

    Any time-aware layer can be used to setup the time slider; the time extent, interval and other properties from the layer are honoured by the time slider.

    earthquakesLayer.addLayerInitializeCompleteListener(new LayerInitializeCompleteListener() {
    			@Override
    			public void layerInitializeComplete(LayerInitializeCompleteEvent arg0) {
    				jTimeSlider.setupFromLayer((TimeAwareLayer) arg0.getLayer());
        jTimeSlider.setTitle("Earthquakes");
    			}
    		});
    

    Setup the time-slider using it's properties

    This option is useful when you have more than one time-aware layer with different time extents or if the setting up the time slider from a layer does not give you the time extent or tick that you want. Time-aware layers can be added to the slider before they are initialized.

    jTimeSlider.setTitle("Earthquakes");
    				jTimeSlider.addLayer(layer);				
    				jTimeSlider.setTimeExtent(new TimeExtent(
                                      new GregorianCalendar(1960, 1, 1), new GregorianCalendar(2019, 1, 1)), 
                                                           10, Units.Years));
    
  4. Add the time-aware layer to your map
    jMap.getLayers.add(earthquakesLayer);//Note: a baselayer has already been added to the map
    
  5. Optionally control the time slider's playback
    jTimeSlider.setTimeMode(TimeMode.CumulativeFromStart);
    jTimeSlider.setPlaybackRate(2000);//tick every two seconds
    jTimeSlider.play();//start the playback
    
  6. Use the time slider in an application

    Use the TimeMapServiceApp in the sample application to experiment with the time slider. Slider thumbs denote a location on the slider and are specified with the JTimeSlider.setTimeMode() method. The time mode valid values are CumulativeFromStart, TimeInstant, and TimeExtent. By default, the JTimeSlider contains two thumbs (the TimeExtent mode), the user can drag the thumbs to represent a time range. One thumb (the TimeInstant mode) enables the user to define specific time to filter the data by. The CumulativeFromStart mode has one thumb locked to the start of the time slider and one thumb that is moveable. A set of buttons on the time slider also enable you to automate the display of time extents by iterating through a sequence of ranges or intervals. The control contains a play button to automatically step through the sequence, and a forward and back button to move the thumbs.

2/7/2013