Select to view content in your preferred language

TimeExtent and Query issue

1683
8
10-24-2011 08:46 AM
deleted-user-VeZur_n9o0OZ
Deactivated User
Hello experts,

I'm using firebug to step through my app. I am using a single time slider (with only one thumb) to query two feature layers loaded into seperate maps. I've followed the samples but my code seems to die on the first line in my connector method; query = new esri.tasks.Query();

query is a public variable and I have included the necessary dojo.require for the query task. I can't catch the error with a try catch either. Anyone know what's going on?

Code below.
Thanks,
James

try {
      //Connect time slider events
      dojo.connect(timeSlider, "onTimeExtentChange", function(timeExtent) {
       query = new esri.tasks.Query();
       query.timeExtent = timeExtent;

       flITIS.queryFeatures(query, function(featureSet) {
        //empty function for now
       });
       flLCAP.queryFeatures(query, function(featureSet) {
        //empty function for now
       });
      });
     } catch(err) {
      alert("Error: " + err.message + ", Line #" + err.lineNumber);
     }
0 Kudos
8 Replies
KellyHutchins
Esri Notable Contributor
Is query in lower case in your dojo.require statement, for example:

  
   dojo.require("esri.tasks.query");


Also have you checked either Firebug or Chrome Developer Tools to see if there are any error messages?
0 Kudos
deleted-user-VeZur_n9o0OZ
Deactivated User
Hi Kelly,

thanks for your comments. My requires statement is correct. I don't think it's an issue with the Query. I have now declared a seperate function to listen to my onTimeExtentChange. It seems that the debugger in firebug will stop at my breakpoint on the first executable line of code. After that, it will not stop at any other breakpoints, but WILL execute the code. In the snippet below I will always see the alert about my start and end times of my query. Ever seen that before? I haven't used Chrome but will do so this afternoon.

//Connect time slider events
     dojo.connect(timeSlider, "onTimeExtentChange", extentChanged(timeExtent));

    } catch(err) {
     alert("Error: " + err.message + ", Line #" + err.lineNumber);
    }
   };

   function extentChanged(timeExtent) {
    try {
     var queryITIS = new esri.tasks.Query();
     var queryLCAP = new esri.tasks.Query();
     
     queryITIS.timeExtent = timeExtent;
     queryLCAP.timeExtent = timeExtent;
     
     flITIS.queryFeatures(queryITIS, function(featureSet) {
      //empty function for now
     });
     flLCAP.queryFeatures(queryLCAP, function(featureSet) {
      //empty function for now
     });
     alert("Start time: " + queryITIS.timeExtent.startTime.toLocaleTimeString() + ", End time: " + queryITIS.timeExtent.endTime.toLocaleTimeString());
    } catch(err) {
     alert("Error: " + err.message + ", Line #" + err.lineNumber);
    }
   }




On a seperate note, I am seeing an error in my console. The error is thrown when I click 'Next' on my time slider. It is as follows:
lls is null.

Does this mean anything to you? I would expect clicking next to trigger my extentChanged function
0 Kudos
deleted-user-VeZur_n9o0OZ
Deactivated User
Update: Chrome error console now tells me:

Uncaught Could not load cross-domain resources: dojox.gfx.svg esri.nls.jsapi_en-gb dijit.layout.BorderContainer dijit.layout.ContentPane dijit.Toolbar esri.layers.FeatureLayer esri.dijit.Legend esri.dijit.Popup esri.dijit.TimeSlider
0 Kudos
deleted-user-VeZur_n9o0OZ
Deactivated User
Ok people - this is really baffling me. My code is now practically identical to the official sample here:
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm

on the line timeSlider.startup() the following error is thrown:
"Cannot call method 'apply' of null"

I've sunk a few hours into this time slider now and really need it working...any input appreciated.

