Select to view content in your preferred language

Graphic TimeExtent null

679
5
08-25-2011 01:46 PM
JillianStanford
Frequent Contributor
Hi!
I'm attempting to query a time enabled layer and then set the map.TimeExtent property based on the time extent of the returned graphic. The query is executed correctly but the Graphic.TimeExtent property is always null.

I've confirmed through the REST services directory page that the layer is time enabled and it interacts correctly with the time slider object.

I'm returning all of the fields and the shape.

Maybe this property isn't what I think it is? Maybe I'm missing some property on my query object? Is there another way to get at a feature's time property?

Thanks!!
Jill
0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor
I cannot reproduce the issue in this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#TimeFeatureLayer. If you add a MouseLeftButtonDown event handler, e.Graphic.TimeExtent is not null. I believe the same is true in GraphicsLayer which holds the results of your query since FeatureLayer is essentially GraphicsLayer + QueryTask.
0 Kudos
JillianStanford
Frequent Contributor
Hi Jennifer,
Thanks for getting back to me.

You are correct, the sample works with the layer I'm trying to query. When I look at the attributes by left clicking on a graphic it has a valid timeextent. However, like I said, when I query that same layer for that same record the graphic returned in the featureset has a timeextent of null.

I should have mentioned that the layer in question is an event layer which I assume is what's causing the issue. It displays and interacts with the time slider correctly but I've had trouble accessing it through the query operation.

Xaml:
<esri:FeatureLayer ID="EarthquakesLayer" MouseLeftButtonDown="FeatureLayer_MouseLeftButtonDown"
     Initialized="FeatureLayer_Initialized"
                    Url="http://server/ArcGIS/rest/services/lane_closure_events/MapServer/2"
                    FeatureSymbol="{StaticResource MyMediumMarkerSymbol}"
                    OutFields="*">

C#:
      private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)
     {
            QueryTask queryTask = new QueryTask("http://server/ArcGIS/rest/services/lane_closure_events/MapServer/2");
            queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
            
            Query query = new Query();
            query.ReturnGeometry = true;
            query.OutFields.Add("*");

            query.Where = "OBJECTID = " + e.Graphic.Attributes["OBJECTID"].ToString();

            Debug.WriteLine(query.Where + " Time extent - ");
            Debug.WriteLine(e.Graphic.TimeExtent.ToString());

            queryTask.ExecuteAsync(query);
        }

        private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            FeatureSet featureSet = args.FeatureSet;
            if (featureSet.Features.Count > 0)
            {
                Debug.WriteLine("OBJECTID = " + args.FeatureSet.Features[0].Attributes["OBJECTID"].ToString() + " Time extent - ");
                if (args.FeatureSet.Features[0].TimeExtent == null)
                {                    
                    Debug.WriteLine("No Date");
                }
                else
                {
                    Debug.WriteLine(args.FeatureSet.Features[0].TimeExtent.ToString());
                }
            }
        }

Output:
OBJECTID = 2323 Time extent - 
2011-08-05 07:00:00Z,2011-08-05 19:00:00Z
OBJECTID = 2323 Time extent - 
No Date


(Hope this code is readable 🙂 )
Thanks!
Jill
0 Kudos
JenniferNery
Esri Regular Contributor
Thanks for sharing your code. QueryTask results is expected to have null TimeExtent on the feature. Unlike the FeatureLayer, a QueryTask does not know of the service Time Info. QueryTask only knows about the attribute value for time.
0 Kudos
dotMorten_esri
Esri Notable Contributor
When your QueryTask comes back, you can set the TimeExtent yourself based on whatever attributes you want to define the time extent.
Ie.
foreach(var graphic in queryTaskResult)
     graphic.TimeExtent = new TimeExtent((DateTime)graphic.Attributes["StartTime"],(DateTime)graphic.Attributes["EndTime"]);
0 Kudos
JillianStanford
Frequent Contributor
Morten and Jennifer,
Thank you for you replies.

I was hopeful when you said that a feature layer was "essentially GraphicsLayer + QueryTask". 🙂

Yes, I can grab the info from the attributes but the nice thing about the time enabled layer is that I don't have to keep track of the time fields in the app, at least when I'm using the time slider.

Thanks again!
Jill
0 Kudos