This sample demonstrates how a scale dependent drop-shadow feature effect set on a FeatureLayerView can be used to highlight counties where the winning party in a presidential election flipped from the previous election.

This map has two feature layers that show the winning parties by county in the 2012 and 2016 presidential elections. References to those layers and their layer views are set once the map component is ready. Once each layer view is initialized, we set a scale dependent feature effect on each one to highlight the counties where the winning party flipped for the presidential election that year.

Selecting a year from the upper corner of the map toggles between the 2012 and 2016 election layers and updates the party switch statistics shown in the map.

// get 2012 and 2016 election layers when the view is initialized
// setup feature effects on the corresponding layer views
// 2016 election layer
const layer16 = viewElement.map.layers.items[0];
const layer16View = await viewElement.whenLayerView(layer16);
applyFilter(layer16View, "F2012_to_2016_Party_Switch");
// 2012 election layer
const layer12 = viewElement.map.layers.items[1];
const layer12View = await viewElement.whenLayerView(layer12);
applyFilter(layer12View, "F2008_to_2012_Party_Switch");
// apply a scale dependent drop-shadow effect to counties where
// the winning party changed from the previous election
function applyFilter(layerView, field) {
const featureFilter = {
where: `${field}='R' OR ${field}='D'`,
};
// set scale dependent drop-shadow effects on election results featurelayers
layerView.featureEffect = {
filter: featureFilter,
includedEffect: [
{
scale: 36978595,
value: "drop-shadow(3px, 3px, 4px)",
},
{
scale: 18489297,
value: "drop-shadow(2px, 2px, 3px)",
},
{
scale: 4622324,
value: "drop-shadow(1px, 1px, 2px)",
},
],
};
}