AnsweredAssumed Answered

Unique Value Renderer and the TOC

Question asked by dcoley on Sep 23, 2014
Latest reply on Sep 24, 2014 by dcoley

Hi all-

So I'm trying to render groups of values based on the blog at:

Data Visualization with ArcGIS API for JavaScript: Show Data by Unique Value | ArcGIS Blog

The problem is that while the renderer portion works great, I can't seem to get around the fact that the TOC wants to list the "if else if" statement text within Nianwei Liu's table of contents.  Here is some code of what I've done so far, I just can't seem to around the fact that the TOC wants to list the attribute field values on which I am rendering, but is listing the function text instead:

 

var defSym = new SimpleFillSymbol().setStyle(SimpleFillSymbol.STYLE_SOLID); 
  defSym.outline.setStyle(SimpleLineSymbol.STYLE_SOLID);

var cszRenderer = new UniqueValueRenderer(defSym, function(graphic) {
if (graphic.attributes['CODE'].indexOf("DTB") !== -1 || graphic.attributes['CODE'].indexOf("DTC") !== -1 || 
          graphic.attributes['CODE'].indexOf("DTE") !== -1 || graphic.attributes['CODE'].indexOf("DTN") !== -1){
          return "Downtown Overlays";
} else if (graphic.attributes['CODE'].indexOf("G") !== -1 || graphic.attributes['CODE'].indexOf("GU") !== -1){
          return "Government Use";
} else {
         return "Other Uses";   
         };
  });
var dtSym = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color("#808000"), 2),new Color("#FF8C00"));
        cszRenderer.addValue("Downtown Overlays", dtSym);
  var gSym = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color("#808080"), 2),new Color("#A4F9FE"));
        cszRenderer.addValue("Government Use", gSym);

lyrCsZoning.setRenderer(cszRenderer);

 

Result:

tocCapture.PNG

Any help is appreciated.  If I can just somehow reverse how the renderer is set up so I can return the attribute and not the function.  Some sort of nested function I think would work but I just can't see it--

 

Thanks-

David

Outcomes