This sample demonstrates how to apply a scale-dependent display filter to a feature layer containing approximately 2.7 million lines representing streams and rivers across the United States. Display filters can be applied to a feature layer and control the visibility of features on the map. It enables you to show only a subset of features while maintaining full access for querying and analysis.
In this case, a scale-dependent filter is used to display only major rivers (such as the Mississippi or Missouri) at smaller zoom levels, providing an overview of the national river network. As the user zooms in, the filter dynamically shows smaller rivers and tributaries too detailed to display at larger scales. This approach improves map performance and reduces visual clutter, ensuring a more efficient and user-friendly experience.
// set a scale dependent display filter for the rivers layer
const layer = new FeatureLayer({
portalItem: {
id: "5fbbf39fe52f4cf88c95cce1223a09dd"
},
minScale: 0,
maxScale: 0,
outFields: ["streamOrder"],
displayFilterInfo: {
mode: "scale",
filters: [
{
title: "streamOrder >= 8",
minScale: 0,
maxScale: 36_978_595.474_472,
where: "streamOrder >= 8"
},
{
title: "streamOrder >= 7",
minScale: 36_978_595.474_472,
maxScale: 18_489_297.737_236,
where: "streamOrder >= 7"
},
{
title: "streamOrder >= 6",
minScale: 18_489_297.737_236,
maxScale: 4_622_324.434_309,
where: "streamOrder >= 6"
},
{
title: "streamOrder >= 5",
minScale: 4_622_324.434_309,
maxScale: 1_155_581.1_085_775,
where: "streamOrder >= 5"
},
{
title: "all",
minScale: 1_155_581.1_085_775,
maxScale: 0
}
]
}
});