AnsweredAssumed Answered

setRenderer error getFieldsUsedInExpressions is not a function

Question asked by abhinavsharma1 on Jan 29, 2018
Latest reply on Feb 2, 2018 by rscheitlin

Hey everyone, I am attempting to create a renderer where the user is able to select the field on which to render based off of. I need to use UniqueValueDefinition as my render which means that I cannot use RendererChooser class—Web AppBuilder for ArcGIS (Developer Edition) | ArcGIS for Developers. After selecting the field the chrome console shoots back the following error

Uncaught TypeError: a.getFieldsUsedInExpressions is not a function

My feature layer is created like so:

var landusePolygonLayer = new FeatureLayer("https://services7.arcgis.com"),
            id: "canada_Risk",//confirm works
            mode: FeatureLayer.MODE_ONDEMAND,

            outFields: ["*"]
          });

I then call getData() after the user chooses the field ( which sets currField to that field which is used in the code below.

function getData(){
            classBreaks("#ffffcc", "#006837");
          }


          function classBreaks(c1, c2) {
            var classDef = new UniqueValueDefinition();

            //define ColorRamp
            var colorRamp = new AlgorithmicColorRamp();
            colorRamp.fromColor = new Color.fromHex(c1);
            colorRamp.toColor = new Color.fromHex(c2);
            colorRamp.algorithm = "hsv"; // options are:  "cie-lab", "hsv", "lab-lch"
            //var classField = this.get("value")
            console.log("This.get(value)", currField);//confirm the field is correct in console
            classDef.attributeField= currField;//set def field to the user selected field
            classDef.type = "classBreaksDef";


            classDef.baseSymbol = new SimpleFillSymbol("solid", null, null);
            classDef.ColorRamp = colorRamp;

            //var params = new GenerateRendererParameters();
            //params.classificationDefinition = classDef;
            console.log("here")
            this.map.getLayer("canada_Risk").setRenderer(classDef);
            console.log("here2")
var currField
define(
  ['dojo/_base/declare',
  "dijit/_WidgetsInTemplateMixin",
  'jimu/BaseWidget',
  "esri/toolbars/draw",
  "esri/toolbars/edit",
  "esri/graphic",
  "esri/request",
  "esri/config",
  "esri/Color",
  "esri/renderers/Renderer",
  "esri/tasks/ClassBreaksDefinition",
  "esri/tasks/UniqueValueDefinition",
  "esri/tasks/ColorRamp",
  "esri/tasks/AlgorithmicColorRamp",
  "esri/tasks/GenerateRendererParameters",
  "esri/tasks/GenerateRendererTask",
  "esri/layers/LayerDrawingOptions",
  "esri/layers/FeatureLayer",
  "esri/layers/Field",
  "esri/symbols/SimpleMarkerSymbol",
  "esri/symbols/SimpleLineSymbol",
  "esri/symbols/SimpleFillSymbol",
  "esri/dijit/editing/TemplatePicker",
  "esri/dijit/editing/Editor",
  "dojo/_base/array",
  "dojo/_base/event",
  "dojo/_base/lang",
  "dojo/parser",
  "dijit/registry",
  "dojo/data/ItemFileReadStore",
  "dojox/grid/DataGrid",
  "dijit/form/FilteringSelect",
  "dijit/form/Select",
  "dojo/on",
  "dojo/data/ObjectStore",
  "dojo/store/Memory",
  "dojo/domReady!"],
  function(declare,_WidgetsInTemplateMixin, BaseWidget, Draw, Edit, Graphic, esriRequest, esriConfig, Color,Renderer,
    ClassBreaksDefinition, UniqueValueDefinition, ColorRamp, AlgorithmicColorRamp,
    GenerateRendererParameters, GenerateRendererTask, LayerDrawingOptions,
    FeatureLayer,Field,
    SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol,
    TemplatePicker,Editor,
    arrayUtils, event, lang, parser, registry, ItemFileReadStore, DataGrid, FilteringSelect,Select, On,ObjectStore, Memory) {

Outcomes