Using ExB DE v.1.15.0
I'm currently working on a custom widget that needs to select multiple layers and get their IDs in a string array. The JimuLayerViewSelector component seemed like a suitable choice because it allowed selecting multiple layers with its isMultiSelection attribute
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 .
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.
This is my code currently:
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<any>) => {
const [jimuMapViewId, setJimuMapViewId] = useState<string>()
const [selectedMapLayers, setSelectedMapLayers] = useState<string[]>()
const activeViewChangeHandler = (jmv: JimuMapView) => {
if (jmv) {
setJimuMapViewId(jmv.id)
}
}
const onMapLayerSelected = (selectedLayerViewIds: string[]) => {
//selectedLayerViewIds only contains the last selection, or empty if you
//de-selected a layer
console.log(selectedLayerViewIds);
setSelectedMapLayers(selectedLayerViewIds)
}
return (
<div className="jimu-widget">
{props.useMapWidgetIds && props.useMapWidgetIds.length === 1 && (
<JimuMapViewComponent useMapWidgetId={props.useMapWidgetIds?.[0]} onActiveViewChange={activeViewChangeHandler} />
)}
{jimuMapViewId ? (
<JimuLayerViewSelector jimuMapViewId={jimuMapViewId} isMultiSelection={true} onChange={onMapLayerSelected} />
) : (<Loading />)}
</div>
)
}
export default Widget