将图例添加到 LayerList

尝试一下在线预览

此示例演示如何将图例微件实例添加到 LayerList 微件。这是通过将 legend 字符串添加到 LayerList 微件中相应 ListItem面板来完成的。

                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Add a legend instance to the panel of a
// ListItem in a LayerList instance
const layerList = new LayerList({
  view: view,
  listItemCreatedFunction: (event) => {
    const item = event.item;
    if (item.layer.type != "group") {
      // don't show legend twice
      item.panel = {
        content: "legend",
        open: true
      };
    }
  }
});
view.ui.add(layerList, "top-right");

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