+ Reply to Thread
Results 1 to 9 of 9

Thread: loading indicator & secured feature layers

  1. #1
    dan becker
    Join Date
    Apr 2010
    Posts
    182
    Points
    21
    Answers Provided
    3


    0

    Default loading indicator & secured feature layers

    ShowLoadingMessage fires and displays loading animation
    Code:
    dojo.connect(map,"onUpdateStart", ShowLoadingMessage('Loading...'))
    HideLoadingMessage fires when the basemap is successfully drawn
    Code:
    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!

  2. #2
    Paul Bushore
    Join Date
    Apr 2010
    Posts
    65
    Points
    21
    Answers Provided
    3


    0

    Default Re: loading indicator & secured feature layers

    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,
    -----------------------------
    Paul Bushore
    Senior GIS Analyst
    Riley County, KS

  3. #3
    dan becker
    Join Date
    Apr 2010
    Posts
    182
    Points
    21
    Answers Provided
    3


    0

    Default Re: loading indicator & secured feature layers

    thanks paul; that should get me going!

  4. #4
    dan becker
    Join Date
    Apr 2010
    Posts
    182
    Points
    21
    Answers Provided
    3


    0

    Default Re: loading indicator & secured feature layers

    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?

    Code:
    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);
    Last edited by dbecker88; 05-03-2012 at 08:51 AM.

  5. #5
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    893
    Answers Provided
    165


    0
    This post is marked as the answer

    Default Re: loading indicator & secured feature layers

    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.
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

  6. #6
    dan becker
    Join Date
    Apr 2010
    Posts
    182
    Points
    21
    Answers Provided
    3


    0

    Default Re: loading indicator & secured feature layers

    Quote Originally Posted by swingley View Post
    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...

  7. #7
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    893
    Answers Provided
    165


    0

    Default Re: loading indicator & secured feature layers

    Quote Originally Posted by dbecker88 View Post
    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.
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

  8. #8
    dan becker
    Join Date
    Apr 2010
    Posts
    182
    Points
    21
    Answers Provided
    3


    0

    Default Re: loading indicator & secured feature layers

    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.

    Code:
    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)
    });

  9. #9
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    893
    Answers Provided
    165


    0

    Default Re: loading indicator & secured feature layers

    Nice, can you mark my post as an answer?

    Edit: look like you marked this answered, thanks!
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts