AnsweredAssumed Answered

FeatureLayer issue

Question asked by samirgambhir on Apr 9, 2012
Latest reply on Apr 9, 2012 by samirgambhir
Hi all,
I am using ArcGIS Server 10.0 with JavaScript API. I need to create a legend from the graphics that are displayed on the map. This forum as well as ESRI's web-help suggests that I use FeatureLayer instead of GraphicsLayer that I am currently using. I am tyring to follow steps as outlined in http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/fl_selectfeatures.html. However, I am a bit confused on how to run query on the FeatureLayer. Unlike GraphicsLayer where we use a queryTask, FeatureLayer uses "selectFeatures". Can someone point me to the right resource? Here is my code so far and I am not sure how to set it right for my needs:

function init() {
....
stateFeatureLayer = new esri.layers.FeatureLayer("http://nsmhpc7007:8399/arcgis/rest/services/Data_by_State/MapServer/1",{mode: esri.layers.FeatureLayer.MODE_ONDEMAND,outFields: ["*"]});
....
}

function viewIndicator() {
        clearElements();
        returnRadioID();
        query = new esri.tasks.Query();
        query.geometry = feature.geometry;
        stateFeatureLayer.selectFeatures(query, esri.Layers.FeatureLayer.SELECTION_NEW);
        query.outFields = ["*"];
       
var symbol =new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([110,110,110,0.4]),2), new dojo.Color([125,125,125,0.4]));
          var symbolSet1 =new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([110,110,110,0.4]),2), new dojo.Color([255,255,128,0.4]));
          var symbolSet2 =new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([110,110,110,0.4]),2), new dojo.Color([242,167,46,0.4]));
          var symbolSet3 =new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([110,110,110,0.4]),2), new dojo.Color([107,0,0,0.4]));
                   
          switch (selRadio)
          {
            case "checkCBR":
            
               if (unitStActiveM==true){
                 var renderer = new esri.renderer.ClassBreaksRenderer(symbol, "CBR_01");
               }
               else if (unitDistActiveM==true) {
                 var renderer = new esri.renderer.ClassBreaksRenderer(symbol, "CBR_11");
               }
               renderer.addBreak(-Infinity, 11, symbolSet1);
               renderer.addBreak(12,20,symbolSet2);
               renderer.addBreak(21,Infinity,symbolSet3);
              
               stateFeatureLayer.setRenderer(renderer);
              
               break;
            case "checkTest1":
          
               if (unitStActiveM==true){
                 var renderer = new esri.renderer.ClassBreaksRenderer(symbol, "MMR_01");
               }
               else if (unitDistActiveM==true) {
                 var renderer = new esri.renderer.ClassBreaksRenderer(symbol, "MMR_11");
               }
               renderer.addBreak(-Infinity, 134, symbolSet1);
               renderer.addBreak(134,260,symbolSet2);
               renderer.addBreak(260,Infinity,symbolSet3);
               //alert ("indicator = "+indicator);
               stateFeatureLayer.setRenderer(renderer);
              
               break;
          }
           
            dojo.forEach(features, function(feature) {
                       for (i=0, il=featureSet.features.length; i<il; i++) {
              var graphic = featureSet.features[i];
              stateFeatureLayer.add(graphic); 
              items.push(graphic.attributes);
            }
            mapM.addLayer(stateFeatureLayer);
            stateFeatureLayer.show();
});
...
}


Thanks
Samir

Outcomes