EncinitasGIS

Query breaks after v 3.2

Discussion created by EncinitasGIS on Jun 12, 2013
I have a simple app.  It has a find tool and address tool and 4 different query tools.  They basically all work the same.  I've never migrated my code past 3.2 because my 4 query tools no long work.  I've spent hours/days looking at this and now I'm just lost.  Here's the basics.

Heads up I can always post more code or send it if someone wants to take a look and help.  Also if I send my query to my function to show the results for my find tool it doesn't work but it works for the find tool.



My html
Code for layout.js

    //**************************1st QUERY TASK ***************************************////
   // build query
        queryTask = new esri.tasks.QueryTask("https://myserver/pubgis/rest/services/layer1/MapServer/0");
        //dojo.connect(queryTask, "onComplete", showResults);

        //build query filter
        query = new esri.tasks.Query();
        query.returnGeometry = true;
        query.outFields = ["*"];
        query.SpatialReference = map.spatialReference;
        query.outSpatialReference = map.spatialReference;         
    //************************** END 1st                  
    //**************************2nd QUERY TASK ***************************************////
   // build query
        queryTaskSupport = new esri.tasks.QueryTask("https://myserver/pubgis/rest/services/layer2/MapServer/1");
       
        //build query filter
        querySupport = new esri.tasks.Query();
        querySupport.returnGeometry = true;
        querySupport.outFields = ["*"];
        querySupport.inSpatialReference = map.spatialReference;
        querySupport.outSpatialReference = map.spatialReference;
           
    //************************** END 2nd QUERY TASK ***************************************////   


my Query JS file


var grid;
var txtType = "SIGNTYPE = ";  //String for Type Search
var txtDate = "DATEINST = TO_DATE(";  //String for Type Search
var txtFacId = "FACILITYID = ";  //String for Type Search
var queryTask; //Query Task
var query;  //Query Task
var tex;


  //(****************************TEST 
   
   
   
 function doSignTypeQuery() {

     tex = ((txtType + "\'" + dojo.byId("SignQuery").value + "\'").toString());
  
  dojo.connect(dijit.byId("STQ"),"onClick", function(){
 
          window.alert(tex);
        });


    // queryTask = new esri.tasks.QueryTask("https://gisapps.escondido.org/pubgis/rest/services/Signs/Signs2/FeatureServer/0");
  query = new esri.tasks.Query();
     query.where = (txtType + "\'" + dojo.byId("SignQuery").value + "\'").toString();
  
        // //execute query
     queryTask.execute(query,showFResults);
   }
   
  function doDateQuery() {
         query = new esri.tasks.Query();
      query.where = (txtDate + "\'" + dojo.byId("DateQuery").value + " 00:00:00\',\'YYYY-MM-DD HH24:MI:SS\')").toString();
        //execute query
        queryTask.execute(query,showQResults);
  }
      
  function doFacIdQuery() {
        query = new esri.tasks.Query();
     query.where = (txtFacId + "\'" + dojo.byId("FacIdQuery").value + "\'").toString();
        //execute query
        queryTask.execute(query,showFResults);
  }
      
      
   
      
      
      function showFResults(results) {
   
   window.alert("Im ready to work");
   
   //remove all graphics on the maps graphics layer
    map.graphics.clear();

    //Performance enhancer - assign featureSet array to a single variable.
    var resultFeatures = featureSet.features;

    //Loop through each feature returned
    for (var i=0, il=resultFeatures.length; i<il; i++) {
      //Get the current feature from the featureSet.
      //Feature is a graphic
      var graphic = resultFeatures[i];
      graphic.setSymbol(symbol);

      //Set the infoTemplate.
      graphic.setInfoTemplate(infoTemplate);

      //Add graphic to the map graphics layer.
      map.graphics.add(graphic);
    }
 window.alert("Im done working");
   
   
       
   //remove all graphics on the maps graphics layer
    map.graphics.clear();
    esri.hide(dojo.byId("gridsup"));
    esri.show(dojo.byId("grid"));
     
        var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([98,194,204]), 2), new dojo.Color([98,194,204,0.5]));
        var markerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 20, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 255]), 1), new dojo.Color([0, 255, 0, 0.25]));
        var lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255, 0, 0]), 1);
  
  
   window.alert("Im ready to work");
   
   //remove all graphics on the maps graphics layer
    map.graphics.clear();
