<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Update feature layer symbology with unique values in ArcGIS Web AppBuilder Questions</title>
    <link>https://community.esri.com/t5/arcgis-web-appbuilder-questions/update-feature-layer-symbology-with-unique-values/m-p/1153153#M21987</link>
    <description>&lt;P&gt;I am new to javascript so please bear with me. I am attempting to build a widget that allows the user to select a field from a drop down list and have the feature layer in the map symbolise with unique values based on the selected field. My code is based on this sample&amp;nbsp;&lt;A href="https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/setrenderer-error-getfieldsusedinexpressions-is/td-p/825783" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/setrenderer-error-getfieldsusedinexpressions-is/td-p/825783&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;The area of interest is the OnFieldChange where I am attempting to use a UniqueValueRenderer to map the feature layer. I however get this error in the chrome console "TypeError: (intermediate value).setColor is not a function". Any ideas are much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;define([
  'dojo/_base/declare',
  "dijit/_WidgetsInTemplateMixin",
  'jimu/BaseWidget',
  "esri/request",
  "dojo/_base/array",
  "esri/Color",
  "esri/tasks/UniqueValueDefinition",
  "esri/tasks/AlgorithmicColorRamp",
  "esri/layers/FeatureLayer",
  "esri/symbols/SimpleFillSymbol",
  "dojo/_base/lang",
  "dojo/on",
  "esri/tasks/GenerateRendererParameters",
  "esri/tasks/GenerateRendererTask",
  "dijit/form/Select",
  "jimu/dijit/RendererChooser",
  "esri/symbols/SimpleFillSymbol", 
  "esri/Color", 
  "esri/renderers/SimpleRenderer",
  "esri/renderers/UniqueValueRenderer"
],
  function(declare, _WidgetsInTemplateMixin, BaseWidget,
    esriRequest, arrayUtils, Color,
    UniqueValueDefinition, AlgorithmicColorRamp,
    FeatureLayer, SimpleFillSymbol,
    lang, on, GenerateRendererParameters, GenerateRendererTask, RendererChooser,
	SimpleFillSymbol, Color, SimpleRenderer, UniqueValueRenderer) {

      return declare([BaseWidget, _WidgetsInTemplateMixin], {

        baseClass: 'jimu-widget-AAA7',
        currField: null,   

        postCreate: function() {
          this.inherited(arguments);
        },

          startup: function () {       
          this.own(on(this.selectField, "change", lang.hitch(this, this.onFieldChange)));

          var landusePolygonLayer = new FeatureLayer("https://myhostname/arcgis/rest/services/Hosted/Map/FeatureServer/4", {
            id: "canada_Risk",//confirm works
            mode: FeatureLayer.MODE_ONDEMAND,
            outFields: ["*"]
          });
          
          //fieldInfo
          var canadaFields = esriRequest({
            url:"https://myhostname/arcgis/rest/services/Hosted/Map/FeatureServer/4",
            content:{
              f: "json"
            },
            callbackParamName : "callback"
          });
          //console.error("Fields", canadaFields)
          var fieldNames, fieldStore;
          canadaFields.then(lang.hitch(this, function(resp){
            var fields = [];
            arrayUtils.forEach(resp.fields,function(f){
              var foption = {
                value: f.name,
                label: f.alias
              };
              fields.push(foption);
            });
            this.selectField.addOption(fields);
          }), function(err){
            console.error("failed to get field names: ", err);
          });
        },

        onFieldChange: function(evt){
		  console.warn(this.selectField.get('value'));		 
			var symbol = new SimpleFillSymbol().setColor(new Color([255,0,0,0.5]));
			var renderer = new UniqueValueRenderer(symbol, this.selectField.get('value'))
            this.map.getLayer("canada_Risk").setRenderer(renderer);
		 this.map.getLayer("canada_Risk").refresh();		 
        }
      });
    });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1104"&gt;@RobertScheitlin__GISP&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/204423"&gt;@ErwinSoekianto&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3014"&gt;@MichaelBranscomb&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/95280"&gt;@JayantaPoddar&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/148663"&gt;@AlixVezina&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1126"&gt;@DerekLaw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 13 Mar 2022 17:48:09 GMT</pubDate>
    <dc:creator>KisakyeM</dc:creator>
    <dc:date>2022-03-13T17:48:09Z</dc:date>
    <item>
      <title>Update feature layer symbology with unique values</title>
      <link>https://community.esri.com/t5/arcgis-web-appbuilder-questions/update-feature-layer-symbology-with-unique-values/m-p/1153153#M21987</link>
      <description>&lt;P&gt;I am new to javascript so please bear with me. I am attempting to build a widget that allows the user to select a field from a drop down list and have the feature layer in the map symbolise with unique values based on the selected field. My code is based on this sample&amp;nbsp;&lt;A href="https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/setrenderer-error-getfieldsusedinexpressions-is/td-p/825783" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/setrenderer-error-getfieldsusedinexpressions-is/td-p/825783&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;The area of interest is the OnFieldChange where I am attempting to use a UniqueValueRenderer to map the feature layer. I however get this error in the chrome console "TypeError: (intermediate value).setColor is not a function". Any ideas are much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;define([
  'dojo/_base/declare',
  "dijit/_WidgetsInTemplateMixin",
  'jimu/BaseWidget',
  "esri/request",
  "dojo/_base/array",
  "esri/Color",
  "esri/tasks/UniqueValueDefinition",
  "esri/tasks/AlgorithmicColorRamp",
  "esri/layers/FeatureLayer",
  "esri/symbols/SimpleFillSymbol",
  "dojo/_base/lang",
  "dojo/on",
  "esri/tasks/GenerateRendererParameters",
  "esri/tasks/GenerateRendererTask",
  "dijit/form/Select",
  "jimu/dijit/RendererChooser",
  "esri/symbols/SimpleFillSymbol", 
  "esri/Color", 
  "esri/renderers/SimpleRenderer",
  "esri/renderers/UniqueValueRenderer"
],
  function(declare, _WidgetsInTemplateMixin, BaseWidget,
    esriRequest, arrayUtils, Color,
    UniqueValueDefinition, AlgorithmicColorRamp,
    FeatureLayer, SimpleFillSymbol,
    lang, on, GenerateRendererParameters, GenerateRendererTask, RendererChooser,
	SimpleFillSymbol, Color, SimpleRenderer, UniqueValueRenderer) {

      return declare([BaseWidget, _WidgetsInTemplateMixin], {

        baseClass: 'jimu-widget-AAA7',
        currField: null,   

        postCreate: function() {
          this.inherited(arguments);
        },

          startup: function () {       
          this.own(on(this.selectField, "change", lang.hitch(this, this.onFieldChange)));

          var landusePolygonLayer = new FeatureLayer("https://myhostname/arcgis/rest/services/Hosted/Map/FeatureServer/4", {
            id: "canada_Risk",//confirm works
            mode: FeatureLayer.MODE_ONDEMAND,
            outFields: ["*"]
          });
          
          //fieldInfo
          var canadaFields = esriRequest({
            url:"https://myhostname/arcgis/rest/services/Hosted/Map/FeatureServer/4",
            content:{
              f: "json"
            },
            callbackParamName : "callback"
          });
          //console.error("Fields", canadaFields)
          var fieldNames, fieldStore;
          canadaFields.then(lang.hitch(this, function(resp){
            var fields = [];
            arrayUtils.forEach(resp.fields,function(f){
              var foption = {
                value: f.name,
                label: f.alias
              };
              fields.push(foption);
            });
            this.selectField.addOption(fields);
          }), function(err){
            console.error("failed to get field names: ", err);
          });
        },

        onFieldChange: function(evt){
		  console.warn(this.selectField.get('value'));		 
			var symbol = new SimpleFillSymbol().setColor(new Color([255,0,0,0.5]));
			var renderer = new UniqueValueRenderer(symbol, this.selectField.get('value'))
            this.map.getLayer("canada_Risk").setRenderer(renderer);
		 this.map.getLayer("canada_Risk").refresh();		 
        }
      });
    });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1104"&gt;@RobertScheitlin__GISP&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/204423"&gt;@ErwinSoekianto&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3014"&gt;@MichaelBranscomb&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/95280"&gt;@JayantaPoddar&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/148663"&gt;@AlixVezina&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1126"&gt;@DerekLaw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Mar 2022 17:48:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-web-appbuilder-questions/update-feature-layer-symbology-with-unique-values/m-p/1153153#M21987</guid>
      <dc:creator>KisakyeM</dc:creator>
      <dc:date>2022-03-13T17:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Update feature layer symbology with unique values</title>
      <link>https://community.esri.com/t5/arcgis-web-appbuilder-questions/update-feature-layer-symbology-with-unique-values/m-p/1153777#M21993</link>
      <description>&lt;P&gt;You need to fully define the SimpleFillSymbol as described here.&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/3/jsapi/simplefillsymbol-amd.html" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/javascript/3/jsapi/simplefillsymbol-amd.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The example they show sets the style of the fill, then the style and color of the outline, and finally the color of the fill.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;var&lt;/SPAN&gt;&lt;SPAN class=""&gt; sfs &lt;/SPAN&gt;&lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;new&lt;/SPAN&gt; &lt;SPAN class=""&gt;SimpleFillSymbol&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;SimpleFillSymbol&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;STYLE_SOLID&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;new&lt;/SPAN&gt; &lt;SPAN class=""&gt;SimpleLineSymbol&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;SimpleLineSymbol&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;STYLE_DASHDOT&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;new&lt;/SPAN&gt; &lt;SPAN class=""&gt;Color&lt;/SPAN&gt;&lt;SPAN class=""&gt;([&lt;/SPAN&gt;&lt;SPAN class=""&gt;255&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;&lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;&lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;SPAN class=""&gt;]),&lt;/SPAN&gt; &lt;SPAN class=""&gt;2&lt;/SPAN&gt;&lt;SPAN class=""&gt;),&lt;/SPAN&gt;&lt;SPAN class=""&gt;new&lt;/SPAN&gt; &lt;SPAN class=""&gt;Color&lt;/SPAN&gt;&lt;SPAN class=""&gt;([&lt;/SPAN&gt;&lt;SPAN class=""&gt;255&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;&lt;SPAN class=""&gt;255&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;&lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;&lt;SPAN class=""&gt;0.25&lt;/SPAN&gt;&lt;SPAN class=""&gt;])&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 13:35:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-web-appbuilder-questions/update-feature-layer-symbology-with-unique-values/m-p/1153777#M21993</guid>
      <dc:creator>BrianLeroux</dc:creator>
      <dc:date>2022-03-15T13:35:34Z</dc:date>
    </item>
  </channel>
</rss>

