Select to view content in your preferred language

FeatureLayer events??? Which one fires when load / drawing complete?

3128
5
Jump to solution
10-30-2013 09:15 AM
DerrickMartin
Emerging Contributor
I'm adding a FeatureLayer to a map and setting the definitionExpression for the layer. What I want is to zoom to the features that are loaded. I can't seem to find the event that is fired when the loading / drawing of the layer is complete. I've tried both the load and the update-end events, but it seems both of them are getting fired before the features are actually on the map. Any ideas?
0 Kudos
1 Solution

Accepted Solutions
JasonZou
Frequent Contributor
To prevent the recursive loop, use a flag variable, like below.


  1. var bolDefExpSet = false;

  2. set bolDefExpSet to true right after featureLayer.setDefinitionExpression.

  3. map.on("update-end", function() {

  4.     if (bolDefExpSet) {
            // set map extent to the feature layer feature extent
            map.setExtent(...);

            // reset bolDefExpSet to prevent the recursive loop
            bolDefExpSet = false;       
        }
    });

View solution in original post

0 Kudos
5 Replies
KenBuja
MVP Esteemed Contributor
Have you tried using the map's update-end event?
0 Kudos
DerrickMartin
Emerging Contributor
I tried that, but since I do a map.setExtent based on the extent of the features, it gets stuck in a loop, where the update-end fires, I do the zoom, which then triggers another map update�?�

Maybe I should re-word my question as�?� How to zoom to the extent of a feature layer after applying a definition expression?
0 Kudos
JasonZou
Frequent Contributor
To prevent the recursive loop, use a flag variable, like below.


  1. var bolDefExpSet = false;

  2. set bolDefExpSet to true right after featureLayer.setDefinitionExpression.

  3. map.on("update-end", function() {

  4.     if (bolDefExpSet) {
            // set map extent to the feature layer feature extent
            map.setExtent(...);

            // reset bolDefExpSet to prevent the recursive loop
            bolDefExpSet = false;       
        }
    });
0 Kudos
DerrickMartin
Emerging Contributor
Thank you! Using the Ken's idea for update-end and zj's idea to stop the looping this is now working.
Too bad I can't give both of you the correct answer 😞
0 Kudos
by Anonymous User
Not applicable
If you only want the function to run once you can use the dojo on.once() method. Using what zj wrote:

map.on.once("update-end", function() {
    // set map extent to the feature layer feature extent
    map.setExtent(...);   
    }
});
0 Kudos