<?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: JimuLayerViewSelector multi selection doesnt work as expected in ArcGIS Experience Builder Questions</title>
    <link>https://community.esri.com/t5/arcgis-experience-builder-questions/jimulayerviewselector-multi-selection-doesnt-work/m-p/1556800#M15835</link>
    <description>&lt;P&gt;Again, that wont work because the onChange callback passes in an empty array if anything is deselected.&lt;BR /&gt;&lt;BR /&gt;this :&lt;/P&gt;&lt;PRE&gt;const found = selectedViews.includes(selected)&lt;/PRE&gt;&lt;P&gt;will always return false&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Cant check if its already in my selected array because it doesnt return anything. Its impossible to know , with this component, when a layer is deselected, or at least i havent found a way.&lt;BR /&gt;&lt;BR /&gt;I ended up just recreating the component myself from scratch without using anything from jimu-ui and handling the selection the way i need it.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Nov 2024 14:42:01 GMT</pubDate>
    <dc:creator>IkelosDev</dc:creator>
    <dc:date>2024-11-08T14:42:01Z</dc:date>
    <item>
      <title>JimuLayerViewSelector multi selection doesnt work as expected</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/jimulayerviewselector-multi-selection-doesnt-work/m-p/1552785#M15666</link>
      <description>&lt;P&gt;Using ExB DE v.1.15.0&lt;/P&gt;&lt;P&gt;I'm currently working on a custom widget that needs to select multiple layers and get their IDs in a string array. The &lt;A href="https://developers.arcgis.com/experience-builder/storybook/?path=/docs/components-jimu-ui-advanced-setting-components-jimulayerviewselector--docs" target="_blank" rel="noopener"&gt;JimuLayerViewSelector&lt;/A&gt; component seemed like a suitable choice because it allowed selecting multiple layers with its&amp;nbsp;isMultiSelection&amp;nbsp;attribute&lt;/P&gt;&lt;P&gt;But, when I use the onChange callback, I noticed that it only gives me the ID of the last selected layer , and is completely empty if something is de-selected, regardless of if there are other selected layers .&lt;/P&gt;&lt;P&gt;This is okay for single selections, but for multi-selection, I expected to get all selected layer IDs in the array. I dont want to have to manually implement this behaviour from scratch if i dont have to.&lt;/P&gt;&lt;P&gt;This is my code currently:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { JimuMapView, JimuMapViewComponent } from "jimu-arcgis";
import { React, type AllWidgetProps, } from "jimu-core"
import { Loading } from "jimu-ui"
import { JimuLayerViewSelector } from 'jimu-ui/advanced/setting-components';
import { useState } from "react";

const Widget = (props: AllWidgetProps&amp;lt;any&amp;gt;) =&amp;gt; {

  const [jimuMapViewId, setJimuMapViewId] = useState&amp;lt;string&amp;gt;()
  const [selectedMapLayers, setSelectedMapLayers] = useState&amp;lt;string[]&amp;gt;()
  const activeViewChangeHandler = (jmv: JimuMapView) =&amp;gt; {
    if (jmv) {
      setJimuMapViewId(jmv.id)
    }
  }

  const onMapLayerSelected = (selectedLayerViewIds: string[]) =&amp;gt; {
    //selectedLayerViewIds only contains the last selection, or empty if you 
    //de-selected  a layer
    console.log(selectedLayerViewIds);
    setSelectedMapLayers(selectedLayerViewIds)
  }

  return (
    &amp;lt;div className="jimu-widget"&amp;gt;
      {props.useMapWidgetIds &amp;amp;&amp;amp; props.useMapWidgetIds.length === 1 &amp;amp;&amp;amp; (
        &amp;lt;JimuMapViewComponent useMapWidgetId={props.useMapWidgetIds?.[0]} onActiveViewChange={activeViewChangeHandler} /&amp;gt;
      )}
      
      {jimuMapViewId ? (
        &amp;lt;JimuLayerViewSelector jimuMapViewId={jimuMapViewId} isMultiSelection={true} onChange={onMapLayerSelected} /&amp;gt;
      ) : (&amp;lt;Loading /&amp;gt;)}
    &amp;lt;/div&amp;gt;

  )
}

