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)
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?
Solved! Go to Solution.
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);
});
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);
});
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
Second result when searching for "layer-add-result" within the JS API Space-
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.
If it matters, I would mark Steve's answer as correct. The link he sent answers your question more directly.