<?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: Change item description depending on the active map in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1236851#M79521</link>
    <description>&lt;P&gt;Note: when adding code to your post, please follow these &lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633#U1007633" target="_self"&gt;instructions&lt;/A&gt;. It makes it much easier to read&lt;/P&gt;&lt;P&gt;You're creating the description variable within the map.when function, so I think you're running into a problem of variable scope. Try instantiating it in the main body of the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const webmapids = [
  "3885bf6eb36c49d1a594b1ecfc093b08",
  "57aadf0f1a374ccda9a0bfeea25f323d",
  "5c41943d760d427a9f78b81b96c0af03",
  "fa90c70cf7ea416381e8fde8bae57055"
];
let description;

map.when(() =&amp;gt; {
  const title = map.portalItem.title;
  description = [webmaps[0].portalItem.description,   webmaps[1].portalItem.description, webmaps[2].portalItem.description, webmaps[3].portalItem.description];
  document.querySelector("#header-title").textContent = title;
  document.querySelector("#item-description").innerHTML = description[0];
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Dec 2022 16:33:03 GMT</pubDate>
    <dc:creator>KenBuja</dc:creator>
    <dc:date>2022-12-01T16:33:03Z</dc:date>
    <item>
      <title>Change item description depending on the active map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1236761#M79515</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an app where you can change the active webmap like in&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=webmap-swap" target="_self"&gt; this sample.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;That works wonderful, but I also have a calcite panel that is populated with the map's description. This also works. But when I change the active map, it does not update to the description of the active map.&lt;/P&gt;&lt;P&gt;How can I get it to update when clicking the button that changes the active webmap?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how the description of the first map is put into the panel:&lt;/P&gt;&lt;P&gt;map.when(() =&amp;gt; {&lt;BR /&gt;const {&lt;BR /&gt;title,&lt;BR /&gt;description&lt;BR /&gt;} = map.portalItem;&lt;BR /&gt;document.querySelector("#header-title").textContent = title;&lt;BR /&gt;document.querySelector("#item-description").innerHTML = description;&lt;/P&gt;&lt;P&gt;)};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be much appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 12:34:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1236761#M79515</guid>
      <dc:creator>LeidavanHees</dc:creator>
      <dc:date>2022-12-01T12:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: Change item description depending on the active map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1236766#M79517</link>
      <description>&lt;P&gt;Similar to how a webmap is selected from the webmaps array when you click on the tab, set up your descriptions in an array. Select the description from the array using the data-id value and apply that to your panel&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 13:03:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1236766#M79517</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-12-01T13:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: Change item description depending on the active map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1236767#M79518</link>
      <description>&lt;P&gt;Thank you for your response!&lt;/P&gt;&lt;P&gt;I've tried what you suggested, but think I'm still missing something.&lt;/P&gt;&lt;P&gt;I set up the array in the map.when and call on the descriptions when clicking the button. That part works. But only the description of the first map is loaded into the array. The descriptions of the other maps remain empty.&lt;/P&gt;&lt;P&gt;I think maybe because the other maps have not loaded when trying to get the description? Do you know what I could try to fix this?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 13:25:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1236767#M79518</guid>
      <dc:creator>LeidavanHees</dc:creator>
      <dc:date>2022-12-01T13:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: Change item description depending on the active map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1236768#M79519</link>
      <description>&lt;P&gt;Can you post your code?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 13:32:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1236768#M79519</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-12-01T13:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: Change item description depending on the active map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1236770#M79520</link>
      <description>&lt;P&gt;Ofcourse, I think these are the relevant bits. I can also post the rest if you prefer, but there is a lot of junk in there atm.&lt;/P&gt;&lt;P&gt;const webmapids = [&lt;BR /&gt;"3885bf6eb36c49d1a594b1ecfc093b08",&lt;BR /&gt;"57aadf0f1a374ccda9a0bfeea25f323d",&lt;BR /&gt;"5c41943d760d427a9f78b81b96c0af03",&lt;BR /&gt;"fa90c70cf7ea416381e8fde8bae57055"&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;const webmaps = webmapids.map((webmapid) =&amp;gt; {&lt;BR /&gt;return new WebMap({&lt;BR /&gt;portalItem: {&lt;BR /&gt;// autocasts as new PortalItem()&lt;BR /&gt;id: webmapid&lt;BR /&gt;}&lt;BR /&gt;});&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;const map = webmaps[0];&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;const view = new MapView({&lt;BR /&gt;map: webmaps[0],&lt;BR /&gt;container: "viewDiv",&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;map.when(() =&amp;gt; {&lt;BR /&gt;const title = map.portalItem.title;&lt;BR /&gt;const description = [webmaps[0].portalItem.description, webmaps[1].portalItem.description, webmaps[2].portalItem.description, webmaps[3].portalItem.description];&lt;BR /&gt;document.querySelector("#header-title").textContent = title;&lt;BR /&gt;document.querySelector("#item-description").innerHTML = description[0];&lt;/P&gt;&lt;P&gt;});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;document.querySelector(".btns").addEventListener("click", (event) =&amp;gt; {&lt;BR /&gt;const id = event.target.getAttribute("data-id");&lt;BR /&gt;if (id) {&lt;BR /&gt;const webmap = webmaps[id];&lt;BR /&gt;view.map = webmap;&lt;/P&gt;&lt;P&gt;const nodes = document.querySelectorAll(".btn-switch");&lt;BR /&gt;for (let idx = 0; idx &amp;lt; nodes.length; idx++) {&lt;BR /&gt;const node = nodes[idx];&lt;BR /&gt;const mapIndex = node.getAttribute("data-id");&lt;BR /&gt;if (mapIndex === id) {&lt;BR /&gt;node.appearance = "solid";&lt;BR /&gt;} else {&lt;BR /&gt;node.appearance = "outline";&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;document.querySelector("#item-description").innerHTML = description[id];&lt;BR /&gt;}&lt;BR /&gt;});&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 13:38:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1236770#M79520</guid>
      <dc:creator>LeidavanHees</dc:creator>
      <dc:date>2022-12-01T13:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Change item description depending on the active map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1236851#M79521</link>
      <description>&lt;P&gt;Note: when adding code to your post, please follow these &lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633#U1007633" target="_self"&gt;instructions&lt;/A&gt;. It makes it much easier to read&lt;/P&gt;&lt;P&gt;You're creating the description variable within the map.when function, so I think you're running into a problem of variable scope. Try instantiating it in the main body of the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const webmapids = [
  "3885bf6eb36c49d1a594b1ecfc093b08",
  "57aadf0f1a374ccda9a0bfeea25f323d",
  "5c41943d760d427a9f78b81b96c0af03",
  "fa90c70cf7ea416381e8fde8bae57055"
];
let description;

map.when(() =&amp;gt; {
  const title = map.portalItem.title;
  description = [webmaps[0].portalItem.description,   webmaps[1].portalItem.description, webmaps[2].portalItem.description, webmaps[3].portalItem.description];
  document.querySelector("#header-title").textContent = title;
  document.querySelector("#item-description").innerHTML = description[0];
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 16:33:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1236851#M79521</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-12-01T16:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: Change item description depending on the active map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1236863#M79522</link>
      <description>&lt;P&gt;I will test that as soon as I can! Thanks again and I will be sure to post my code better next time.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 16:52:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1236863#M79522</guid>
      <dc:creator>LeidavanHees</dc:creator>
      <dc:date>2022-12-01T16:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: Change item description depending on the active map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1237713#M79555</link>
      <description>&lt;P&gt;Unfortunately, that didn't quite work. But you did point me in the right direction.&lt;/P&gt;&lt;P&gt;It seems the descriptions weren't loading because the map.when fucntion belonged to the first webmap. The others apparently need to be loaded before you can get their description.&lt;/P&gt;&lt;P&gt;So, I ended up loading the descriptions of the other maps each in their own map.when functions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for the help, you are awesome!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;	let description = ["Beschrijving wordt geladen","Beschrijving wordt geladen","Beschrijving wordt geladen","Beschrijving wordt geladen"];

      webmaps[0].when(() =&amp;gt; {
	const title = map.portalItem.title;
	description[0] = [webmaps[0].portalItem.description];
        document.querySelector("#header-title").textContent = title;
        document.querySelector("#item-description").innerHTML = description[0];
});

     webmaps[1].when(() =&amp;gt; {
	description[1] = [webmaps[1].portalItem.description]
        document.querySelector("#item-description").innerHTML = description[1];
	});

	
     webmaps[2].when(() =&amp;gt; {
	description[2] = [webmaps[2].portalItem.description]
        document.querySelector("#item-description").innerHTML = description[2];
	});


     webmaps[3].when(() =&amp;gt; {
	description[3] = [webmaps[3].portalItem.description]
        document.querySelector("#item-description").innerHTML = description[3];
	});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 11:32:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-item-description-depending-on-the-active/m-p/1237713#M79555</guid>
      <dc:creator>LeidavanHees</dc:creator>
      <dc:date>2022-12-05T11:32:09Z</dc:date>
    </item>
  </channel>
</rss>

