<?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 Re: Custom TOC / Legend Javascript API in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-toc-legend-javascript-api/m-p/276334#M25512</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Chris are you talking about feature or dynamic layers?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 May 2015 17:41:51 GMT</pubDate>
    <dc:creator>BenFousek</dc:creator>
    <dc:date>2015-05-28T17:41:51Z</dc:date>
    <item>
      <title>Custom TOC / Legend Javascript API</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-toc-legend-javascript-api/m-p/276331#M25509</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to build a Custom TOC / Legend with the ArcGIS Javascript API.&amp;nbsp; I have tried many different prebuild widgets and other googlable things but none of them seem to work completely, or be compatible with my browser requirements of IE9.&amp;nbsp; So I've been working on my own.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The issue I am having now is accessing the Legend image/symbol/png of each layer within my ArcGISDynamicMapServiceLayer so that I can insert it in the HTML.&amp;nbsp; I can see that there is a JSON thing for it within the REST page.&amp;nbsp; How do I access this and use it within my JavaScript page?&amp;nbsp; My JSON knowledge is small, but I'm sure once I learn this it will help with many other tasks.&amp;nbsp; Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 16:31:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-toc-legend-javascript-api/m-p/276331#M25509</guid>
      <dc:creator>JosephRogan</dc:creator>
      <dc:date>2015-05-28T16:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: Custom TOC / Legend Javascript API</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-toc-legend-javascript-api/m-p/276332#M25510</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;The legend json can be gotten via an esriRequest to &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://SERVER/arcgis/rest/services/SERVICE/legend" rel="nofollow noopener noreferrer" target="_blank"&gt;https://SERVER/arcgis/rest/services/SERVICE/legend&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example of a single layer legend info:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;{
&amp;nbsp; "layerId": 0,
&amp;nbsp; "layerName": "City Limits",
&amp;nbsp; "layerType": "Feature Layer",
&amp;nbsp; "minScale": 0,
&amp;nbsp; "maxScale": 0,
&amp;nbsp; "legend": [{
&amp;nbsp;&amp;nbsp;&amp;nbsp; "label": "",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "url": "d81c20bbbe11d1b64ebe9ad98f2e9062",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAADFJREFUOI1jYaAyYKGZgf/+7WugxCAmJqcGFAOpBUYNHDVw1MBRA+lsIKw8o5qB1AIA8kUFF7zjdA0AAAAASUVORK5CYII=",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "contentType": "image/png",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "height": 20,
&amp;nbsp;&amp;nbsp;&amp;nbsp; "width": 20
&amp;nbsp; }]
}&lt;/PRE&gt;&lt;P&gt;The "layerId" and "legend.url" properties can then be use to form a url for img src.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the above example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="https://SERVER/arcgis/rest/services/SERVICE/MapServer/" rel="nofollow noopener noreferrer" target="_blank"&gt;https://SERVER/arcgis/rest/services/SERVICE/MapServer/&lt;/A&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;/images/&lt;STRONG&gt;d81c20bbbe11d1b64ebe9ad98f2e9062&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with aforementioned properties in bold.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Gets a bit more complicated with categories and renderers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/cmv/cmv-app/blob/master/viewer/js/gis/dijit/LayerControl/plugins/legendUtil.js" title="https://github.com/cmv/cmv-app/blob/master/viewer/js/gis/dijit/LayerControl/plugins/legendUtil.js" rel="nofollow noopener noreferrer" target="_blank"&gt;cmv-app/legendUtil.js at master · cmv/cmv-app · GitHub&lt;/A&gt; here's a utility class I use. It's written to back a specific widget but has examples of the requests and handling the responses.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:27:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-toc-legend-javascript-api/m-p/276332#M25510</guid>
      <dc:creator>BenFousek</dc:creator>
      <dc:date>2021-12-11T13:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: Custom TOC / Legend Javascript API</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-toc-legend-javascript-api/m-p/276333#M25511</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This probably wasn't the best way to go, but for my case, I needed a custom legend for a renderer with multiple category values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried pulling it out of the renderer directly, but didn't have much luck (I got color and symbol info, but no SVGs), so the class just piggy-backs off of what I send to the renderer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From these parameters, I dynamically construct the SVGs and embed them onto the map by tying into a notify framework I'm already using. Works well for my case, and is extensible for all of my foreseeable needs (hopefully); however, I will definitely need to look into Ben's idea more...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 17:37:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-toc-legend-javascript-api/m-p/276333#M25511</guid>
      <dc:creator>ChrisSmith7</dc:creator>
      <dc:date>2015-05-28T17:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: Custom TOC / Legend Javascript API</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-toc-legend-javascript-api/m-p/276334#M25512</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Chris are you talking about feature or dynamic layers?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 17:41:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-toc-legend-javascript-api/m-p/276334#M25512</guid>
      <dc:creator>BenFousek</dc:creator>
      <dc:date>2015-05-28T17:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: Custom TOC / Legend Javascript API</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-toc-legend-javascript-api/m-p/276335#M25513</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's a feature layer dynamically creating from a JSON x/y dataset I'm getting from a proc call. I am creating the feature collection in code, and from that, the feature layer, then, applying a UniqueValueRenderer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 17:54:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-toc-legend-javascript-api/m-p/276335#M25513</guid>
      <dc:creator>ChrisSmith7</dc:creator>
      <dc:date>2015-05-28T17:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Custom TOC / Legend Javascript API</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-toc-legend-javascript-api/m-p/276336#M25514</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was asking because feature layers are easier yet. You don't need to make a call to the legend endpoint. All the methods and props are right there in the renderer classes. You're on the right track with svg. You can create surfaces and svg using 'dojox/gfx'. &lt;A href="https://github.com/cmv/cmv-app/blob/master/viewer/js/gis/dijit/LayerControl/plugins/legendUtil.js#L200" title="https://github.com/cmv/cmv-app/blob/master/viewer/js/gis/dijit/LayerControl/plugins/legendUtil.js#L200"&gt;Here&lt;/A&gt; are the methods for that.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 18:08:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-toc-legend-javascript-api/m-p/276336#M25514</guid>
      <dc:creator>BenFousek</dc:creator>
      <dc:date>2015-05-28T18:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: Custom TOC / Legend Javascript API</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-toc-legend-javascript-api/m-p/276337#M25515</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, I'll check it out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not to go too far off the original topic, legends have always been a little tricky for me since I do a lot of binding to JSON datasets. One of the things I'm doing is similar to:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/jssamples/data_gas_prices.html" title="https://developers.arcgis.com/javascript/jssamples/data_gas_prices.html"&gt;Gas price data by state mashup | ArcGIS API for JavaScript&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In 3.13, the legend creation is broken - I filed a bug with Esri:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.esri.com/en/bugs/nimbus/QlVHLTAwMDA4NjE1MA==" title="http://support.esri.com/en/bugs/nimbus/QlVHLTAwMDA4NjE1MA=="&gt;BUG-000086150 - Legend fails with JSON data in ArcGIS API for Java..&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rather than creating my own legend, I lightly massaged what the API returned, but this method fails in 3.13 since the legend is having rendering problems. Esri isn't sure when the bug will be fixed, so if I need to upgrade to the latest version before this is fixed, I will need to look into this more closely - that and getting a meaningful legend to show up when using the print/export service!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 18:18:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-toc-legend-javascript-api/m-p/276337#M25515</guid>
      <dc:creator>ChrisSmith7</dc:creator>
      <dc:date>2015-05-28T18:18:57Z</dc:date>
    </item>
  </channel>
</rss>

