View layers toggle

This widget demonstrates how to create a dropdown toggle to allow viewing different layers on the map.

How to use the sample

Clone the sample repo and copy this widget's folder (within widgets) to the client/your-extensions/widgets folder of your Experience Builder installation.

How it works

Within widget.tsx, in the render() function, the layers are added to the dropdown <select>:

{this.props.config.layerUrls.map((url) => {
  return <option value={url}>{url}</option>;
})}

The onChange handler is setup to call the selectChangeHandler() function when the selected value changes.

A reference to the Map object is acquired using the JimuMapViewComponent module, and that reference is used in the selectChangeHandler() function to add the selected layer to the map:

// Create and add the new Feature Layer
const featureLayer = new FeatureLayer({
  url: evt.target.value,
});
this.state.jimuMapView.view.map.add(featureLayer);

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close