How to add time-aware layers

There are several ways to work with time-aware layers. The simplest is to use the TimeSlider control in the toolkit because it handles the process of updating the map's time extent for you. Alternatively, you can use the application programming interface (API) to build applications that perform temporal queries, filter layers using time definitions, and set the map's time extent.

Creating dates and times to use with time-aware layers

When working with time-aware layers, you may need to create dates and times in WPF. The platform has a DateTime class to define a specific time and a TimeSpan class to define a duration. Either can be used when creating a time extent to apply to a map or use to query a layer. When creating a new DateTime, always specify Universal Time Coordinated (UTC) for the time zone. UTC is a time standard based on atomic time and is functionally equivalent to Greenwich Mean Time (GMT). UTC is denoted by adding a Z to the end of the time string. For example, 2008-11-01T19:35:00.0000000Z represents Saturday, 01 Nov 2008 19:35:00 UTC.

If no time zone is specified, the ArcGIS for Server REST API returns the date string without time zone information. If you use a date without a time zone in a temporal query, the time zone may default to the current local time. This can result in dates that are off by several hours. The following example illustrates how to create a new TimeExtent instance and define a start time using a UTC date:

TimeExtent timeExtent = new ESRI.ArcGIS.Client.TimeExtent(); 
timeExtent.Start = DateTime.Parse("2002-01-01T17:33:46.0000000",
                                  CultureInfo.CurrentCulture,
                                  DateTimeStyles.AdjustToUniversal);

Working with time in the ArcGIS Runtime SDK for WPF

The ArcGIS Runtime SDK for WPF provides a TimeSlider control in the Toolkit library (ESRI.ArcGIS.Client.Toolkit.dll) 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 benefit of using the time slider is that it handles setting the map's time extent, which filters time-aware layers to only display data for the current time extent.

To set up the time slider, add a time-aware map or feature service to the map using the ArcGISDynamicMapService, ArcGISLocalDynamicMapService, FeatureLayer, or ArcGISLocalFeatureLayer class in Extensible Application Markup Language (XAML). Next, associate the value (time extent) of the TimeSlider with the time extent of the map using element binding, then create the number of tics (or stops) the slider displays (requires code-behind).

In the following code example, a feature layer represents a feature service that contains earthquakes at a specific time and location. The TimeSlider's minimum and maximum values are bound to the start and end time for features in the layer. The map's time extent is bound to the value (time extent) of the TimeSlider. When the feature layer is initialized, it has the information it needs to establish intervals for the TimeSlider. The initialize event is used to calculate and apply time intervals.

<esri:Map x:Name="MyMap" TimeExtent="{Binding ElementName=MyTimeSlider, Path=Value}">
    <esri:ArcGISTiledMapServiceLayer ID="BaseLayer"
        Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer" />
    <esri:FeatureLayer ID="EarthquakesLayer"
        Initialized="FeatureLayer_Initialized"
        Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/Since_1970/MapServer/0" />       
</esri:Map>

<esri:TimeSlider x:Name="MyTimeSlider" Height="20" TimeMode="CumulativeFromStart"
    MinimumValue="{Binding ElementName=MyMap, Path=Layers[EarthquakesLayer].TimeExtent.Start, Mode=OneWay}" 
    MaximumValue="{Binding ElementName=MyMap, Path=Layers[EarthquakesLayer].TimeExtent.End, Mode=OneWay}">
</esri:TimeSlider>
private void FeatureLayer_Initialized(object sender, EventArgs e) 
{
  List<DateTime> intervals = new List<DateTime>();
  DateTime dt = MyTimeSlider.MinimumValue; 
  while (dt < MyTimeSlider.MaximumValue) 
  {
    intervals.Add(dt); 
    dt =dt.AddYears(2); 
  } 
  MyTimeSlider.Intervals = intervals; 
}

Slider thumbs denote a location on the slider and are specified using the TimeMode property of the TimeSlider. The TimeMode property valid values are CumulativeFromStart, TimeInstant, and TimeExtent. By default, the TimeSlider contains one thumb (TimeInstant), which enables the user to define a time extent that ranges from the minimum value (earliest date) to a later date up to the maximum value. If two thumbs (TimeExtent) are included, the user can drag the thumbs to represent a time range or an instant on the slider. The CumulativeFromStart value of the TimeMode property has one non-visible thumb locked to the start of the TimeSlider and one visible thumb that is moveable. A set of buttons and members on the TimeSlider 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 rewind button to move the thumbs. A set of methods and properties enable you to control and manage the automation.

NoteNote:

Do not use the TimeSlider 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 a feature layer in snapshot mode. If your dataset is large, consider using an ArcGISDynamicMapServiceLayer instead.

Filtering data using the Map control's TimeExtent property

In addition to the TimeSlider, there are other techniques for visualizing time-aware layers in mapping applications. The Map control has a TimeExtent property that acts as a filter for time-aware layers. The TimeExtent property can be set on the Map control after it loads. In the following code example, only data that meets the input time definition of June 2, 2009, 0:00 UTC appears.

TipTip:

If the TimeExtent has not already been set on the Map control, you must specify both the Start and End values of the TimeExtent.

private void MyMap_Loaded(object sender, RoutedEventArgs e) 
{
  TimeExtent timeExtent = new ESRI.ArcGIS.Client.TimeExtent();
  timeExtent.Start = DateTime.Parse("2009-06-02T00:00:00.0000000Z",
                                    CultureInfo.CurrentCulture, 
                                    DateTimeStyles.AdjustToUniversal);
  timeExtent.End = DateTime.Parse("2010-6-30T17:33:46.0000000Z",
                                  CultureInfo.CurrentCulture,
                                  DateTimeStyles.AdjustToUniversal);

  MyMap.TimeExtent = timeExtent; 
}

All time-aware layers display features for the time extent defined by the Map control. The TimeExtent property on time-aware layers cannot be set explicitly since it is defined by the map, feature, or image service.

1/27/2015