I am creating an application using arcgis javascript api. I placed my basemap gallery in an expand and I would like to do the same with my layer list. How do I add my layerlist to an expand?.
This is how I did my basemap gallery:
const basemapGallery = new BasemapGallery({
view: view,
});
// Create an Expand instance and set the content
// property to the DOM node of the basemap gallery widget
// Use an Esri icon font to represent the content inside
// of the Expand widget
const bgExpand = new Expand({
view: view,
content: basemapGallery
});
// close the expand whenever a basemap is selected
basemapGallery.watch("activeBasemap", () => {
const mobileSize = view.heightBreakpoint === "xsmall" || view.widthBreakpoint === "xsmall";
if (mobileSize) {
bgExpand.collapse();
}
});
// Add the expand instance to the ui
view.ui.add(bgExpand, "top-left");
Is exactly the same as you did with the basemap gallery, in this case the content will be the layer list.
In the code below I slightly change and ESRI layer list example (ArcGIS JS Samples - LayerList) it to include the expand.
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
<title>
LayerList widget | Sample | ArcGIS Maps SDK for JavaScript 4.26
</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.26/esri/themes/light/main.css" />
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
</style>
<script src="https://js.arcgis.com/4.26/"></script>
<script>
require([
"esri/views/SceneView",
"esri/widgets/LayerList",
"esri/WebScene",
"esri/widgets/Expand"
], (SceneView, LayerList, WebScene, Expand) => {
const scene = new WebScene({
portalItem: {
// autocasts as new PortalItem()
id: "adfad6ee6c6043238ea64e121bb6429a"
}
});
const view = new SceneView({
container: "viewDiv",
map: scene
});
view.when(() => {
const layerList = new LayerList({
view: view
});
const expand = new Expand({
view: view,
content: layerList
});
// Add widget to the top right corner of the view
view.ui.add(expand, "top-right");
});
});
</script>
</head>
<body class="calcite">
<div id="viewDiv"></div>
</body>
</html>