1

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

rahul
  • 11
  • 3
  • are you using a custom widget? .. what is the relation between the close button and the "load" event? .. why you need the "load" event? – cabesuon Mar 04 '20 at 14:52
  • i am not using custom widget , using default legend widget only , but problem is my client need close button along with legend widget so that he can close it without switching off the layer. basically when legend will load then i am going to show the close button on top to legend window – rahul Mar 06 '20 at 07:32

1 Answers1

0

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)
    });
  });
Below the Radar
  • 7,321
  • 11
  • 63
  • 142