1

我正在研究 arcgis 地图 JavaScript API,我想显示带有关闭图标的地图图层图例,但我无法找到图例加载事件来显示相同​​的内容。图例和关闭图标如下图所示。在此处输入图像描述

4

1 回答 1

0

mapview.ui将图例小部件的 dom 节点添加到图例小部件的container属性后,您可以访问它。

下面的这个脚本取自一个示例演示

require([
    "esri/views/MapView",
    "esri/widgets/Legend",
    "esri/WebMap"
  ], function(MapView, Legend, WebMap) {
    var webmap = new WebMap({
      portalItem: {
        // autocasts as new PortalItem()
        id: "4abe6a830b8f466dacf8abfde567a781"
      }
    });

    var view = new MapView({
      container: "viewDiv",
      map: webmap
    });

    view.when(function() {
      // get the first layer in the collection of operational layers in the WebMap
      // when the resources in the MapView have loaded.
      var featureLayer = webmap.layers.getItemAt(0);

      var legend = new Legend({
        view: view,
        layerInfos: [
          {
            layer: featureLayer,
            title: "NY Educational Attainment"
          }
        ]
      });

      // Add widget to the bottom right corner of the view
      view.ui.add(legend, "bottom-right");

      //Now you can access the legend domNode and add a close button
      console.log(legend.container)
    });
  });
于 2020-03-09T13:31:20.883 回答