loading indicator & secured feature layers

2031
8
Jump to solution
05-02-2012 08:59 AM
danbecker
Occasional Contributor III
ShowLoadingMessage fires and displays loading animation
dojo.connect(map,"onUpdateStart", ShowLoadingMessage('Loading...'))


HideLoadingMessage fires when the basemap is successfully drawn
dojo.connect(map, "onUpdateEnd", HideLoadingMessage);


identifyManager login then pops up, asking for username/password.

After signing in, the 9 feature layers are then added to map, but it takes a few seconds;

how do I fire my ShowLoadingMessage, then fire HideLoadingMessage when all feature layers are drawn?

I looked through featurelayer events and can't find what I'm looking for.

thanks!
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Frequent Contributor
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.

View solution in original post

0 Kudos
8 Replies
PaulBushore
Occasional Contributor
Hello,


If you had a function that loaded the 9 services, you could have the showloading function fire prior to the load then have an onLayerAdd event listener on the map that would check if the layer being added matches the last layer of your 9 services.  Once it matches you would then fire the hideloading.

I might try to add some code to describe a bit more clearly.

Here is a snippet:
dojo.connect(map, "onLayerAdd", function (layer) { console.log(layer.url + " added"); });

This would give you the url of the layer.

Best wishes,
0 Kudos
danbecker
Occasional Contributor III
thanks paul; that should get me going!
0 Kudos
danbecker
Occasional Contributor III
Here's what I have.
It fires the loading indicator fine, but hides the indicator too soon. It's still several seconds after the indicator is hidden that featLayer3 actually appears on the map...

what could be causing this?

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);
0 Kudos
derekswingley1
Frequent Contributor
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.
0 Kudos
danbecker
Occasional Contributor III
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.


thanks for the reply.

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.

I'll try this out and report back...
0 Kudos
derekswingley1
Frequent Contributor

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.


That's correct. When you create a feature layer, a call is made to the map service layer that will be used for the feature layer to get the layer's metadata. Things like field info, scale dependencies, etc. are retrieved. If you're using ONDEMAND mode, features are retrieved when the layer is added to the map.
0 Kudos
danbecker
Occasional Contributor III
adding the onUpdateEnd listener to the last featLayer that's added to the map seemed to do the trick. I also changed to "ONDEMAND" mode.

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)
});
0 Kudos
derekswingley1
Frequent Contributor
Nice, can you mark my post as an answer?

Edit:  look like you marked this answered, thanks!
0 Kudos