mborr

Selecting Points, displaying Graphics

Discussion created by mborr on Sep 23, 2011
Latest reply on Sep 23, 2011 by mborr
Wondering if someone could help. Hopefully an easy one.

When I use this format:
    
 dojo.connect(map, "onClick", executeQueryTask);

      function executeQueryTask(evt) {
        query.geometry = evt.mapPoint;
        queryTask.execute(query, showResults);
      }

      function showResults(featureSet) {

        dojo.forEach(featureSet.features,function(feature){
          var graphic = feature;
          graphic.setSymbol(symbol);
          map.graphics.add(graphic);
        
        });
      }


to select polygons from:

http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/1

Which is a polygon layer from the census map service, it works fine.

However, if I use layer 0, which is a point layer, it will not run the dojo.foreach() function, and will not place the selection graphic. Here is my new code:

<script type="text/javascript" language="Javascript">
      dojo.require("esri.map");
      dojo.require("esri.tasks.query");
   dojo.require("esri.toolbars.draw");
      dojo.require("dojox.color.Palette");

      var map, querytask, query;
      var selectionSymbol, infoTemplate;

      function init() {
        //create map
        map = new esri.Map("mapDiv");

        //create and add new layer
        var layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
        map.addLayer(layer);
  
  var imageParams = new esri.layers.ImageParameters();
        imageParams.layerIds = [0,1];
        imageParams.layerOption = esri.layers.ImageParameters.LAYER_OPTION_SHOW;
   var dynamicLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer", {imageParameters:imageParams});
        
  var layerDefinitions = [];
  layerDefinitions[0] = "CNTY_FIPS = '081'";

  dynamicLayer.setLayerDefinitions(layerDefinitions);
  map.addLayer(dynamicLayer);

        dojo.connect(map, "onClick", executeQueryTask);

        querytask = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/0");

        query = new esri.tasks.Query();
        query.returnGeometry = true;
  query.outFields = ["POP2000"];
  
  selectionSymbol = new esri.symbol.SimpleMarkerSymbol();
     symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE);
      symbol.setSize(10);
     symbol.setColor(new dojo.Color([255,255,0,0.5]));
  
  
      }

      function executeQueryTask(evt) {
       
     query.geometry = evt.mapPoint;

     querytask.execute(query, showResults);
      }

      function showResults(featureSet) {
        
        map.graphics.clear();
   dojo.forEach(featureSet.features,function(feature){
          var graphic = feature;
    
          graphic.setSymbol(selectionSymbol);

          map.graphics.add(graphic);
       
        });
      }

      dojo.addOnLoad(init);
    </script>


Any thoughts out there?

Outcomes