dojo.connect(map,"onUpdateStart", ShowLoadingMessage('Loading...'))
dojo.connect(map, "onUpdateEnd", HideLoadingMessage);
Solved! Go to Solution.
dojo.connect(map, "onLayerAdd", function(layer) { //console.log(layer.id); if(layer.id == "featLayer1"){ ShowLoadingMessage('Loading...'); // <-- fires loading indicator } else if (layer.id == "featLayer3"){ HideLoadingMessage(); // <--hides loading indicator } }); var legendLayers = []; var featLayer1 = new esri.layers.FeatureLayer(url11, {id:'featLayer1'}); legendLayers.push({layer:featLayer1,title:"featLayer1"}); var featLayer2 = new esri.layers.FeatureLayer(url22, {id:'featLayer2'}); legendLayers.push({layer:featLayer2,title:"featLayer2"}); var featLayer3 = new esri.layers.FeatureLayer(url33, {id:'featLayer3'}); legendLayers.push({layer:featLayer3,title:"featLayer3"}); var featLayers = []; dojo.forEach(legendLayers,function(layer){ featLayers.push(layer.layer) }); map.addLayers(featLayers);
onLayerAdd fires when a layer is added to the map. A layer being added to the map is not the same as all features being visible on the map.
Ideally, your features would load fast enough that you don't need to show a loading icon. If that's not the case, look at using your layers' onUpdateEnd event. You could set up a listener for this event and then disconnect the listener after the event fires the first time. To do this for multiple layers, you could check each layer's updating property. When all updating is false for all your feature layers, you would hide your loading icon and disconnect your event listener using dojo.disconnect.
I noticed that when the featlayer is added to the map a RestURL/layerID/query? call is made to the server. It looks like the features aren't actually displayed until the query is returned from the server, which in my case takes awhile because some of the featlayers have >1K records.
dojo.connect(map, "onLayerAdd", function(layer) { //console.log(layer.id); if(layer.id == "featLayer1"){ ShowLoadingMessage('Loading...'); // <-- fires loading indicator } }); var handle = dojo.connect(featLayer3, "onUpdateEnd", function(){ createLabels(); HideLoadingMessage(); <--hides load indicator dojo.disconnect(handle) });