1

I am executing an IdentifyTask and then using dojo array.map to create an array of Features to pass to an InfoWindow. The stripped down version of my code follows.

        var deferred = identifyTask.execute(identifyParkParams);
        deferred.then(function (response) {
            featureArray = array.map(response, function (result) {
               if(test1){
                  testTemplate = new InfoTemplate(stuff1);
               } else {
                  featureLayer.selectFeatures(query, function(featureSet){
                    //processing code
                      testTemplate = new InfoTemplate(stuff2);
                      }
               }
            feature.setInfoTemplate(testTemplate);
            return feature;
                });
                return featureArray;
            }).then(function(featureArray){
                    app.map.infoWindow.setFeatures(featureArray);
            });

My issue is if test1 is false the array.map puts a null testTemplate in the feature instead of waiting until the selectFeatures is done processing.

2

Your issue is that the featureLayer.selectFeatures() method returns a promise. So you have to wait till the promise is resolved to set the Info Template. It is nothing related with dojo.map. The same as you are doing in the identifyTask.Execute() method. Something like this (I did not test it!):

var deferred = identifyTask.execute(identifyParkParams); deferred.then(function (response) { featureArray = array.map(response, function (result) { if(test1){ testTemplate = new InfoTemplate(stuff1); feature.setInfoTemplate(testTemplate); return feature; } else { featureLayer.selectFeatures(query, function(featureSet){ //processing code testTemplate = new InfoTemplate(stuff2); feature.setInfoTemplate(testTemplate); return feature; } } }); return featureArray; }).then(function(featureArray){ app.map.infoWindow.setFeatures(featureArray); });

Another solution would be to implement dojo.all (see more info here).

I hope it helps =)

|improve this answer|||||
  • I tried putting the return feature in a .then() clause of the featureLayer.selectFeatures() but the array.map finished processing anyway. Maybe I did something else wrong. If you use array.map without a return does it wait forever? – ponder275 Oct 16 '17 at 0:09
  • 1
    If you do not have a return, then the returned array will be empty =). Try to do it simple. Why not just do 2 different mappings, one if test 1 is true, another if ti is false? Just make it working. Then you can just think about a better implementation. A nice solution would be using dojo.when to let the synchronous and asynchronous calls be handled in the same way. You have to wait till the testTemplate object is filled, whether that is using stuff1 or stuff 2. After that, call setInfoTemplate and return the Feature – Katah Oct 16 '17 at 9:03
0

I wound up using array.forEach and manually creating an array of Features with pop-up window templates.

identifyTask.execute(identifyParams, function(response){
    var featuresWithTemplates = [];
    arrayUtils.forEach(response, function (result, index) {
        var feature = result.feature;
        var infoTemplate = new InfoTemplate();
        feature.attributes.layerName = result.layerName;
        infoTemplate.setTitle(createInfoTitle(feature.attributes.layerName));
        createInfoContent(feature).then(lang.hitch(this, function(contentString){
            infoTemplate.setContent(contentString);
            feature.setInfoTemplate(infoTemplate);
            featuresWithTemplates.push(feature);
            if(index === response.length - 1){
                if(featuresWithTemplates.length != 0){
                    app.map.infoWindow.setFeatures(featuresWithTemplates);
                }
            }
        }));
    });
});


function createInfoContent(feature){
    var deferredContentString = new Deferred();
    if(test1){
        deferredContentString.resolve(getTrailPointsOfInterestContent(feature));
    } else{
        getBlazeTextContent(feature).then(function(string){
            deferredContentString.resolve(string);
        });
    }
    return deferredContentString;
}

function getBlazeTextContent(feature){
    var deferredBlazeColorString = new Deferred();
    var queryParams = initializeBlazeQueryParameters(feature);
    var blazeColorLayer = app.map.getLayer("blazeColor1");
    blazeColorLayer.queryFeatures(queryParams, function(featureSet) {
        dojoXhr("/trails/trailPopupUses.action",{
            query:{
                parkName: PARK_NAME,
                trailName: TRAIL_ASSOC,
            },
            preventCache: true,
            sync: true
        }).then(function(data){

            var blazeColorString =  "long string is here"
            deferredBlazeColorString.resolve(blazeColorString);
        });
    });
    return deferredBlazeColorString;
};
|improve this answer|||||
  • It seems to resolve the topic, congratulations! – Katah Oct 18 '17 at 12:14

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.