Adding Before Load and After Load Events

You can add JavaScript events to occur before and after a map layer is loaded:

  1. Draw an ESRI map component.
  2. Add a map layer.
  3. Open the Properties panel, click the Events icon to open the list of events, and either double-click Before Load or After Load or select Before Load or After Load and click the ellipsis.

    The Embedded JavaScript tab opens with a template for your JavaScript function.

  4. Add your JavaScript code.

Every time a layer is ready, meaning that the layer has all its graphics, the event geometry-complete is fired. The afterload event fires when geometry-complete has fired as many times as there are data layers in the application. The load event fires after base maps and the first layer (if it exists) have been added to the map (not drawn, just added).

There is a time gap between the time the afterload event fires and when you actually see the layer in the map. This time gap is related to the time the map takes to render the layer. So the layer is already in the map, but it has not rendered yet. There is no event that will fire after the layer is finished rendering in the map.