Select to view content in your preferred language

Time extent data not displayed for single day

1252
5
04-23-2010 09:35 AM
RaviKonaparthi
Deactivated User
Hi,

I am working on application which requires TimeExtent feature. I created a timeextent and a timeslider and for the timeslider i created timestops as type esritimeunitsdays. The problem is when the right and left thumb of the timeslider are same i.e. records of a single day the map doesn't show the features on the map. This is because my startTime and endTime are same so the map is not getting the data for the day. Is there any workaround for this issue.

I am adding the code of the same:

var timeExtent = new esri.TimeExtent();
    var todayDate = new Date();
    timeExtent.startTime = new Date((todayDate.getMonth() + 2) + "/" + 1 + "/" + (todayDate.getFullYear() - 1) + " UTC");
    timeExtent.endTime = new Date((todayDate.getMonth() + 1) + "/" + GetLastDay() + "/" + todayDate.getFullYear() + " UTC");
    featureLayer.setTimeDefinition(timeExtent);

var timeSlider = new esri.dijit.TimeSlider({}, dojo.byId("monthslider"));
    map.setTimeSlider(timeSlider);
    timeSlider.setThumbCount(2);
    timeSlider.createTimeStopsByTimeInterval(timeExtent, 1, 'esriTimeUnitsDays');
    timeSlider.setThumbIndexes([300, 365]);
    timeSlider.startup();

Regards,
Ravi.
0 Kudos
5 Replies
KellyHutchins
Esri Frequent Contributor
I setup a quick test using the code below and cannot reproduce the problem. In this test case if you run the application then move both sliders to the same position and start playing you'll see that data displays on the map. It looks like you have an extra space in the following line, perhaps this is the issue or maybe it was an error when copying the code?
timeSlider.createTimeStopsByTimeInterval(timeExten t, 1, 'esriTimeUnitsDays');

Here's my test case:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <meta http-equiv="X-UA-Compatible" content="IE=7" />
    <title>H1N1 Flu Outbreak</title>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.0/js/dojo/dijit/themes/tundra/tundra.css">
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0"></script>

    <script type="text/javascript" language="Javascript">
      dojo.require("esri.map");
        dojo.require("esri.tasks.query");
        dojo.require("esri.layers.FeatureLayer");
        dojo.require("esri.dijit.TimeSlider")
        var timeSlider,map;
        var opLayer;

      function init() {
       map = new esri.Map("map");
       var layers = [];
       var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer");
       layers.push(basemap);

       opLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://servicesbeta.esri.com/ArcGIS/rest/services/Health/h1n1/MapServer");
       layers.push(opLayer);
       //add all the layers to the map then initialize the slider
       map.addLayers(layers);
       dojo.connect(map,"onLayersAddResult",function(results){
         timeSlider = new esri.dijit.TimeSlider({},dojo.byId("timeSliderDiv"));
         map.setTimeSlider(timeSlider);
         timeSlider.setThumbCount(2);
        //get the time extent from the H1N1 layer and use that to define the time stops
        timeSlider.createTimeStopsByTimeInterval(results[1].layer.timeInfo.timeExtent,1,'esriTimeUnitsDays');
        dojo.connect(timeSlider,"onTimeExtentChange",extentChanged);
        timeSlider.startup();
       });
      }
      function extentChanged(timeExtent){
       //format the dates
       console.log(timeExtent.startTime.toUTCString());
       console.log(timeExtent.endTime.toUTCString());
       var startVal = timeExtent.startTime.getMonth() + 1 + "/" +  timeExtent.startTime.getDate() + "/" + timeExtent.startTime.getFullYear();
       var endVal = timeExtent.endTime.getMonth() + 1 + "/" + + timeExtent.endTime.getDate() + "/" +  timeExtent.endTime.getFullYear();
       dojo.byId("timeVal").innerHTML = "<b>H1N1 Flu Outbreak data from " + startVal + " TO " + endVal  + "<\/b>";
      }
      dojo.addOnLoad(init);
    </script>
 </head>
  <body class="tundra">
    <div id="timeVal"></div>
    <div id="map" style="width:900px; height:600px; border:1px solid #000;"></div>
    <div id="timeSliderDiv"></div>
  </body>
</html>
0 Kudos
RaviKonaparthi
Deactivated User
Hi Kelly,

Thanks for the reply. The sample you posted uses a ArcGISDynamicMapServiceLayer while we are working with a FeatureLayer from a featureservice. It works fine if we use ArcGISDynamicMapServiceLayer, but strange enough it doesnt work for a featurelayer!

The extra space was a typo and its not there in my code.

am I missing something?

regards
Ravi
0 Kudos
KellyHutchins
Esri Frequent Contributor
Ravi,

I switched my test case to use a feature layer instead, mine is a feature layer pointing to a map service and the test case still works. This service is public if you'd like to test:
opLayer = new esri.layers.FeatureLayer("http://servicesbeta.esri.com/ArcGIS/rest/services/Health/h1n1/MapServer/0",{
          mode: esri.layers.FeatureLayer.MODE_SNAPSHOT
});


Which mode are you specifying for your feature layer? We recommend using MODE_SNAPSHOT if you aren't using a large amount of data. If you have a large amount of data you may want to use an ArcGISDynamicMapServiceLayer instead.  ONDEMAND_MODE is not recommended because it can result in too many requests to the server.
0 Kudos
RaviKonaparthi
Deactivated User
Kelly,

It works fine if I use a featurelayer with my mapservice. however, it doesnt work when I instantiate a featurelayer from the same featureservice. I need to perform edits on this layer and hence have to use featureservice.

Another point I have noticed in all jsapi samples is that featurelayers are created from a mapservice (except for editing samples). Is this due to any limitation of any kind or just a recommended practice?

regards
Ravi
0 Kudos
Town_ofSnowflake
Deactivated User
I'm experiencing this same problem.  When I have a two thumb slider, and both are sitting on the same year, no data appears on my map.  Has this issue been resolved?
0 Kudos