<?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: Accessing 'url' property in 'LayerList' widget in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/accessing-url-property-in-layerlist-widget/m-p/1518281#M85295</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/822510"&gt;@LakshanRasingolla&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;The first typescript error is because the base&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-Layer.html#properties-summary" target="_self"&gt;Layer&lt;/A&gt; class doesn't have a url property.&amp;nbsp; You'll need to cast the layer as a specific layer type that does have a url property such as FeatureLayer.&amp;nbsp; It's probably best to do some sort of test for the layer type first. There are a couple ways to do this but I usually just test the `type` property on the layer.&amp;nbsp; There isn't any need to use await, the url property doesn't return a promise. Sometimes you may need to wait for then layer itself to be ready and this can be done with the load() or when() methods.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import type FeatureLayer from "@arcgis/core/layers/FeatureLayer"

layerList.on('trigger-action',(event) =&amp;gt; {
  const { action, item } = event;

  if (action.id == 'description') {
    if (item.layer.type === 'feature') {
      const layer = item.layer as FeatureLayer;
      const layerUrl = layer.url;
      window.open(layer.url);
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The sample code would need to be modified like so to make typescript happy.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;      ...
      } else if (id === "information") {
        // If the information action is triggered, then
        // open the item details page of the service layer
        if (visibleLayer.type === "map-image") {
          const mapImageLayer = visibleLayer as MapImageLayer;
          window.open(mapImageLayer.url);
        }
      } else if (id === "increase-opacity") {
      ...&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 12 Aug 2024 11:44:21 GMT</pubDate>
    <dc:creator>Sage_Wall</dc:creator>
    <dc:date>2024-08-12T11:44:21Z</dc:date>
    <item>
      <title>Accessing 'url' property in 'LayerList' widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/accessing-url-property-in-layerlist-widget/m-p/1518175#M85291</link>
      <description>&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;Version :- "@arcgis/core"&lt;SPAN&gt;: &lt;SPAN&gt;"4.30.9"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;I am implementing a&amp;nbsp;LayerList widget with actions. One of these actions is 'Description' which redirects the user to the map server directory. For this purpose, I need to get the URL of the selected layer. You can find the solutions tried below.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;P&gt;&lt;STRONG&gt;First implementation:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&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: layerItemActions,
    });

    layerList.on('trigger-action', async (event) =&amp;gt; {
      // Capture the action id.
      const id = event.action.id;

      if (id == 'description') {
        const layerUrl = (await event.item.layer.url) as string;
        window.open(layerUrl);
      }
    });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Even though above solution works it gives the following error,&lt;/P&gt;&lt;P&gt;'Property 'url' does not exist on type 'Layer'.'&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;STRONG&gt;Second implementation:&amp;nbsp;&lt;/STRONG&gt;&lt;/STRONG&gt;&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: layerItemActions,
    });

    layerList.on('trigger-action', async (event) =&amp;gt; {
      // Capture the action id.
      const id = event.action.id;

    if (id == 'description') {
        const layerUrl = (await event.item.layer.get('url')) as string;
        window.open(layerUrl);
      }
    });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The above solution also works, But with the following deprecated message,&amp;nbsp;&lt;/P&gt;&lt;P&gt;[esri.layers.FeatureLayer] &lt;span class="lia-unicode-emoji" title=":stop_sign:"&gt;🛑&lt;/span&gt; DEPRECATED - Function: `Accessor.get` is deprecated in favor of using optional chaining()&lt;STRONG&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;As far as I understand, the first approach might be the correct one. But I need to find a way to avoid this error message. How do we fix this issue?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2024 03:58:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/accessing-url-property-in-layerlist-widget/m-p/1518175#M85291</guid>
      <dc:creator>LakshanRasingolla</dc:creator>
      <dc:date>2024-08-12T03:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing 'url' property in 'LayerList' widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/accessing-url-property-in-layerlist-widget/m-p/1518281#M85295</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/822510"&gt;@LakshanRasingolla&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;The first typescript error is because the base&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-Layer.html#properties-summary" target="_self"&gt;Layer&lt;/A&gt; class doesn't have a url property.&amp;nbsp; You'll need to cast the layer as a specific layer type that does have a url property such as FeatureLayer.&amp;nbsp; It's probably best to do some sort of test for the layer type first. There are a couple ways to do this but I usually just test the `type` property on the layer.&amp;nbsp; There isn't any need to use await, the url property doesn't return a promise. Sometimes you may need to wait for then layer itself to be ready and this can be done with the load() or when() methods.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import type FeatureLayer from "@arcgis/core/layers/FeatureLayer"

layerList.on('trigger-action',(event) =&amp;gt; {
  const { action, item } = event;

  if (action.id == 'description') {
    if (item.layer.type === 'feature') {
      const layer = item.layer as FeatureLayer;
      const layerUrl = layer.url;
      window.open(layer.url);
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The sample code would need to be modified like so to make typescript happy.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;      ...
      } else if (id === "information") {
        // If the information action is triggered, then
        // open the item details page of the service layer
        if (visibleLayer.type === "map-image") {
          const mapImageLayer = visibleLayer as MapImageLayer;
          window.open(mapImageLayer.url);
        }
      } else if (id === "increase-opacity") {
      ...&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 12 Aug 2024 11:44:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/accessing-url-property-in-layerlist-widget/m-p/1518281#M85295</guid>
      <dc:creator>Sage_Wall</dc:creator>
      <dc:date>2024-08-12T11:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing 'url' property in 'LayerList' widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/accessing-url-property-in-layerlist-widget/m-p/1522696#M85387</link>
      <description>&lt;P&gt;This solution worked. Thankz..!!!&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/507049"&gt;@Sage_Wall&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 03:04:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/accessing-url-property-in-layerlist-widget/m-p/1522696#M85387</guid>
      <dc:creator>LakshanRasingolla</dc:creator>
      <dc:date>2024-08-16T03:04:53Z</dc:date>
    </item>
  </channel>
</rss>

