Apply featureEffect to a FeatureLayer

Explore in the sandboxView live

This sample demonstrates how to apply a featureEffect to an instance of a FeatureLayer. FeatureEffect is used to draw attention features of interest by highlighting the features that meet the filter requirements or by dimming the features that do not meet the filter requirements.

In this sample, a HistogramRangeSlider is used to highlight block groups in Phoenix, AZ if they fall within the age range specified by the HistogramRangeSlider's thumb values. As user moves the HistogramRangeSlider thumbs, the application updates the filter property of the layer's featureEffect and applies the following included and excluded effects.

Use dark colors for code blocks
                                                                                                                                          
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />

    <title>Apply featureEffect to a FeatureLayer | Sample | ArcGIS API for JavaScript 4.22</title>

    <link rel="stylesheet" href="https://js.arcgis.com/4.22/esri/themes/dark/main.css" />
    <script src="https://js.arcgis.com/4.22/"></script>

    <style>
      html,
       body,
       #viewDiv {
         padding: 0;
         margin: 0;
         height: 100%;
         width: 100%;
       #controls {
         padding: 15px;
         width: 380px;
      #description {
        padding: 10px 10px 0px 10px;
        font-size: 14pt;
      .esri-histogram-range-slider .esri-slider .esri-slider__anchor .esri-slider__label {
        display: inline;
    </style>

    <script>
      require([
        "esri/views/MapView",
        "esri/WebMap",
        "esri/widgets/HistogramRangeSlider",
        "esri/smartMapping/statistics/histogram",
        "esri/widgets/Legend",
        "esri/widgets/Expand"
      ], (MapView, WebMap, HistogramRangeSlider, histogram, Legend, Expand) => {
        const map = new WebMap({
          portalItem: {
            id: "f3551252973c41fa868c08edceb504e6"
        const view = new MapView({
          map: map,
          container: "viewDiv"
        map.loadAll().then(async () => {
          // get the phoenix featurelayer from the webmap
          const layer = map.layers.getItemAt(0);
          layer.effect = null;
          applyFeatureEffect(layer, "MEDAGE_CY BETWEEN 25 AND 35");
          const histogramResponse = await histogram({
            layer: layer,
            field: field,
            numBins: 80,
            minValue: min,
            maxValue: max
        // medium age min, max to be used by the histogram range
        // slider bins
        const min = 18;
        const max = 80;
        const field = "MEDAGE_CY";
        const slider = new HistogramRangeSlider({
          min: min,
          max: max,
          values: [25, 35],
          excludedBarColor: "#524e4e",
          rangeType: "between",
          container: document.getElementById("slider-container")
        // this function is called when the map is loaded
        // then when user changes the histogram range slider thumbs
        function applyFeatureEffect(layer, where){
          layer.featureEffect = {
            filter: {
              where
            },
            includedEffect: "bloom(0.9 0.6pt 0)",
            excludedEffect: "blur(2.25pt) opacity(0.5)"
          };
        }

        // apply a feature effect to highlight the block groups that
        // fall within the age range
        slider.on(["thumb-change", "thumb-drag", "segment-drag"], (event) => {
          const layer = map.layers.getItemAt(0);
          applyFeatureEffect(layer, slider.generateWhereClause(field))
        });
        view.ui.add("controls", "bottom-left");
        // add a legend for the Phoenix block groups layer
        const legendExpand = new Expand({
          expandTooltip: "Legend",
          content: new Legend({
          expanded: false
        view.ui.add(legendExpand, "top-left");
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
    <div id="controls" class="esri-widget">
      <div id="description" class="esri-widget">Phoenix Average Age (2015-2020)</div>
      <div style="padding: 5px 10px 0px 10px" class="esri-widget">by block groups</div>
      <div id="outer-container" class="esri-widget">
        <div id="slider-container"></div>
      </div>
    </div>
  </body>
</html>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.