UniqueValueRenderer with array of values

4376
3
02-26-2013 01:30 AM
MarcoBrugna
New Contributor II
Hi everyone,

is it possibile to create a UniqueValueRenderer using an array of values?
Something like this:

var info = {
                value: [1778,1779],
                symbol: new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([256,0,0]))
            };

var renderer = new esri.renderer.UniqueValueRenderer(defaultSymbol, "O");
renderer.infos = [info];


I have a layer with about 3000 polygons and I need to add tree type of symbols (red, yellow and green) based on a value coming from a database.

PS. With ArcGis Dekstop this thing is possibile using the groups in the Unique Value Symbology.


Thanks in advance
Marco
3 Replies
MartinOver
New Contributor III

Hi,

Using an array instead a single string would be perfect for many solutions.

Please consider an implementation.

Best,

Martin

0 Kudos
ChristopherTotty
New Contributor III

You can accomplish this functionality using multiple calls to your renderer's addValue method in combination with passing a function into the UniqueValueRenderer constructor.  Check out this example:

r.addValue(3, greenSymbol);

renderer = new UniqueValueRenderer(defaultSymbol, function (value) {
  var expectedRedValue = 'red'; //You provide these based on your data
  var expectedYellowValue = 'yellow';
  var expectedGreenValue = 'green';
  if (value.attributes.YourAttribute == expectedRedValue) {
       return 1;
  }
  else if (value.attributes.YourAttribute == expectedYellowValue) {
       return 2;
  }
  else if (value.attributes.YourAttribute == expectedGreenValue) {
       return 3;
  }
});


renderer.addValue(1, redSymbol);
renderer.addValue(2, yellowSymbol);
renderer.addValue(3, greenSymbol);
MartinOver
New Contributor III

Hi,

Thanks for this solution.

We would like to use the UniqueValueRenderer inside the dynamicLayers parameter with a direkt browser request. The Request gets very long when the whole uniqueValueInfos part must be repeated for every single value.

Best,

Martin

0 Kudos