How can I, if possible, set a renderer for an ArcGISDynamicMapServiceLayer which uses a function to determine feature values instead of just attribute values?

When using the following code, the function specified never gets called. Instead, the value to be added last is used for every feature, which kind of seems like a bug to me. That is, the following, which I expected to render features using the default gray symbol only, instead renders all features red.

var map, mapService;
require(["esri/map", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/layers/LayerDrawingOptions", "esri/renderers/UniqueValueRenderer", "esri/symbols/SimpleFillSymbol", "dojo/_base/Color", "dojo/domReady!"],
    function (Map, ArcGISDynamicMapServiceLayer, LayerDrawingOptions, UniqueValueRenderer, SimpleFillSymbol, Color) {

    var drawingOptions, optionsArray = [];

    map = new Map("mapDiv", {
        basemap: "osm",
        center: [0, 0],
        zoom: 5

    mapService = new ArcGISDynamicMapServiceLayer(
        {id: "test"});

    // The renderer displays polygons with a GRAY fill per default.
    var defaultSymbol = new SimpleFillSymbol().setColor(new Color("#999999"));
    // There are only two specified categories, using YELLOW and RED fill.
    var yellowSymbol = new SimpleFillSymbol().setColor(new Color("#ffff00"));
    var redSymbol = new SimpleFillSymbol().setColor(new Color("#ff0000"));

    var renderer = new UniqueValueRenderer(defaultSymbol, function (feature) {
        return "other";

    renderer.addValue({value: "yellow",
        symbol: yellowSymbol,
        label: "Category One (Yellow)", description: ""});
    renderer.addValue({value: "red",
        symbol: redSymbol,
        label: "Category Two (Red)", description: ""});

    drawingOptions = new LayerDrawingOptions();
    drawingOptions.renderer = renderer;
    optionsArray[0] = drawingOptions;

Following this sample, using a FeatureLayer instead and adding the renderer by calling layer.setRenderer(renderer);. produces the expected result but is not the answer to this question.

1 Answer 1


A dynamic layer is rendered on the server, which does not support the same functionality as a graphics layer, which is rendered on the browser. The browser can easily run a JavaScript function at rendering time for the desired result; however, to communicate/run the function to/on the server is very difficult, if not impossible: it may have all sorts of code, references to other scope, etc.

The Esri documentation doesn't mention this distinction specifically, but the LayerDrawingOptions object is basically providing an intermediate step of transforming (what it can) a renderer to options that a server understands for a dynamic layer. This is in contrast to the graphics layer which has the renderer set directly.

  • 1
    Thanks for the explanation, it makes sense. As you hint at, my misunderstanding is probably due to the documentation. Perhaps they could mention that function-based renderers are not valid for dynamic layers. Also, I think the layer should fall back to use the default symbol instead of the last to be added (in case of an invalid renderer).
    – MattiasSp
    Apr 25, 2014 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.