简体   繁体   中英

Legend load event in ArcGIS JavaScript API

I am working on arcgis map JavaScript API and i want to show map layer legend with close icon but i am unable to find legend load event to show the same. Legend along with close icon is shown in below image. enter image description here

You can access the dom node of the legend widget after it was added to the mapview.ui with the container property of the legend widget.

This script below was taken from a 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)
    });
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM