Select to view content in your preferred language

GenerateRendererTask does not create symbols

295
0
03-14-2022 01:24 PM
KisakyeM
New Contributor III

I am attempting to render a feature layer based on UniqueValueDefinition to show unique symbology for the unique values for a given field. When the field changes, I re-render the feature layer. My problem is that the unique values are shown but there are no symbols associated with the values. Why is GenerateRendererTask  not generating symbols for the unique values? I've attached an image of the legend with the unique values whose symbols are missing. Javascript api version 3.39.

Edit: I used the layer at "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2" to test and the symbols are shown. The only major difference between that layer and mine is Can Modify Layer: true. Could that be causing the symbols not to show up in my application?

 

 

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",
  "esri/layers/LayerDrawingOptions",
  "esri/tasks/QueryTask",
  "esri/tasks/query",
  "esri/renderers/UniqueValueRenderer",
  "dijit/form/Select"
],
  function(declare, _WidgetsInTemplateMixin, BaseWidget,
    esriRequest, arrayUtils, Color,
    UniqueValueDefinition, AlgorithmicColorRamp,
    FeatureLayer, SimpleFillSymbol,
    lang, on, GenerateRendererParameters, GenerateRendererTask,LayerDrawingOptions,QueryTask,Query,UniqueValueRenderer ) {

      return declare([BaseWidget, _WidgetsInTemplateMixin], {

        baseClass: 'jimu-widget-aUV',
        currField: null,

        postCreate: function() {
          this.inherited(arguments);
        },

        startup: function() {
          this.own(on(this.selectField, "change", lang.hitch(this, this.onFieldChange)));
		var layerUrl="my service url";
          var landusePolygonLayer = new FeatureLayer(layerUrl, {
            id: "canada_Risk",
            mode: FeatureLayer.MODE_SNAPSHOT,
            outFields: ["*"]
          });
          this.map.addLayers([landusePolygonLayer]);
		  
          //fieldInfo		  
          var canadaFields = esriRequest({
            url:layerUrl,
            content:{
              f: "json"
            },
            callbackParamName : "callback"
          });
          console.log("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.log("failed to get field names: ", err);
          });
        },

          onFieldChange: function (evt) {  	  			  			  
		
			  var colorRamp = new AlgorithmicColorRamp();
			  colorRamp.fromColor =  dojo.colorFromHex("#998ec3");//new Color.fromHex("#ffffcc");
			  colorRamp.toColor =  dojo.colorFromHex("#f1a340");//new Color.fromHex("#006837");
			  colorRamp.algorithm = "hsv"; // options are:  "cie-lab", "hsv", "lab-lch"	  
			 
			  var classDef = new UniqueValueDefinition();
		      classDef.attributeField = this.selectField.get('value');
			  classDef.type = "uniqueValueDef";
			  classDef.baseSymbol = new SimpleFillSymbol().setColor(new Color([255,0,0,0.5]));//new SimpleFillSymbol("solid", null, null);
			  classDef.ColorRamp = colorRamp;

			  var params = new GenerateRendererParameters();
			  params.classificationDefinition = classDef;					  
			  
			  var generateRenderer = new GenerateRendererTask("my service url");
			  generateRenderer.execute(params, lang.hitch(this, function(renderer){ 
							
				this.map.getLayer("canada_Risk").setRenderer(renderer);
				this.map.getLayer("canada_Risk").redraw();
				this.map.getLayer("canada_Risk").refresh();
			  }), lang.hitch(this, function(err){
				console.info(err);
          }));
        }
      });
    });

 

 

 

 

UniqueValueError.PNG

 

 

@RobertScheitlin__GISP  @ErwinSoekianto  @MichaelBranscomb  @JayantaPoddar  @AlixVezina  @DerekLaw  @KristianEkenes 

0 Kudos
0 Replies