Thanks,
James



     //Timeslider stuff
     var timeExtent = new esri.TimeExtent();
     timeExtent.startTime = new Date("9/1/2011 15:00:00 UTC");
     timeExtent.endTime = new Date("9/1/2011 23:00:00 UTC");

     //create the div
     var tsDiv = dojo.create("div", null, dojo.byId('timeSliderDiv'));
     var timeSlider = new esri.dijit.TimeSlider({
      style : "width: 90%;",
      id : 'timeSlider',
      options : {
       excludeDataAtLeadingThumb : true
      }
     }, tsDiv);

     //Connect time slider events
     dojo.connect(timeSlider, "onTimeExtentChange", extentChanged(timeExtent));
     //dojo.connect(timeSlider, "onTimeExtentChange", function(timeExtent){

     //set map timesliders
     mapITIS.setTimeSlider(timeSlider);
     //mapLCAP.setTimeSlider(timeSlider);

     timeSlider.setThumbCount(2);

     timeSlider.createTimeStopsByTimeInterval(timeExtent, 5, 'esriTimeUnitsMinutes', {
      resetStartTime : true
     });

     //a tick for each 30mins
     //timeSlider.setTickCount(17);

     //timeSlider.singleThumbAsTimeInstant(true);
     timeSlider.setThumbIndexes([0, 1]);
     timeSlider.setThumbMovingRate(500);
     timeSlider.setLoop(true);
     timeSlider.startup();

     var labels = ['16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00', '00:00'];
     timeSlider.setLabels(labels);
0 Kudos
KellyHutchins
Esri Notable Contributor
Its hard to know what's happening without seeing more code. Is your service public? If so can you create a test case that shows the problem?
0 Kudos
deleted-user-VeZur_n9o0OZ
Deactivated User
Morning Kelly.

Oddly, I have now worked around the error messages i was seeing with the following code. I went back to using an anonymous function for my timeslider connection. Also, I declared a seperate function for my timeslider initialisation after my feature layers are finished loading. Thanks for the continued support Kelly...


Time extent setup and connector:

//Timeslider stuff
     var timeExtent = new esri.TimeExtent();
     timeExtent.startTime = new Date("9/1/2011 15:00:00 UTC");
     timeExtent.endTime = new Date("9/1/2011 23:00:00 UTC");

     flITIS.setTimeDefinition(timeExtent);
     flLCAP.setTimeDefinition(timeExtent);

     //create the div
     var tsDiv = dojo.create("div", null, dojo.byId('timeSliderDiv'));
     timeSlider = new esri.dijit.TimeSlider({
      style : "width: 90%;",
      id : 'timeSlider',
      options : {
       excludeDataAtTrailingThumb : true
      }
     }, tsDiv);

     //Connect time slider events
     //dojo.connect(timeSlider, "onTimeExtentChange", extentChanged(timeExtent));
     dojo.connect(timeSlider, "onTimeExtentChange", function(timeExtent) {
      try {
       var queryITIS = new esri.tasks.Query();
       var queryLCAP = new esri.tasks.Query();

       queryITIS.timeExtent = timeExtent;
       queryLCAP.timeExtent = timeExtent;

       //update label for slider
       updateTimeString(timeExtent);

       flITIS.queryFeatures(queryITIS, function(featureSet) {
        //empty function for now
       });
       flLCAP.queryFeatures(queryLCAP, function(featureSet) {
        //empty function for now
       });
       //alert("Start time: " + queryITIS.timeExtent.startTime.toLocaleTimeString() + ", End time: " + queryITIS.timeExtent.endTime.toLocaleTimeString());
      } catch(err) {
       alert("Error: " + err.message + ", Line #" + err.lineNumber);
      }
     })




Time slider setup:

//when the LCAP fl is loaded, initiate the slider
dojo.connect(flLCAP, "onUpdateEnd", timeSliderInit(timeExtent));


function timeSliderInit(timeExtent) {
    timeSlider.setThumbCount(2);

    timeSlider.createTimeStopsByTimeInterval(timeExtent, 5, 'esriTimeUnitsMinutes', {
     resetStartTime : true
    });

    //a tick for each 30mins
    timeSlider.setTickCount(17);

    //timeSlider.singleThumbAsTimeInstant(true);
    timeSlider.setThumbIndexes([0, 1]);
    timeSlider.setThumbMovingRate(1500);
    timeSlider.setLoop(true);
    timeSlider.startup();

    var labels = ['16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00', '00:00'];
    timeSlider.setLabels(labels);
   }
0 Kudos
DavidHollema
Deactivated User
If you're still having trouble with this and post all your code, I will take a look.  I'm curious why your named function for the timeslider event was problematic.
0 Kudos
Salomon_VágadalJoensen
Deactivated User
The query task is case sensitive. Thought I would want to throw it out there.
0 Kudos