<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic JS API: How to Update the Legend when changing Renderer in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676228#M62989</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have an application I'm building with version 3.16 of the API.&amp;nbsp; One of the features is the ability to switch between 3 different symbology sets.&amp;nbsp; Each of these 3 is created using the UniqueValueRenderer and updating the FeatureLayer's renderer when a specific option is chosen.&amp;nbsp; Works great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;app.legend.refresh();&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've also tried writing and calling a function that should destroy any existing legend and create a new one:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; function updateLegend(map, fl) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // destroy previous legend, if present&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( app.hasOwnProperty("legend") ) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; app.legend.destroy();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; domConstruct.destroy(dojo.byId("legend"));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // create a new div for the legend&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var legendDiv = domConstruct.create("div", {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id: "legend"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }, dom.byId("legendWrapper"));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; app.legend = new Legend({&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map : map,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerInfos : [{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer : fl,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; title: 'Stormwater Service Requests'&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }, legendDiv);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; app.legend.startup();&lt;BR /&gt;&amp;nbsp; }&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But neither of these updates the legend.&amp;nbsp; In fact, all I get is a message where the legend should be that says "Creating Legend..."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I have my browser console open, an error is thrown (with both of these options):&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Object doesn't support property or method 'replace'&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;File: 3.16, Line:1715, Column: 514&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It looks like the error is being thrown in the API code, not the code for my app.&amp;nbsp; Does anyone have any insight on what this error might be, and what I can do to get the legend to update properly?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 Jul 2016 20:27:00 GMT</pubDate>
    <dc:creator>BatesRambow</dc:creator>
    <dc:date>2016-07-07T20:27:00Z</dc:date>
    <item>
      <title>JS API: How to Update the Legend when changing Renderer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676228#M62989</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have an application I'm building with version 3.16 of the API.&amp;nbsp; One of the features is the ability to switch between 3 different symbology sets.&amp;nbsp; Each of these 3 is created using the UniqueValueRenderer and updating the FeatureLayer's renderer when a specific option is chosen.&amp;nbsp; Works great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;app.legend.refresh();&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've also tried writing and calling a function that should destroy any existing legend and create a new one:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; function updateLegend(map, fl) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // destroy previous legend, if present&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( app.hasOwnProperty("legend") ) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; app.legend.destroy();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; domConstruct.destroy(dojo.byId("legend"));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // create a new div for the legend&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var legendDiv = domConstruct.create("div", {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id: "legend"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }, dom.byId("legendWrapper"));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; app.legend = new Legend({&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map : map,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerInfos : [{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer : fl,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; title: 'Stormwater Service Requests'&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }, legendDiv);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; app.legend.startup();&lt;BR /&gt;&amp;nbsp; }&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But neither of these updates the legend.&amp;nbsp; In fact, all I get is a message where the legend should be that says "Creating Legend..."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I have my browser console open, an error is thrown (with both of these options):&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Object doesn't support property or method 'replace'&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;File: 3.16, Line:1715, Column: 514&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It looks like the error is being thrown in the API code, not the code for my app.&amp;nbsp; Does anyone have any insight on what this error might be, and what I can do to get the legend to update properly?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2016 20:27:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676228#M62989</guid>
      <dc:creator>BatesRambow</dc:creator>
      <dc:date>2016-07-07T20:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: JS API: How to Update the Legend when changing Renderer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676229#M62990</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It should not be necessary to rebuild the legend every time.&amp;nbsp; Try setting the autoUpdate property to true and run the refresh() after the layer renderer change.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jul 2016 06:13:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676229#M62990</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2016-07-08T06:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: JS API: How to Update the Legend when changing Renderer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676230#M62991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, but that doesn't change anything.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jul 2016 12:43:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676230#M62991</guid>
      <dc:creator>BatesRambow</dc:creator>
      <dc:date>2016-07-08T12:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: JS API: How to Update the Legend when changing Renderer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676231#M62992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I might be wrong, but the legend widget is getting the symbology from the rest, so when you change the symbology in your app, it won't show a change in the legend.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jul 2016 12:49:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676231#M62992</guid>
      <dc:creator>TimWitt2</dc:creator>
      <dc:date>2016-07-08T12:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: JS API: How to Update the Legend when changing Renderer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676232#M62993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So the legend works when you initiate the application with any of the 3 symbology sets?&amp;nbsp; And you are not forcing the legend to update before the layer has completely updated the symbology renderer?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jul 2016 12:49:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676232#M62993</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2016-07-08T12:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: JS API: How to Update the Legend when changing Renderer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676233#M62994</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It does, but not if you apply a renderer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jul 2016 12:51:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676233#M62994</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2016-07-08T12:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: JS API: How to Update the Legend when changing Renderer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676234#M62995</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I figured this out in case anyone else has this issue.&amp;nbsp; The problem was that I was not setting a 'label' value for each of the UniqueValues in my renderer.&amp;nbsp; It isn't totally obvious, but that 'label' value is required for the legend to display.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jul 2016 12:59:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676234#M62995</guid>
      <dc:creator>BatesRambow</dc:creator>
      <dc:date>2016-07-08T12:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: JS API: How to Update the Legend when changing Renderer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676235#M62996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for following up, I figured it out.&amp;nbsp; I wasn't setting the 'label' parameter in the renderer.&amp;nbsp; After adding that, it worked.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jul 2016 13:00:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-how-to-update-the-legend-when-changing/m-p/676235#M62996</guid>
      <dc:creator>BatesRambow</dc:creator>
      <dc:date>2016-07-08T13:00:42Z</dc:date>
    </item>
  </channel>
</rss>

