【问题标题】:Legend load event in ArcGIS JavaScript APIArcGIS JavaScript API 中的图例加载事件
【发布时间】:2020-06-17 00:51:57
【问题描述】:

我正在研究 arcgis 地图 JavaScript API,我想显示带有关闭图标的地图图层图例,但我无法找到图例加载事件来显示相同​​的内容。图例和关闭图标如下图所示。enter image description here

【问题讨论】:

  • 您在使用自定义小部件吗? ..关闭按钮和“加载”事件之间的关系是什么? .. 为什么需要“加载”事件?
  • 我没有使用自定义小部件,仅使用默认图例小部件,但问题是我的客户需要关闭按钮和图例小部件,以便他可以在不关闭图层的情况下关闭它。基本上当图例加载时,我将在图例窗口顶部显示关闭按钮

标签: arcgis-js-api arcgis-online


【解决方案1】:

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

以下脚本取自sample demo

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)
    });
  });

【讨论】:

    猜你喜欢
    • 2014-09-10
    • 2022-01-08
    • 2016-03-16
    • 2016-11-16
    • 2018-10-08
    • 2016-11-23
    • 1970-01-01
    • 2017-10-22
    • 1970-01-01
    相关资源
    最近更新 更多