window.alert("Im thinking about doing something");
    //Performance enhancer - assign featureSet array to a single variable.
    var resultFeatures = featureSet.features;
 
    //Loop through each feature returned
    for (var i=0, il=resultFeatures.length; i<il; i++) {
      //Get the current feature from the featureSet.
      //Feature is a graphic
      var graphic = resultFeatures[i];
      graphic.setSymbol(markerSymbol);
 window.alert("Im thinking....");


      //Set the infoTemplate.
      graphic.setInfoTemplate(infoTemplate);

      //Add graphic to the map graphics layer.
      map.graphics.add(graphic);
    }
 window.alert("Im done working");
   
//DURING THE FOLLOWING LOOP IT JUST STOPS - Never reaches the switch or dies inside it   

     
     //create array of attributes
        var items = dojo.map(results,function(result){
          var graphic = result.feature;
          switch (graphic.geometry.type) {
          case "point":
            graphic.setSymbol(markerSymbol);
            break;
          case "polyline":
            graphic.setSymbol(lineSymbol);
            break;
          case "polygon":
            graphic.setSymbol(polygonSymbol);
            break;
          }
          
          // //Set the infoTemplate.
        //   graphic.setInfoTemplate(SignInfoTemplate);
           
          map.graphics.add(graphic);
          return result.feature.attributes;
        });

 
 
       //Create data object to be used in store
        var data = {
          identifier: "OBJECTID",  //This field needs to have unique values
          label: "OBJECTID", //Name field for display. Not pertinent to a grid but may be used elsewhere.
          items: items
        };

 
         //Create data store and bind to grid.
        store = new dojo.data.ItemFileReadStore({ data:data });
        grid = dijit.byId('grid');
        grid.setStore(store);
  

    
        //+++++++++++++++++++++++++ Zoom back to extent of graphics selected ++++++++++++++++++++++++++++++++++
        
        //Check to see if there is only one graphic 
  
         for (var i=0, il=results.features.length; i<il; i++) {
          dojo.forEach(map.graphics.graphics,function(graphic){
            g = graphic; 
   
            return;    
          });
         }
         
         //if only one graphic and graphic is a point then go to the extent of that graphic 
        if (g.geometry.type === "point" &&  i===1)
        {
        var pExtent = new esri.geometry.Extent({"xmin":g.geometry.x - 500,"ymin":g.geometry.y - 500,"xmax":g.geometry.x + 500,"ymax":g.geometry.y + 500,"spatialReference":{"wkid":g.geometry.spatialReference.wkid}});
      map.setExtent(pExtent);
    }
    else  //go to the extent of all the graphics
    {
         var graphicExtent = esri.graphicsExtent(map.graphics.graphics);
       map.setExtent(graphicExtent);
      };
     
  
     //***************END Zoom back to extent of graphics selected ++++++++++++++++++++++++//////////
    
      }
   
   


alternative code - it never reaches the 2nd alert ("Im thinking about doing something") or gets to the loop
 window.alert("Im ready to work");
   
   //remove all graphics on the maps graphics layer
    map.graphics.clear();
window.alert("Im thinking about doing something");
    //Performance enhancer - assign featureSet array to a single variable.
    var resultFeatures = featureSet.features;
 
    //Loop through each feature returned
    for (var i=0, il=resultFeatures.length; i<il; i++) {
      //Get the current feature from the featureSet.
      //Feature is a graphic
      var graphic = resultFeatures[i];
      graphic.setSymbol(markerSymbol);
 window.alert("Im thinking....");


      //Set the infoTemplate.
      graphic.setInfoTemplate(infoTemplate);

      //Add graphic to the map graphics layer.
      map.graphics.add(graphic);
    }


ALT NUMBER 2  -- Never gets inside an if / elseif

 var items = []; 
 dojo.forEach(results.features, function (feature) {
                    var graphic = feature;
                   var type = feature.geometry.type;
  if (type == 'point') {
   graphic.setSymbol(markerSymbol);
               } else if (type == 'polyline') {
   graphic.setSymbol(lineSymbol);
  } else if (type == 'polygon') {
   graphic.setSymbol(polygonSymbol);
   }
    
 //Add graphic to map    
                    map.graphics.add(graphic);
                   // return feature.attributes;
                    items.push(feature.attributes);

Outcomes