export default Widget&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 14:14:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/jimulayerviewselector-multi-selection-doesnt-work/m-p/1552785#M15666</guid>
      <dc:creator>IkelosDev</dc:creator>
      <dc:date>2024-10-28T14:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: JimuLayerViewSelector multi selection doesnt work as expected</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/jimulayerviewselector-multi-selection-doesnt-work/m-p/1552825#M15668</link>
      <description>&lt;P&gt;&lt;A href="https://react.dev/learn/updating-arrays-in-state" target="_blank"&gt;https://react.dev/learn/updating-arrays-in-state&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;The way you have written this, you are replacing the array every time with a new array containing a single item. You will need to re-write your function so that you are adding new items using the spread operator and removing them with the filter method. This page from the React docs should help clarify what is going on and how to fix it.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 15:30:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/jimulayerviewselector-multi-selection-doesnt-work/m-p/1552825#M15668</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2024-10-28T15:30:38Z</dc:date>
    </item>
    <item>
      <title>Re: JimuLayerViewSelector multi selection doesnt work as expected</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/jimulayerviewselector-multi-selection-doesnt-work/m-p/1552840#M15669</link>
      <description>&lt;P&gt;I thought about that and i did do it that way initially&lt;/P&gt;&lt;P&gt;But doing it like that only tells me if a layer has been selected at some point , but i need to be able to toggle the selections.&lt;/P&gt;&lt;P&gt;Deselecting a layer calls the onChange callback with an empty array, not specifying which layer has been deselected, which as i said works fine with the single selection mode , but not with the multiple one&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 15:43:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/jimulayerviewselector-multi-selection-doesnt-work/m-p/1552840#M15669</guid>
      <dc:creator>IkelosDev</dc:creator>
      <dc:date>2024-10-28T15:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: JimuLayerViewSelector multi selection doesnt work as expected</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/jimulayerviewselector-multi-selection-doesnt-work/m-p/1556732#M15832</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/845678"&gt;@IkelosDev&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you set the props `&lt;SPAN&gt;selectedValues`? &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;When you get values from `onChange`, you need pass it to `selectedValues`.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2024 08:37:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/jimulayerviewselector-multi-selection-doesnt-work/m-p/1556732#M15832</guid>
      <dc:creator>WenpingWang</dc:creator>
      <dc:date>2024-11-08T08:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: JimuLayerViewSelector multi selection doesnt work as expected</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/jimulayerviewselector-multi-selection-doesnt-work/m-p/1556737#M15833</link>
      <description>&lt;P&gt;selectedValues isnt a prop for this component, It has defaultSelectedValues, but that only gets set on first render and then never again&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2024 08:48:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/jimulayerviewselector-multi-selection-doesnt-work/m-p/1556737#M15833</guid>
      <dc:creator>IkelosDev</dc:creator>
      <dc:date>2024-11-08T08:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: JimuLayerViewSelector multi selection doesnt work as expected</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/jimulayerviewselector-multi-selection-doesnt-work/m-p/1556795#M15834</link>
      <description>&lt;P&gt;You could check the selected value against the items already in the array. Something like this.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const [selectedViews, setSelectedViews] = useState([])

const handleSelection = (selected) =&amp;gt; {
    const found = selectedViews.includes(selected)
    if (found) {
        // remove view
        setSelectedViews(selectedViews.filter(s =&amp;gt; s !== selected))
    } else {
        // add view
        setSelectedViews([...selectedViews, selected])
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;A href="https://www.w3schools.com/jsref/jsref_includes_array.asp" target="_blank"&gt;https://www.w3schools.com/jsref/jsref_includes_array.asp&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2024 14:27:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/jimulayerviewselector-multi-selection-doesnt-work/m-p/1556795#M15834</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2024-11-08T14:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: JimuLayerViewSelector multi selection doesnt work as expected</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/jimulayerviewselector-multi-selection-doesnt-work/m-p/1556800#M15835</link>
      <description>&lt;P&gt;Again, that wont work because the onChange callback passes in an empty array if anything is deselected.&lt;BR /&gt;&lt;BR /&gt;this :&lt;/P&gt;&lt;PRE&gt;const found = selectedViews.includes(selected)&lt;/PRE&gt;&lt;P&gt;will always return false&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Cant check if its already in my selected array because it doesnt return anything. Its impossible to know , with this component, when a layer is deselected, or at least i havent found a way.&lt;BR /&gt;&lt;BR /&gt;I ended up just recreating the component myself from scratch without using anything from jimu-ui and handling the selection the way i need it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2024 14:42:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/jimulayerviewselector-multi-selection-doesnt-work/m-p/1556800#M15835</guid>
      <dc:creator>IkelosDev</dc:creator>
      <dc:date>2024-11-08T14:42:01Z</dc:date>
    </item>
  </channel>
</rss>

