<?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: How to get reference to instance of Legend in LayerList? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-get-reference-to-instance-of-legend-in/m-p/1332091#M82309</link>
    <description>&lt;P&gt;There doesn't appear to be a way of doing so according to the documentation, but this presently works:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const layerList = new LayerList({
  view: view,
  listItemCreatedFunction: function(event){
    const item = event.item;
    // displays the legend for each layer list item
    item.panel = {
      content: "legend"
    };
    var handle = item.panel.watch("className", function(newValue, oldValue, propertyName, target) {
      if (target._legend) {
        handle.remove();
        handle = null;

        var legend = target._legend;
        alert("got legend: " + legend.id);
      }
    });
  }
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Sep 2023 18:26:32 GMT</pubDate>
    <dc:creator>JoelBennett</dc:creator>
    <dc:date>2023-09-25T18:26:32Z</dc:date>
    <item>
      <title>How to get reference to instance of Legend in LayerList?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-get-reference-to-instance-of-legend-in/m-p/1331848#M82294</link>
      <description>&lt;P&gt;Given example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const layerList = new LayerList({
  view: view,
  listItemCreatedFunction: function(event){
    const item = event.item;
    // displays the legend for each layer list item
    item.panel = {
      content: "legend"
    };
  }
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to get reference to the legend instance created this way? E.g., if I would like to set legend.&lt;SPAN&gt;respectLayerVisibility to false? &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Update - current workaround I use is by&amp;nbsp;&lt;/SPAN&gt;creating legend instance from Legend widget myself:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const legend = new arcgis.Legend({
    view: view,
    respectLayerVisibility: false,
    layerInfos: [
        {
            layer: item.layer,
        },
    ],
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And add legend instance created this way to the panel instead of using string 'legend':&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    item.panel = {
      content: legend
    };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 03:13:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-get-reference-to-instance-of-legend-in/m-p/1331848#M82294</guid>
      <dc:creator>miro_aus</dc:creator>
      <dc:date>2023-09-25T03:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get reference to instance of Legend in LayerList?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-get-reference-to-instance-of-legend-in/m-p/1332091#M82309</link>
      <description>&lt;P&gt;There doesn't appear to be a way of doing so according to the documentation, but this presently works:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const layerList = new LayerList({
  view: view,
  listItemCreatedFunction: function(event){
    const item = event.item;
    // displays the legend for each layer list item
    item.panel = {
      content: "legend"
    };
    var handle = item.panel.watch("className", function(newValue, oldValue, propertyName, target) {
      if (target._legend) {
        handle.remove();
        handle = null;

        var legend = target._legend;
        alert("got legend: " + legend.id);
      }
    });
  }
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 18:26:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-get-reference-to-instance-of-legend-in/m-p/1332091#M82309</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2023-09-25T18:26:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to get reference to instance of Legend in LayerList?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-get-reference-to-instance-of-legend-in/m-p/1349514#M82763</link>
      <description>&lt;P&gt;Thank you, appreciate it.&lt;/P&gt;&lt;P&gt;I have ended up creating legend object for each item in layer list using Legend widget and layerInfos as:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const legend = new Legend({
  view: view,
  layerInfos: [{
    title: '',
    layer: item.layer,
  },],
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Creating legend by just passing legend string is really convenient way if one doesn't need reference, but until there will be standard&amp;nbsp; way to get a reference I stick with creating legend with these couple of lines.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2023 03:46:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-get-reference-to-instance-of-legend-in/m-p/1349514#M82763</guid>
      <dc:creator>miro_aus</dc:creator>
      <dc:date>2023-11-15T03:46:37Z</dc:date>
    </item>
  </channel>
</rss>

