How to specify layer with layer-add-result event?

7483
5
Jump to solution
11-06-2014 09:33 AM
SimonHodge
New Contributor III

The ArcGIS JavaScript API Map object has the following two events (text taken from the API):

layer-add

Fires any time a layer is added to the map. Should be used in favor of onLayerAdd. (Added at v3.5)

layer-add-result

Fires after specified layer has been added to the map. Should be used in favor of onLayerAddResult. (Added at v3.5)

layer-add does exactly what it says: fires every time a layer is added.  However, layer-add-result says it will fire after specified layer has been added.  How do you specify the layer to trigger this event to fire?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Simon,

Here is an example:

     var map;

      require([

        "esri/map", "esri/layers/FeatureLayer",

        "dojo/on", "dojo/domReady!"

      ], function(

        Map, FeatureLayer,

        on

      ) {

        map = new Map("mapDiv", {

          basemap: "streets",

          center: [-81.792107, 26.150807],

          zoom: 8

        });

       

        on(map, "layer-add-result", function(){

          console.log(featureLayer)

        })      

       

        var featureLayer = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0",{

            mode: FeatureLayer.MODE_ONDEMAND,

            outFields: ["*"]

        }); 

       

        map.addLayer(featureLayer);               

      });

View solution in original post

0 Kudos
5 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Simon,

Here is an example:

     var map;

      require([

        "esri/map", "esri/layers/FeatureLayer",

        "dojo/on", "dojo/domReady!"

      ], function(

        Map, FeatureLayer,

        on

      ) {

        map = new Map("mapDiv", {

          basemap: "streets",

          center: [-81.792107, 26.150807],

          zoom: 8

        });

       

        on(map, "layer-add-result", function(){

          console.log(featureLayer)

        })      

       

        var featureLayer = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0",{

            mode: FeatureLayer.MODE_ONDEMAND,

            outFields: ["*"]

        }); 

       

        map.addLayer(featureLayer);               

      });

0 Kudos
SimonHodge
New Contributor III

Hi Jake,

Thanks for a quick answer.  However, I don't see how that differs to the layer-add event - it looks like it will be fired every time a layer is added but the API says it is fired when a specified layer is added.

Simon

0 Kudos
SteveCole
Frequent Contributor

Second result when searching for "layer-add-result" within the JS API Space-

https://community.esri.com/message/93134#93134

SimonHodge
New Contributor III

Yeah, I came across that too after I'd asked the question, but thought I'd leave my question up in case things have changed since then.  It doesn't look like they have and so I think it's just a case that the notes in the API are just a bit ambiguous.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

If it matters, I would mark Steve's answer as correct.  The link he sent answers your question more directly.

0 Kudos