Skip to content

This sample demonstrates how to use the Smart Mapping renderer creators to generate a renderer for a Sublayer created from a dynamic data layer. The dynamic layer joins ancestry data from a table in a dynamic workspace to a map service layer. Select elements are provided to the user, allowing him/her to dynamically change the renderer based on different ancestry variables and classification methods.

To generate a renderer using the Smart Mapping creator methods, you must first create a FeatureLayer using the same data source as the Sublayer. The createFeatureLayer() method is a convenience method for creating matching FeatureLayer instances from Sublayers.

// Get the sublayer to explore
const ancestrySublayer = layer.sublayers.find((sublayer) => {
return sublayer.title === "% population with selected ancestry";
});
ancestrySublayer.createFeatureLayer().then((ancestryFeatureLayer) => {
// use the feature layer instance for some other purpose,
// such as generating a renderer
});

Use the FeatureLayer instance to generate the renderer. Then set the output renderer back on the Sublayer instance.

const params = {
// set FeatureLayer as input
layer: ancestryFeatureLayer,
// Arcade is used to normalize and round the data
valueExpression: "Round( ( $feature['" + ancestrySelect.value + "'] / $feature['states.POP2007'] ) * 100, 1);",
view: viewElement.view, // required with valueExpression
classificationMethod: classSelect.value,
};
colorRendererCreator.createClassBreaksRenderer(params).then((response) => {
// set the renderer on the sublayer
ancestrySublayer.renderer = response.renderer;
});

The select elements are placed within the Layer List component’s panel content. Note that individual list items can contain multiple content items within the same panel. In this case, we add an array of content items: (1) the Card element containing the two select elements, and (2) a Legend component.

Use listItemCreatedFunction to add a panel containing the two select elements and a legend
// Set Layer List with two content elements in the same content panel
// 1. An element containing the select elements for data exploration
// 2. A legend instance
const layerListElement = document.querySelector("arcgis-layer-list");
layerListElement.listItemCreatedFunction = function (event) {
const item = event.item;
item.panel = {
content: [document.getElementById("selectCard"), document.querySelector("arcgis-legend")],
open: true,
};
};

A word of caution

Keep in mind that generating renderers should be avoided in most applications because of the performance cost affecting the end user. As stated in the Smart Mapping guide topic, the Smart Mapping APIs were designed for two types of applications: data exploration apps and visualization authoring apps similar to ArcGIS Online. In all other cases, renderers should be saved to the layer or manually created using any of the renderer classes.