0

35 years coding but new to GIS leaflet and Esri.leaflet. Javascript I can do but it is not one my long term primary languages. I am trying to make a query result available for processing after some dependencies are taken care of. cQuery here is pre-defined using L.esri.Query using layer 14 of the service it is pointed at.

var rslt;
cQuery.run(function (error, fset) {
    // if (error) display alert, return
    rslt = fset;

    if (fset.features.length = 0 && check2ndLayer) {
        cQuery.layer(15).run(function (error, fset2) {
            // same thing here for error
            rslt = fset2;
        });
    };

    // A
});

// B

The code runs but...inserting some alerts I have determined layer 14 query completes, condition to run query for 15 engages. Code placed at "A" can process "fset" or "rslt" and does so if layer 14 found something. If not, code runs past there and then I get the indicator that the layer 15 query has found something to process but it never does. What I want is to end up with one featureCollection in "rslt" and process that at "B" but no matter what I do "rslt" seems to always be undefined at that point.

What am I doing incorrectly?

0

Well, a local-ish resource enlightened me. Due to the asynchronous nature of the query.run (callback) I cannot do what I was trying to do. Instead it is necessary to define a function to do what I want to do at point B and call that function from inside each of the callback functions here passing the feature collection to said function. Works great.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.