AnsweredAssumed Answered

Problem with UniqueValueRenderer

Question asked by rolandoflorez17 on Dec 21, 2016
Latest reply on Dec 27, 2016 by thejus.kambi

Hi,
I have a problem with this render.
I'm trying to diferenciate the posible values from a domain field (with respective coded values). The render receive a symbol and the field. And then I'm going code value by code value (into foreach) assigning diferents color and label.
But the result is that the render is drawing all codedvalues with the last color assigned.

uniqueValRender: function () {
   var randomColor;
   var defaultSymbol = this.getBaseSymbol();
   console.info(defaultSymbol);
   console.info(this.parameters.field);
   var renderer = new UniqueValueRenderer(defaultSymbol, this.parameters.field);
   var codedValues = this.parameters.domainObject.codedValues;
   var color;

   arrayUtils.forEach(codedValues, function (value) {
      console.info(value);
      randomColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
      console.warn(randomColor);
      color = new Color(randomColor);
      /*color.a = 0.5;*/
      console.info(color);
      console.info(value.code);
      console.info(value.name);
      renderer.addValue({
      value: value.code,
      symbol: defaultSymbol.setColor(color),
      label: value.name,
      description: ""
   });
   console.info(renderer);
});

   var optionsArray = [];
   var drawingOptions = new LayerDrawingOptions();
   drawingOptions.renderer = renderer;
   // set the drawing options for the relevant layer
   // optionsArray index corresponds to layer index in the map service
   optionsArray[this.parameters.idPos] = drawingOptions;
   this.parameters.layer.setLayerDrawingOptions(optionsArray);
   this.parameters.layer.show();
   if (!this.legend) {
      this.createLegend();
   }

}

Outcomes