Hello community.
I'm looking to use some javascript script to improve my experience builder application.
I want to create a button to Add layers from one of my Feature Layers service and it works :
const { useState } = React
const Widget = (props: AllWidgetProps<any>) => {
const [jimuMapView, setJimuMapView] = useState<JimuMapView>()
const activeViewChangeHandler = (jmv: JimuMapView) => {
if (jmv) {
setJimuMapView(jmv)
}
}
const formSubmit = (evt) => {
evt.preventDefault()
const layer = new FeatureLayer({
url: 'MYURL'
})
jimuMapView.view.map.add(layer)
}
return (
<div className="widget-starter jimu-widget">
{
props.useMapWidgetIds &&
props.useMapWidgetIds.length === 1 && (
<JimuMapViewComponent
useMapWidgetId={props.useMapWidgetIds?.[0]}
onActiveViewChange={activeViewChangeHandler}
/>
)
}
<form onSubmit={formSubmit}>
<div>
<button>Add Layer</button>
</div>
</form>
I repeat the "formSubmit" const each time I need to create multiple button depending of which layer I want to add on a Map.
But now, I want to allow my users to REMOVE the layers that it was added to the map.
So I try this :
const formSubmit3 = (evt) => {
evt.preventDefault()
jimuMapView.view.map.remove(layer)
}with the same code on the return part to create my button "Remove". But it doesn't work.
I think i don't get one thing of how to use the remove function. I need to use another function to call my previous layers ?
And my second question is : Rather than add/remove Feature Layers, which function can I use to Show/Hide layers from a list of layers ?
Thanks if anyone can help me !