AnsweredAssumed Answered

Simple Query Task Help Needed

Question asked by PW941248 on Jan 24, 2014
Latest reply on Apr 1, 2014 by PW941248
Hi All:

I really must be missing something here because I have yet to get a query task to work properly. I'm very new to both javascript and web app development and so I'm taking baby steps to build the app that my organization has requested. As a first step all I'd like to do is query my layer and return one point of 64 based upon the query. In this case based on the query, the point with the name "Albany" in the CampusName field should return the symbol specified in the query and be different than the other points.

This seems to be a simple task and I'm following the guide here:

https://developers.arcgis.com/javascript/jshelp/intro_querytask.html
and trying to apply it to my data.

Any insight would be much appreciated.

Below is my code;

<!DOCTYPE html>
<html>
<head>
  <title>Create a Map</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  <link rel="stylesheet" href="http://js.arcgis.com/3.8/js/dojo/dijit/themes/claro/claro.css">
  <link rel="stylesheet" href="http://js.arcgis.com/3.8/js/esri/css/esri.css">
  <style>
    html, body, #mapDiv{
      padding: 0;
      margin: 0;
      height: 100%;
    }
  </style>
 
  <script src="http://js.arcgis.com/3.8/"></script>
  <script>
    var map;
    require(["esri/map", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/tasks/QueryTask", "esri/tasks/query", "esri/symbols/SimpleMarkerSymbol", "esri/InfoTemplate", "dojo/_base/Color", "dojo/domReady!"],
   
    function(Map,ArcGISDynamicMapServiceLayer, QueryTask,Query, SimpleMarkerSymbol, InfoTemplate, Color)
    {
      map = new Map("mapDiv",
      {
        center: [-56.049, 38.485],
        zoom: 3,
        basemap: "streets"
       
       
      });
       var SunySchoolsLayer = new ArcGISDynamicMapServiceLayer("http://w7hp348/arcgis/rest/services/Testservice/FeatureServiceTest/MapServer/");
       map.addLayer(SunySchoolsLayer);
      
       queryTask=new QueryTask("http://w7hp348/arcgis/rest/services/Testservice/FeatureServiceTest/MapServer/0");
      
       query = new Query();
       query.returnGeometry = true;
       query.outFields = ["CampusName"];
      
       infoTemplate = new InfoTemplate ("${CampusName}");
      
       symbol=new simpleMarkerSymbol();
       symbol.setStyle(SimpleMarkerSymbol.STYLE_SQUARE);
       symbol.setSize(10);
       symbol.setColor(new Color([255,255,0,0.5]));
      
     
      
       function executeQueryTask()
       {
         query.where = "CampusName = 'Albany' ";
         queryTask.execute(query,showResults);
       }
      
       function showResults(featureSet)
       {
         for(vari=0, i1=resultFeatures.length; i<i1; i++)
         {
           var graphic=resultFeatures[i];
           graphic.setSymbol(symbol);
           graphic.setInfoTEmplate(infoTemplate);
           map.graphics.add(graphic);
         }
       }
    });

Outcomes