Select to view content in your preferred language

Adding TimeSlider: "results is not defined"

1278
8
Jump to solution
10-02-2012 07:16 AM
DonRea
by
Occasional Contributor
I am trying to add a TimeSlider to an app that includes a time-aware feature layer. I have carefully read the reference doc (http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp_start.htm#jshelp/inside_temporal.htm) and copied the sample code into my page, as well as looking at some of the working examples. But when the page loads the slider does not initiate, and the js console shows the error "results is not defined". What am I not doing?

You can see the app here: http://www.facstaff.bucknell.edu/rea/map.html
0 Kudos
1 Solution

Accepted Solutions
DonRea
by
Occasional Contributor
0 Kudos
8 Replies
KellyHutchins
Esri Notable Contributor
Don,

In your app you are accessing the variable results before it is defined. In this line you want to get the time info from the layer so perhaps you mean feature1 instead of results[1].layer? Looks like feature1 is the time-aware layer in your app.

var layerTimeExtent = results [1].layer.timeInfo.timeExtent;
0 Kudos
DonRea
by
Occasional Contributor
I'm afraid I have no idea what I want. I just copied the code from the examples...When is 'results' defined? What is it? And how does one find out things like that? My experience with the documentation so far has been pretty frustrating.

In any case, trying to refer to features1.timeExtent results in this message in the js console: "TimeExtent not specified, or in incorrect format." According to the map service:

Time Info:
Start Time Field: PERMITYEAR_TimeSliderDATE
End Time Field: null
Track ID Field: null
Time Extent:
[1999/01/01 00:00:00 UTC, 2010/01/01 00:00:00 UTC]

Time Reference: N/A
Time Interval: 1
Time Interval Units: esriTimeUnitsYears
Has Live Data: false
Export Options:
Use Time: true
Time Data Cumulative: true
Time Offset: null (null)

Is there something wrong here?
0 Kudos
KellyHutchins
Esri Notable Contributor
Try features1.timeInfo.timeExtent.  In your code features1 is a feature layer so you can use the timeInfo property to access details about the layer's time properties. See the feature layer api reference for info:

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/featurelayer.htm

I'd have to know which sample you copied the code from to be sure but I suspect that results is the argument in the onLayersAddResult event handler. If that's the case the results would refer to the layers that were added to the map with the addLayers method.

I'm afraid I have no idea what I want. I just copied the code from the examples...When is 'results' defined? What is it? And how does one find out things like that? My experience with the documentation so far has been pretty frustrating.

In any case, trying to refer to features1.timeExtent results in this message in the js console: "TimeExtent not specified, or in incorrect format." According to the map service:

Time Info:
Start Time Field: PERMITYEAR_TimeSliderDATE
End Time Field: null
Track ID Field: null
Time Extent:
[1999/01/01 00:00:00 UTC, 2010/01/01 00:00:00 UTC]

Time Reference: N/A
Time Interval: 1
Time Interval Units: esriTimeUnitsYears
Has Live Data: false
Export Options:
Use Time: true
Time Data Cumulative: true
Time Offset: null (null)

Is there something wrong here?
0 Kudos
DonRea
by
Occasional Contributor
Now I'm really confused. When I refer to features1.timeInfo.timeExtent, I'm seeing the error "features1.timeInfo is undefined", even though the time info I posted above is copied directly from viewing the service in my browser.
0 Kudos
KellyHutchins
Esri Notable Contributor
Don,

Try using either Firebug or Chrome Developer tools to add a breakpoint at the line in your code where you are trying to get features1.timeInfo. After setting a breakpoint you can inspect features1 and check the value to see if it has a value for the timeInfo property.

Kelly
0 Kudos
DonRea
by
Occasional Contributor
Kelly,

I'm sorry, I wasn't clear. At that point, features1 doesn't even have a timeInfo property. I guess what I'm asking is, why doesn't initializing a featureLayer object with a time-enabled feature layer from the map service include the time information? What else do I not yet know I need to do?
0 Kudos
KellyHutchins
Esri Notable Contributor
Try moving the logic that gets the timeInfo into the initSlider function. It may be that you are trying to access the timeInfo before the layer has loaded:


    function initSlider (results)
    {
 
            var slider = new esri.dijit.TimeSlider ({}, dojo.byId ('sliderDiv'));
            map.setTimeSlider (slider);
        //  var layerTimeExtent = results [1].layer.timeInfo.timeExtent;
            var layerTimeExtent = features1.timeInfo.timeExtent;
            slider.createTimeStopsByTimeInterval (layerTimeExtent, 1, 'esriTimeUnitsYears');
            slider.singleThumbAsTimeInstant (false);
            slider.startup();
        
    }

0 Kudos
DonRea
by
Occasional Contributor
And, thank you!
0 Kudos