robertzsl

How to get the initial datas of the featureLayer after I bind timeSlider to the map?

Discussion created by robertzsl on Oct 29, 2013
Hi everyone!

Like this example:https://developers.arcgis.com/en/javascript/jssamples/time_slider_layerDef.html ,
I have added my featureLayer to my map, and bind the timeSlider with the timeExtent = featureLayer's timeExtent. After that, the points display normally, but i cannot get attribute data of these points.

But, after i click the play button, in the timeSlider's "timeExtentChange" event, I can get the attribute data of the points normally.

My question is that how can i get the attribute data of the points after i bind timeSlider to map and before i click the play button.

This is my code.
function initSlider(results) {
        var timeLayers = dojo.map(results, function (result) {
            return result.layer;
        });
        var timeExtent = new esri.TimeExtent();
        timeExtent = results[0].layer.timeInfo.timeExtent;

        var timeSlider = new esri.dijit.TimeSlider({
            style: "width: 800px;"
        }, dojo.byId("timeSliderDiv"));

        myMap.setTimeSlider(timeSlider);

        timeSlider.setThumbCount(1);
        timeSlider.createTimeStopsByTimeInterval(timeExtent, 1, 'esriTimeUnitsHours');
        timeSlider.singleThumbAsTimeInstant(true);
        timeSlider.setThumbIndexes([0]);
        timeSlider.setThumbMovingRate(1000);
        timeSlider.setLoop(true);
        timeSlider.startup();


        //add labels for every other time stop
        var labels = dojo.map(timeSlider.timeStops, function (timeStop, i) {
            return timeStop.getHours();
        });
        timeSlider.setLabels(labels);


        //search the initial datas
        var timeQuery = new esri.tasks.Query();
        var timeE = new esri.TimeExtent();
        timeE = myMap.timeExtent;

        timeQuery.timeExtent = timeE;
        
        dojo.forEach(timeLayers, function (layer) {
            var mappedField = layer.renderer.attributeField;
            
            layer.queryFeatures(timeQuery, function (featureSet) {
                var timeDatas = dojo.map(featureSet.features, function (feature) {
                    return [feature.attributes["RG_id"], Number(feature.attributes[mappedField])]; 
                }); 
            });
        });

        //search datas in the timeSlider's event.
        dojo.connect(timeSlider, "onTimeExtentChange", function (timeExtent) {
            timeQuery.timeExtent = timeExtent;
            var yearlyLayerProduction = '';

            dojo.forEach(timeLayers, function (layer) {
                var mappedField = layer.renderer.attributeField;
                layer.queryFeatures(timeQuery, function (featureSet) {
                    var chartDatas = dojo.map(featureSet.features, function (feature) {
                        return [feature.attributes["RG_id"], Number(feature.attributes[mappedField])]; 
                    });
                });
            });
        });
    }



I also found this example seemed resolved this problem, but i haven't find the different of the these two examples.
https://developers.arcgis.com/en/javascript/jssamples/time_streetTrees.html

This problem has troubled me for a long time. Can anyone help me? Any help will be appreciated.

Thank you
Shengli Zhao

Outcomes