AnsweredAssumed Answered


Question asked by ho0mwp on Jun 16, 2014
Latest reply on Jun 17, 2014 by ho0mwp
I am trying to clear out graphics on a graphicsLayer so that I can get a new selection.  Everything works with my Query task but I can't seem to clear out the old results.  All I end up doing is adding to the new results.  I've tried a lot of different stuff but it is not working.  How can I do this?  I thought a graphics layer would allow me to do this and seems to be my best choice since I have a couple of other layers I want to be able to filter as well as different results.

I tried up at the top putting the code up top where I add in some ArcGISDynamicMapServiceLayers but in my function it does not recognize my add layer and just bombs out.  Works in my function though.  However, I have a feeling it is creating multiple instances of otherRetailers.

//Where should I put this in my code. 
otherRetailerLayer = new esri.layers.GraphicsLayer(); = 'otherRetailers';   

//Why does this not clear out my layer?;

 function showCEResults(featureSet) {       //  Clear Datagrid          //create an empty store and then bind to grid var emptyCells = { items: "" }; var emptyStore = new{data: emptyCells});    grid = dijit.byId('gridCE');       grid.setStore(emptyStore); //alert ("Found InfoTemplate"); //Popup window settings  var content = "<b>FID</b>: ${FID}"  +               "<br><b>MALLID</b>: ${MALLID}" +        "<br><b>Mall Grade</b>: ${MALL_GRADE}" +      "<br><b>District</b>: ${DISTRICT}" +      "<br><b>MALL NAME</b>: ${MALLNAME}";                     var infoTemplate = new esri.InfoTemplate("${DIVISIONNA}", content);   var symbol = new esri.symbol.SimpleMarkerSymbol({   "color": [120,120,120,255],   "size": 8,   "type": "esriSMS",   "style": "esriSMSSquare",   "outline": {     "color": [0,0,0,255],     "width": 2,     "type": "esriSLS",     "style": "esriSLSSolid"  }});   var symbolRedShinyPin = new esri.symbol.PictureMarkerSymbol({  "angle": 0, "xoffset": 0, "yoffset": 12, "type": "esriPMS",  "url": "",  "contentType": "image/png", "width": 18, "height": 18  });  var symbolShinyPin = new esri.symbol.PictureMarkerSymbol({  "angle": 0, "xoffset": 0, "yoffset": 12, "type": "esriPMS",  "url": "",  "contentType": "image/png", "width": 18, "height": 18  });      //alert ("Found DataGrid and Graphics");    var dataForGrid = [];  var temp = "";  var varRetailer = "";       //remove all graphics on the maps graphics layer                otherRetailerLayer = new esri.layers.GraphicsLayer(); = 'otherRetailers';         map.addLayer(otherRetailerLayer);       //;              //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];            varRetailer = resultFeatures[i].attributes.RETAILERID;         if (varRetailer == "3000"){      resultFeatures[i].setSymbol(symbolRedShinyPin );       }           else {      resultFeatures[i].setSymbol(symbolShinyPin);          }       resultFeatures[i].setInfoTemplate(infoTemplate);   otherRetailerLayer.add(resultFeatures[i]);              //Put values in array for datagrid      var attValues = resultFeatures[i].attributes;                      dataForGrid.push(attValues);       };  //var grid = registry.byId("gridCE");        var data = {   identifier : "FID",   label : "FID",         items : dataForGrid         };      var store = new{data: data});  grid.setSortIndex(2,"true"); //sort on the state name      grid.setStore(store);   grid.on("rowclick", onRowClickHandler);        //;    }