Visual Basic (Declaration) | |
---|---|
Public Property UseTime As Boolean |
C# | |
---|---|
public bool UseTime {get; set;} |
It is the Map.TimeExtent that controls what features are displayed based upon the temporal information in the ArcGISDynamicMapServiceLayer. The Map.TimeExtent acts as to limit the features displayed based upon the window-of-time specified by the TimeExtent.Start and TimeExtent.End. One analogy you can think of is that the Map.TimeExtent is like a window in a house. Depending on the size of the window, allows how much you can see outside (i.e. the features in the ArcGISDynamicMapServiceLayer). See the visual analogy depiction.
If the TimeOption.UseTime = True then the data in the ArcGISDynamicMapServiceLayer returned is based upon occurrences between the TimeExtent.Start and TimeExtent.End of the Map Control. If the TimeOption.UseTime = False then time based queries are disabled for the ArcGISDynamicMapServiceLayer (meaning all of the records will be returned subject to any LayerDefinitons that may be set).
The ArcGISDynamicMapServiceLayer.LayerDefinitions take precedence over other data restriction techniques like those of the ArcGISDynamicMapServiceLayer.LayerTimeOptions. In other words, the ArcGISDynamicMapServiceLayer.LayerDefinitions acts to limit the data in the ArcGISDynamciMapServiceLayer that the ArcGISDynamicMapServiceLayer.LayerTimeOptions can operate on.
NOTE: A change was made to ArcGIS Server 10.02 (i.e. 10.0 Service Pack 2) and subsequents future versions that impacts what is needed to draw ALL features in an ArcGISDynamicMapServiceLayer that is time-enabled. Prior to ArcGIS Server 10.02, it was required in order to see the ALL features for a time-enabled ArcGISDynamicMapServiceLayer in a Map Control to either:
(1) set the Map.TimeExtent to a valid time that covered the features in the ArcGISDynamicMapServiceLayer
OR
(2) if no Map.TimeExtent was set on the Map Control, then each TimeOption for the sub-layer of the ArcGISDynamicMapServiceLayer needs to have the TimeOption.UseTime Property set to False.
As of ArcGIS Sever 10.02 and higher, the time-enabled ArcGISDynamicMapServiceLayer will automatically show ALL features, even if no Map.TimeExtent is set. See the code example in the ArcGISDynamicMapServiceLayer.LayerTimeOptions document for a demonstration.
How to use:
When the application loads all trees maintained in the San Francisco database with an ID less that 500 will be displayed. Choose the different UseTime RadioButton options to see what effect occurs in the features being drawn in the Map (and their count). When UseTime = True the data in the ArcGISDynamicMapServiceLayer returned is based upon occurrences between the TimeExtent.Start (1/1/2000) and TimeExtent.End (12/31/2000) of the Map Control and will display 4 features. When UseTime = False then time based queries are disabled for the ArcGISDynamicMapServiceLayer (meaning all of the records will be returned subject to any LayerDefinitons that may be set) and will display 171 features.
The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.
The following screen shot corresponds to the code example in this page.
XAML | Copy Code |
---|---|
<Grid x:Name="LayoutRoot"> <!-- Add a Map Control. --> <esri:Map Name="Map1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="14,240,0,0" Height="350" Width="500" WrapAround="True" Extent="-13641670,4536157,-13616982,4553439"> <esri:Map.Layers> <esri:LayerCollection> <!-- Add a backdrop ArcGISTiledMapServiceLayer. --> <esri:ArcGISTiledMapServiceLayer Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer" /> <!-- Add an ArcGISDynamicMapServiceLayer. The layer displays trees maintained in San Francisco. Because the amomut od data points in the service is large, a LayerDefinition has been applied such that only those trees with and numerical ID value of less that 500 will be drawn in the Map. The Initialized event is wired up to display the TimeExtents for which the trees will be displayed as well as count of the number of occurances displayed in the Map. The DisableClientCaching is set to true which means all Rendering logic will be handled on ArcGIS Server. The LayerDefinition takes precidence over other data restriction types of queries like the LayerTimeOptions. --> <esri:ArcGISDynamicMapServiceLayer ID="SanFranciscoTrees" Url="http://servicesbeta.esri.com/ArcGIS/rest/services/SanFrancisco/SFStreetTreesRendered/MapServer" DisableClientCaching="True" Initialized="ArcGISDynamicMapServiceLayer_Initialized"> <esri:ArcGISDynamicMapServiceLayer.LayerDefinitions> <esri:LayerDefinition LayerID="0" Definition="TreeID < 500"/> </esri:ArcGISDynamicMapServiceLayer.LayerDefinitions> </esri:ArcGISDynamicMapServiceLayer> </esri:LayerCollection> </esri:Map.Layers> </esri:Map> <!-- Display the TimeExtent information being used by the Map Control. --> <sdk:Label Height="21" HorizontalAlignment="Left" Margin="12,111,0,0" Name="Label_TimeExtent_Start" VerticalAlignment="Top" Width="120" Content="Map.TimeExtent.Start:"/> <TextBox Height="23" HorizontalAlignment="Left" Margin="140,106,0,0" Name="TextBox_TimeExtent_Start" VerticalAlignment="Top" Width="374" /> <sdk:Label Height="21" HorizontalAlignment="Left" Margin="12,146,0,0" Name="Label_TimeExtent_End" VerticalAlignment="Top" Width="120" Content="Map.TimeExtent.End:"/> <TextBox Height="23" HorizontalAlignment="Left" Margin="140,144,0,0" Name="TextBox_TimeExtent_End" VerticalAlignment="Top" Width="374" /> <TextBlock Height="23" HorizontalAlignment="Left" Margin="12,109,0,0" Name="TextBlock_Ignored" Visibility="Visible" Text="---------------------------------------------- I G N O R E D --------------------------------------" VerticalAlignment="Top" Width="502" Foreground="Red" FontFamily="Arial" FontSize="14"/> <TextBlock Height="23" HorizontalAlignment="Left" Margin="14,144,0,0" Name="TextBlock_Ignored2" Visibility="Visible" Text="---------------------------------------------- I G N O R E D --------------------------------------" VerticalAlignment="Top" Width="502" Foreground="Red" FontFamily="Arial" FontSize="14"/> <!-- Allow the user to change the ArcGISDynamicMapServiceLayer's UseTime options. If UseTime = True then the data in the ArcGISDynamicMapServiceLayer returned is based upon occurrences between the TimeExtent.Start and TimeExtent.End of the Map Control. If UseTime = False then time based queries are disabled for the ArcGISDynamicMapServiceLayer (meaning all of the records will be returned subject to any LayerDefinitons that may be set). --> <sdk:Label Height="22" HorizontalAlignment="Left" Margin="14,180,0,0" Name="Label_UseTime" VerticalAlignment="Top" Width="120" Content="UseTime:" /> <RadioButton Content="True" Height="16" HorizontalAlignment="Left" Margin="72,181,0,0" Name="rb_UseTime_True" VerticalAlignment="Top" /> <RadioButton Content="False" Height="16" HorizontalAlignment="Left" Margin="123,181,0,0" Name="rb_UseTime_False" VerticalAlignment="Top" IsChecked="True"/> <!-- Display the number of features that are returned as a result of changing the ArcGISDynamicMapServiceLayer's UseTime options. --> <sdk:Label Content="Number of Features:" Height="23" HorizontalAlignment="Left" Margin="284,181,0,0" Name="Label_NumberOfFeatures" VerticalAlignment="Top" Width="120" /> <TextBox Height="23" HorizontalAlignment="Left" Margin="401,176,0,0" Name="TextBox_NumberOfFeatures" VerticalAlignment="Top" Width="113" /> <!-- Add a button to demonstrate changing the ArcGISDynamicServiceLayer's UseTime options. --> <Button Content="Apply ArcGISDynamicMapServiceLayer.LayerTimeOptions" Height="23" HorizontalAlignment="Left" Margin="14,207,0,0" Name="Button1" VerticalAlignment="Top" Width="500" Click="Button1_Click"/> <!-- Provide the instructions on how to use the sample code. --> <TextBlock Height="100" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="788" TextWrapping="Wrap" Text="When the application loads all trees maintained in the San Francisco database with an ID less that 500 will be displayed. Choose the different UseTime RadioButton options to see what effect occurs in the features being drawn in the Map (and their count). When UseTime = True the data in the ArcGISDynamicMapServiceLayer returned is based upon occurrences between the TimeExtent.Start (1/1/2000) and TimeExtent.End (12/31/2000) of the Map Control and will display 4 features. When UseTime = False then time based queries are disabled for the ArcGISDynamicMapServiceLayer (meaning all of the records will be returned subject to any LayerDefinitons that may be set) and will display 171 features." /> </Grid> |
C# | Copy Code |
---|---|
private void Button1_Click(object sender, System.Windows.RoutedEventArgs e) { // Get the ArcGISDynamicMapServiceLayer. ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = null; myArcGISDynamicMapServiceLayer = (ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)(Map1.Layers["SanFranciscoTrees"]); // Create a new LayerTimeOptionCollection object. ESRI.ArcGIS.Client.LayerTimeOptionCollection myLayerTimeOptionCollection = new ESRI.ArcGIS.Client.LayerTimeOptionCollection(); // Create a new TimeOption object. You can have multiple TimeOption objects; one for each FeatureLayer in // the ArcGISDynamicMapServicelayer. ESRI.ArcGIS.Client.Tasks.TimeOption myTimeOption1 = new ESRI.ArcGIS.Client.Tasks.TimeOption(); // This the Layer ID from REST. Although the .LayerID property accepts a string you need to give it the integer // value of a specific FeatureLayer in the ArcGISDynamicMapServiceLayer. myTimeOption1.LayerId = Convert.ToString(0); // Create some variables used to obtain a count of the number of features returned via a QueryTask. The QueryTask // will approximate the same SQL syntax that is used by the ArcGISDynamicMapServiceLayer's TimeDataCumulative Property. string mySqlQuery = null; string mySubLayer_LayerDefinition = myArcGISDynamicMapServiceLayer.LayerDefinitions(0).Definition; // If TimeDataCumulative = False then all the features from the beginning of Map.TimeExtent.Start to // Map.TimeExtent.End are returned. myTimeOption1.TimeDataCumulative = false; if (rb_UseTime_True.IsChecked == true) { //mySqlQuery = "qCaretaker = 'TreeID < 500 AND PlantDate >= '1/1/2001' AND PlantDate <= '12/31/2001'" mySqlQuery = mySubLayer_LayerDefinition + " AND PlantDate >= '" + TextBox_TimeExtent_Start.Text + "' AND PlantDate <= '" + TextBox_TimeExtent_End.Text + "'"; TextBlock_Ignored.Visibility = Windows.Visibility.Collapsed; TextBlock_Ignored2.Visibility = Windows.Visibility.Collapsed; myTimeOption1.UseTime = true; } else if (rb_UseTime_False.IsChecked == true) { //mySqlQuery = "TreeID < 500" mySqlQuery = mySubLayer_LayerDefinition; TextBlock_Ignored.Visibility = Windows.Visibility.Visible; TextBlock_Ignored2.Visibility = Windows.Visibility.Visible; myTimeOption1.UseTime = false; } // Add the various options for the TimeOption into the LayerTimeOptionCollection. Note: you could have multiple TimeOption // objects and set the various values independently -- i.e. the ArcGISDynamicMapServiceLayer could have multiple // FeatureLayers each that is Time enabled. myLayerTimeOptionCollection.Add(myTimeOption1); // Set the ArcGISDynamicMalServiceLayer.LayerTimeOptions to the custom LayerTimeOptionCollection. myArcGISDynamicMapServiceLayer.LayerTimeOptions = myLayerTimeOptionCollection; // Create a TimeExtent object based upon what the user specifies for a TimeExtent.Start and TimeExtent.End. ESRI.ArcGIS.Client.TimeExtent myTimeExtent = new ESRI.ArcGIS.Client.TimeExtent(Convert.ToDateTime(TextBox_TimeExtent_Start.Text), Convert.ToDateTime(TextBox_TimeExtent_End.Text)); // Set the Map.TimeExtent which will cause the ArcGISDynamicMapServiceLayer to re-render based upon the // new TimeExtent values. Map1.TimeExtent = myTimeExtent; // Display the number of features being returned in the ArcGISDynamicMapServiceLayer. GetFeatureCount(mySqlQuery); } private void ArcGISDynamicMapServiceLayer_Initialized(object sender, System.EventArgs e) { // Set the values that the Map Control will use for the TimeExtent. TextBox_TimeExtent_Start.Text = Convert.ToString(new DateTime(2000, 1, 1)); TextBox_TimeExtent_End.Text = Convert.ToString(new DateTime(2000, 12, 31)); // Create a SQL query that will perform QueryTask that approximates the same SQL syntax that is used by // the ArcGISDynamicMapServiceLayer's UseTime Property. string mySqlQuery = null; ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = (ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)sender; string mySubLayer_LayerDefinition = myArcGISDynamicMapServiceLayer.LayerDefinitions(0).Definition; GetFeatureCount(mySubLayer_LayerDefinition); } private void GetFeatureCount(string sqlQuery) { // This function approximates the same SQL syntax that is used by the ArcGISDynamicMapServiceLayer's // UseTime Property and displays the feature count back to the user. // Get the ArcGISDynamicMapServicelayer. ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = null; myArcGISDynamicMapServiceLayer = (ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)(Map1.Layers["SanFranciscoTrees"]); // Get the Url of the ArcGISDynamicMapServiceLayer. string myUrl = myArcGISDynamicMapServiceLayer.Url; // Get the ID of the SanFranciscoTrees sub-layer. int mySubLayerID = myArcGISDynamicMapServiceLayer.Layers(0).ID; // Create a Query. Use the Map's Extent and SpatialReference. Return all the fields. ESRI.ArcGIS.Client.Tasks.Query myQuery = new ESRI.ArcGIS.Client.Tasks.Query(); myQuery.Geometry = Map1.Extent; myQuery.OutSpatialReference = Map1.SpatialReference; myQuery.OutFields.Add("*"); myQuery.Where = sqlQuery; // Create a QueryTask using the correct Url and Query Parameters. ESRI.ArcGIS.Client.Tasks.QueryTask myQueryTask = new ESRI.ArcGIS.Client.Tasks.QueryTask(); //queryTask.Url = "http://servicesbeta.esri.com/ArcGIS/rest/services/SanFrancisco/SFStreetTreesRendered/MapServer/0" myQueryTask.Url = myUrl + "/" + mySubLayerID.ToString(); myQueryTask.ExecuteAsync(myQuery); // Add the Event Handler for the Asynchronous QueryTask request. myQueryTask.ExecuteCompleted += myQueryTask_ExecuteCompleted; } private void myQueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs e) { // Check to ensure we have valid return results. if (e.FeatureSet == null) { return; } // Obtain a FeatureSet from the queryArgs returned from the web service. ESRI.ArcGIS.Client.Tasks.FeatureSet myFeatureSet = e.FeatureSet; // Get the Features from the FeatureSet. System.Collections.Generic.IList<ESRI.ArcGIS.Client.Graphic> myFeatures = myFeatureSet.Features; // Display the number of features returned from the QueryTask. int myCount = myFeatures.Count; TextBox_NumberOfFeatures.Text = myCount.ToString(); } |
VB.NET | Copy Code |
---|---|
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) ' Get the ArcGISDynamicMapServiceLayer. Dim myArcGISDynamicMapServiceLayer As ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = CType(Map1.Layers("SanFranciscoTrees"), ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer) ' Create a new LayerTimeOptionCollection object. Dim myLayerTimeOptionCollection As New ESRI.ArcGIS.Client.LayerTimeOptionCollection ' Create a new TimeOption object. You can have multiple TimeOption objects; one for each FeatureLayer in ' the ArcGISDynamicMapServicelayer. Dim myTimeOption1 As New ESRI.ArcGIS.Client.Tasks.TimeOption ' This the Layer ID from REST. Although the .LayerID property accepts a string you need to give it the integer ' value of a specific FeatureLayer in the ArcGISDynamicMapServiceLayer. myTimeOption1.LayerId = CStr(0) ' Create some variables used to obtain a count of the number of features returned via a QueryTask. The QueryTask ' will approximate the same SQL syntax that is used by the ArcGISDynamicMapServiceLayer's TimeDataCumulative Property. Dim mySqlQuery As String = Nothing Dim mySubLayer_LayerDefinition As String = myArcGISDynamicMapServiceLayer.LayerDefinitions(0).Definition ' If TimeDataCumulative = False then all the features from the beginning of Map.TimeExtent.Start to ' Map.TimeExtent.End are returned. myTimeOption1.TimeDataCumulative = False If rb_UseTime_True.IsChecked = True Then 'mySqlQuery = "qCaretaker = 'TreeID < 500 AND PlantDate >= '1/1/2001' AND PlantDate <= '12/31/2001'" mySqlQuery = mySubLayer_LayerDefinition + " AND PlantDate >= '" + TextBox_TimeExtent_Start.Text + "' AND PlantDate <= '" + TextBox_TimeExtent_End.Text + "'" TextBlock_Ignored.Visibility = Windows.Visibility.Collapsed TextBlock_Ignored2.Visibility = Windows.Visibility.Collapsed myTimeOption1.UseTime = True ElseIf rb_UseTime_False.IsChecked = True Then 'mySqlQuery = "TreeID < 500" mySqlQuery = mySubLayer_LayerDefinition TextBlock_Ignored.Visibility = Windows.Visibility.Visible TextBlock_Ignored2.Visibility = Windows.Visibility.Visible myTimeOption1.UseTime = False End If ' Add the various options for the TimeOption into the LayerTimeOptionCollection. Note: you could have multiple TimeOption ' objects and set the various values independently -- i.e. the ArcGISDynamicMapServiceLayer could have multiple ' FeatureLayers each that is Time enabled. myLayerTimeOptionCollection.Add(myTimeOption1) ' Set the ArcGISDynamicMalServiceLayer.LayerTimeOptions to the custom LayerTimeOptionCollection. myArcGISDynamicMapServiceLayer.LayerTimeOptions = myLayerTimeOptionCollection ' Create a TimeExtent object based upon what the user specifies for a TimeExtent.Start and TimeExtent.End. Dim myTimeExtent As New ESRI.ArcGIS.Client.TimeExtent(CDate(TextBox_TimeExtent_Start.Text), CDate(TextBox_TimeExtent_End.Text)) ' Set the Map.TimeExtent which will cause the ArcGISDynamicMapServiceLayer to re-render based upon the ' new TimeExtent values. Map1.TimeExtent = myTimeExtent ' Display the number of features being returned in the ArcGISDynamicMapServiceLayer. GetFeatureCount(mySqlQuery) End Sub Private Sub ArcGISDynamicMapServiceLayer_Initialized(sender As System.Object, e As System.EventArgs) ' Set the values that the Map Control will use for the TimeExtent. TextBox_TimeExtent_Start.Text = CStr(New Date(2000, 1, 1)) TextBox_TimeExtent_End.Text = CStr(New Date(2000, 12, 31)) ' Create a SQL query that will perform QueryTask that approximates the same SQL syntax that is used by ' the ArcGISDynamicMapServiceLayer's UseTime Property. Dim mySqlQuery As String = Nothing Dim myArcGISDynamicMapServiceLayer As ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer = CType(sender, ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer) Dim mySubLayer_LayerDefinition As String = myArcGISDynamicMapServiceLayer.LayerDefinitions(0).Definition GetFeatureCount(mySubLayer_LayerDefinition) End Sub Private Sub GetFeatureCount(sqlQuery As String) ' This function approximates the same SQL syntax that is used by the ArcGISDynamicMapServiceLayer's ' UseTime Property and displays the feature count back to the user. ' Get the ArcGISDynamicMapServicelayer. Dim myArcGISDynamicMapServiceLayer As ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = CType(Map1.Layers("SanFranciscoTrees"), ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer) ' Get the Url of the ArcGISDynamicMapServiceLayer. Dim myUrl As String = myArcGISDynamicMapServiceLayer.Url ' Get the ID of the SanFranciscoTrees sub-layer. Dim mySubLayerID As Integer = myArcGISDynamicMapServiceLayer.Layers(0).ID ' Create a Query. Use the Map's Extent and SpatialReference. Return all the fields. Dim myQuery As New ESRI.ArcGIS.Client.Tasks.Query myQuery.Geometry = Map1.Extent myQuery.OutSpatialReference = Map1.SpatialReference myQuery.OutFields.Add("*") myQuery.Where = sqlQuery ' Create a QueryTask using the correct Url and Query Parameters. Dim myQueryTask As New ESRI.ArcGIS.Client.Tasks.QueryTask 'queryTask.Url = "http://servicesbeta.esri.com/ArcGIS/rest/services/SanFrancisco/SFStreetTreesRendered/MapServer/0" myQueryTask.Url = myUrl + "/" + mySubLayerID.ToString myQueryTask.ExecuteAsync(myQuery) ' Add the Event Handler for the Asynchronous QueryTask request. AddHandler myQueryTask.ExecuteCompleted, AddressOf myQueryTask_ExecuteCompleted End Sub Private Sub myQueryTask_ExecuteCompleted(sender As Object, e As ESRI.ArcGIS.Client.Tasks.QueryEventArgs) ' Check to ensure we have valid return results. If e.FeatureSet Is Nothing Then Return End If ' Obtain a FeatureSet from the queryArgs returned from the web service. Dim myFeatureSet As ESRI.ArcGIS.Client.Tasks.FeatureSet = e.FeatureSet ' Get the Features from the FeatureSet. Dim myFeatures As System.Collections.Generic.IList(Of ESRI.ArcGIS.Client.Graphic) = myFeatureSet.Features ' Display the number of features returned from the QueryTask. Dim myCount As Integer = myFeatures.Count TextBox_NumberOfFeatures.Text = myCount.ToString End Sub |
Target Platforms:Windows Phone 7