AnsweredAssumed Answered

JS API: How to Update the Legend when changing Renderer

Question asked by brambow on Jul 7, 2016
Latest reply on Jul 8, 2016 by brambow

I have an application I'm building with version 3.16 of the API.  One of the features is the ability to switch between 3 different symbology sets.  Each of these 3 is created using the UniqueValueRenderer and updating the FeatureLayer's renderer when a specific option is chosen.  Works great.


The problem I'm having is that I want the legend in the application to update when a new renderer is applied, but I haven't been able to figure it out.


I've tried:



I've also tried writing and calling a function that should destroy any existing legend and create a new one:

  function updateLegend(map, fl) {
    // destroy previous legend, if present
    if ( app.hasOwnProperty("legend") ) {
    // create a new div for the legend
    var legendDiv = domConstruct.create("div", {
      id: "legend"
    }, dom.byId("legendWrapper"));

    app.legend = new Legend({
      map : map,
      layerInfos : [{
        layer : fl,
        title: 'Stormwater Service Requests'
    }, legendDiv);


But neither of these updates the legend.  In fact, all I get is a message where the legend should be that says "Creating Legend..."


If I have my browser console open, an error is thrown (with both of these options):

Object doesn't support property or method 'replace'

File: 3.16, Line:1715, Column: 514


It looks like the error is being thrown in the API code, not the code for my app.  Does anyone have any insight on what this error might be, and what I can do to get the legend to update properly?