将阴影效果应用于图层视图

尝试一下在线预览

此示例演示了如何使用在 FeatureLayerView 上设置的与比例相关的 drop-shadow 要素效果来突出显示总统选举中获胜政党与上次选举相反的县。

此地图有两个要素图层,按县显示 2012 年和 2016 年总统选举中的获胜政党。加载 webmap 后,就会设置对这些图层及其图层视图的引用。初始化每个图层视图后,我们会在每个图层上设置一个与比例相关的要素效果,以突出显示获胜党在当年总统选举中翻转的县。

                                            
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
// get 2012 and 2016 election layers when the view is initialized
// setup feature effects on the corresponding layer views
view.when().then(() => {
  // 2016 election layer
  const layer16 = webmap.layers.items[0];
  view.whenLayerView(layer16).then( (lv) => {
    applyFilter(lv, "F2012_to_2016_Party_Switch");
  });

  // 2012 election layer
  const layer12 = webmap.layers.items[1];
  view.whenLayerView(layer12).then( (lv) => {
    applyFilter(lv, "F2008_to_2012_Party_Switch");
  });

  // this function is called when layerViews are loaded
  // for 2012 and 2016 election results layers and called
  // once to set up the effects on the layer views to set
  // drop-shadow effect on counties where the winning parties
  // 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)"
        }
      ]
    };
  }
});

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