carisasmith

UniqueValueRenderer function attribute not working with a second attribute field

Discussion created by carisasmith on Dec 14, 2013
Latest reply on Jan 8, 2014 by carisasmith
Let me know if I'm missing something here, but it seems to me that the JavaScript UniqueValueRenderer function option works fine if you just use one attributeField for your function, but if you have one function and another attributeField as an actual attributeField.  The function no longer is called.  Two attribute fields only work fine as well.  I realize the first attributeField is the only one that appears to be open for the use of a function call and that is which field I'm using, yet also using attributeField2 as an attributeField from the Feature Class.

Modifying ESRI's example doesn't seem to work either (modified code below to use UniqueValueRenderer & pick three values I know exist from their sample):
Note: the code below works if I put in the values of "M163_07" instead of function calculateSquareMiles

https://developers.arcgis.com/en/javascript/jssamples/renderer_function.html

    var map, calculateSquareMiles;
      require([
        "esri/map", "esri/layers/FeatureLayer", "esri/InfoTemplate",
        "esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleLineSymbol", "esri/renderers/UniqueValueRenderer",
        "esri/dijit/Legend",
        "dojo/_base/Color", "dojo/number", "dojo/domReady!"
      ], function(
        Map, FeatureLayer, InfoTemplate,
        SimpleFillSymbol, SimpleLineSymbol, UniqueValueRenderer,
        Legend,
        Color, number
      ) {
        map = new Map("map", {
          basemap: "gray",
          center: [-89.849, 40.369],
          zoom: 6
        });

        // convert acres to square miles
        // also used by the feature layer's info template
        // test for presence to a property named "attributes" to
        // determine whether or the "value" argument is a graphic or number
        calculateSquareMiles = function(value) {
          var acres = (value.hasOwnProperty("attributes")) ? value.attributes.M163_07 : value;
          return number.format(acres / 640, { places: 2 });;
        }
       
        var symbol = new SimpleFillSymbol("solid", null, null);
        var renderer = new UniqueValueRenderer(null, calculateSquareMiles, "STATE", null, ":");
        //renderer.setMaxInclusive(true);
        var color1 = new Color([247, 252, 185]); // yellow
        var color2 = new Color([173, 221, 142]); // light green
        var color3 = new Color([49, 163, 84]); // green
        renderer.addValue("4.67:MO",new SimpleFillSymbol(  //"2987:MO"
            "solid",
            new SimpleLineSymbol("solid", color1, 1),
            color1
          ));
        renderer.addValue("39.83:MO",new SimpleFillSymbol( //"25491:MO"
            "solid",
            new SimpleLineSymbol("solid", color2, 1),
            color2
          ));
        renderer.addValue("252.41:IA", new SimpleFillSymbol( //"161542:IA"
            "solid",
            new SimpleLineSymbol("solid", color3, 1),
            color3
          ));
 
        layer.setRenderer(renderer);
        map.addLayers([layer]);

Outcomes