3

I want to customize the time slider. Currently I am using "esriTimeUnitsMonths" in which I am getting only months not the year (Please check the imagescreenshot)

I want to put month name +year ex. Jan 09 Feb 09 like that..

I researched on google but I am not able find suitable information. Some one told me that create the array but we can use array on time slider.

Any help will be great..thanks in advance : )

Software : ArcGIS Server 10.1 & ArcGIS Java Script API 3.1

Code: `

var timeExtent = new esri.TimeExtent();
        timeExtent.startTime = new Date("1/1/2009 UTC");
        timeExtent.endTime = new Date("12/31/2011 UTC");
        timeSlider.setLoop(true);
        timeSlider.setThumbCount(2);
        //timeSlider.setTickCount(dojo.date.difference(timeExtent.startTime,timeExtent.endTime,"Months"));
        // original timeSlider.createTimeStopsByTimeInterval(timeExtent,1,'esriTimeUnitsMonths');
        timeSlider.createTimeStopsByTimeInterval(timeExtent,1,'esriTimeUnitsMonths');
        //timeSlider.createTimeStopsByTimeInterval(timeExtent,1,'esriTimeUnitsYears');
        timeSlider.setThumbIndexes([0,1]);
       // timeSlider.timeStops(3);
        timeSlider.setThumbMovingRate(1000);
        timeSlider.startup();`

1 Answer 1

4

Generate your own array of labels, and then specify them on the time slider using TimeSlider.setLabels.

Here's code I put together to do this, use this after you've called timeSlider.startup():

var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
//add labels for every other time stop
var labels = dojo.map(timeSlider.timeStops, function(timeStop,i){ 
  if ( i % 2 ) {
    var m = months[timeStop.getMonth()];
    var y = (timeStop.getFullYear() - 2000);
    var py = (y < 10) ? "0" + y : y;
    var lbl =  m + " " + py;
    console.log("time stop: ", lbl);
    return lbl;
  } else {
    return "";
  }
});     

timeSlider.setLabels(labels);

The code above will label every other tick instead of every tick. Labeling every tick clutters up the bottom of the slider and makes all labels hard to read. This technique is also shown in the Time Slider sample.

2
  • Hello Derek, Thanks for your answer..I will try this and let you know..thanks once again : )
    – Sunil
    Nov 2, 2012 at 19:00
  • Thank you very much...still getting an error but I will find out the..it almost resolved..thanks once again : )
    – Sunil
    Nov 3, 2012 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.