This sample demonstrates how to create and add a CatalogLayer to 3D SceneView. The CatalogLayer points to different portal items and services, helping you to organize and manage your data. It also makes it simpler for users to find information. Instead of manually gathering and adding each dataset separately in your map, you can create a CatalogLayer, a centralized reference point for all the data you need.
CatalogLayer has two types of subLayers which can be accessed via the footprintLayer and the dynamicGroupLayer properties. These two sub
are grouped under the catalog layer, which manages their settings. Every catalog item (layer) in the CatalogLayer has a footprint stored in the footprint
. A footprint is a polygon feature that envelopes the item's features, rasters, and so forth. The dynamic
dynamically updates to display catalog items (layers) in the current view. By default, it draws up to 10 layers at a time.
The catalog layer is initialized as shown below when the application loads:
// Create a new CatalogLayer instance from a portal item
const layer = new CatalogLayer({
portalItem: {
id: "487cc66d305145d3b67fed383456af48",
portal: {
url: "https://jsapi.maps.arcgis.com/"
}
}
});
The CatalogLayerList widget provides a way to display and interact with CatalogLayers. It displays a catalog layer's dynamic group layer. The catalog layer list will be displayed as an expandable ListItem in the LayerList widget. This property is set when a catalog layer's dynamic group layer is expanded in the LayerList.
// create a new LayerList widget and add catalogOptions to display and interact with CatalogLayers
const layerList = new LayerList({
catalogOptions: {
selectionMode: "single"
},
// create a listItemCreatedFunction that adds an "add-layer" action to each catalog layer list item
listItemCreatedFunction: (event) => {
if (event.item.layer.type === "catalog") {
event.item.open = true;
}
if (catalogUtils.isLayerFromCatalog(event.item.layer)) {
event.item.actionsSections = [
[
{
title: "Add layer to map",
icon: "add-layer",
id: "add-layer"
}
]
];
}
},
visibilityAppearance: "checkbox",
view
});
view.ui.add(layerList, "top-right");
Once the layer of interest is located in the catalog layer list, it can be add to the map, by clicking the Add layer to map
button next to the layer. This action creates a new instance of a layer for the given layer in the dynamic
based on its footprint feature. The instance of the footprint feature associated with the layer can be obtained by calling the CatalogLayer's createFootprintFromLayer() method. Then the footprint feature is used to create a new instance of the layer inside the footprint by calling the CatalogLayer's createLayerFromFootprint() method.
// Listen for the trigger-action event on the CatalogLayerListViewModel
// and add layers from the catalog to the map when the "add-layer" action is triggered.
// To correctly add a layer to the map, you must create a footprint from the layer
// and then create a new layer from the footprint.
reactiveUtils.on(
() => layerList.catalogLayerList,
"trigger-action",
async (event) => {
if (event.action.id === "add-layer") {
// Get the parent catalog layer
const parentCatalogLayer = catalogUtils.getCatalogLayerForLayer(event.item.layer);
// Get the footprint from the parent catalog layer
const footprint = parentCatalogLayer.createFootprintFromLayer(event.item.layer);
// Get the layer from the footprint
const layerFromFootprint = await parentCatalogLayer.createLayerFromFootprint(footprint);
// Add the layer to the map
map.add(layerFromFootprint);
}
}
);