0

I would like to fire the following two execute statements with one variable using javascript/dojo.

identifyTaskParcels.execute(identifyParams);
identifyTaskZoning.execute(identifyParams);

I have tried various variations of:

var deferred = [identifyTaskParcels.execute(identifyparams), identifyTaskZoning.execute(identifyParams)];

Is this something that is possible to do?

Edit

I'm trying to build a web mapping application that pulls info from 2 services and presents them in an infowindow/popup with feature info.

Its easy to do with 1 service, but I'm finding it hard to do with 2. Example of code that works:

EDIT 2

    dojo.require("esri.dijit.Popup"); //Infowindow

var identifyTask,identifyParams;    

      function mapReady(map){

       dojo.connect(map,"onClick",executeIdentifyTask);

       //create identify tasks and setup parameters 
       identifyTaskZoning = new esri.tasks.IdentifyTask("https:path/to/url/service");
       identifyTaskParcels = new esri.tasks.IdentifyTask("https://path/to/url/service");

            //Set Zoning Parameters
       identifyParamsZoning = new esri.tasks.IdentifyParameters();
       identifyParamsZoning.tolerance = 3;
       identifyParamsZoning.returnGeometry = true;
       identifyParamsZoning.layerIds = [0,1,2,3,4];
       identifyParamsZoning.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
       identifyParamsZoning.width  = map.width;
       identifyParamsZoning.height = map.height;
            //Set Parcel Parameters
       identifyParamsParcels = new esri.tasks.IdentifyParameters();
       identifyParamsParcels.tolerance = 3;
       identifyParamsParcels.returnGeometry = true;
       identifyParamsParcels.layerIds = [0,1,2,3,4];
       identifyParamsParcels.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
       identifyParamsParcels.width  = map.width;
       identifyParamsParcels.height = map.height;

       //resize the map when the browser resizes
       dojo.connect(dijit.byId('map'), 'resize', map,map.resize);
      };

   function executeIdentifyTask(evt){
     identifyParamsParcels.geometry = evt.mapPoint;
     identifyParamsParcels.mapExtent = map.extent;
     var deferred = identifyTaskParcels.execute(identifyParamsParcels);
     deferred.addCallback(function(response){
       if (response.length > 0) {
//         console.log(response.length)
//         response is an array of identify result objects    
//         Let's return an array of features.
        return dojo.map(response, function(result){
          var feature = result.feature;
          feature.attributes.layerName = result.layerName;
          if(result.layerName === 'TaxParcel'){
              console.log(feature.attributes.NAME);
              var template = new esri.dijit.PopupTemplate({
                            title:"Parcels",
                            description:"<b>Parcel ID:</b> {Parcel Identification Number} <br/> <b>Address:</b> {Site Address}"
                            });
              feature.setInfoTemplate(template);
            }

                return feature;
        });
        }
      else {
          identifyParamsZoning.geometry = evt.mapPoint;
          identifyParamsZoning.mapExtent = map.extent;
          var deferred = identifyTaskZoning.execute(identifyParamsZoning);
          deferred.addCallback(function(response){
            // response is an array of identify result objects    
            // Let's return an array of features.
            return dojo.map(response, function(result){
              var feature = result.feature;
              feature.attributes.layerName = result.layerName;
            if(result.layerName === 'Zoning Classifications'){
              console.log(feature.attributes.NAME);
              var template = new esri.dijit.PopupTemplate({
                            title:"Zoning",
                            description:"<b>Zoning:</b> {Zoning Classification} <br/> <b>Description:</b> {Zoning Description}"
                            });
              feature.setInfoTemplate(template);
            }
            else if (result.layerName === 'Assisted Living Facilities'){
              var template = new esri.dijit.PopupTemplate({
                            title:"Assisted Living Facilities",
                            description:"<b>Parcel ID:</b> {Parcel} <br/> <b>Applicant:</b> {BusinessApplicantName} <br/> <b>No. of Residents</b> {NbrResidents}"
                            });
              feature.setInfoTemplate(template);
            }
                        else if (result.layerName === 'Family Divisions'){
              var template = new esri.dijit.PopupTemplate({
                            title:"Family Divisions",
                            description:"<b>Parcel ID:</b> {Parcel} <br/> <b>Project Number:</b> {project_nbr} </br> <b>Status:</b> {Status}"
                            });
              feature.setInfoTemplate(template);
            }
                        else if (result.layerName === 'Policy 120'){
              var template = new esri.dijit.PopupTemplate({
                            title:"Policy 120",
                            description:"<b>Parcel ID:</b> {Parcel} <br/> <b>Business Name:</b> {BusinessName} </br> <b>Date of Letter:</b> {DateOfLetter}"
                            });
              feature.setInfoTemplate(template);
            }
                        else if (result.layerName === 'Zoning Changes'){
              var template = new esri.dijit.PopupTemplate({
                            title:"Zoning Changes",
                            description:"<b>Parcel ID:</b> {Parcel} <br/> <b>Request Number:</b> {REQUEST_NBR} </br> <b>Property Owner:</b> {PROPERTY_OWNER}"
                            });
              feature.setInfoTemplate(template);
            }
            return feature;
            });
          });
      };
        map.infoWindow.setFeatures([deferred]);
        map.infoWindow.show(evt.mapPoint);          
      });
        map.infoWindow.setFeatures([deferred]);
        map.infoWindow.show(evt.mapPoint);      
      };
Craig
  • 229
  • 5
  • 20
  • Please read: [http://stackoverflow.com/questions/4908378/javascript-array-of-functions](http://stackoverflow.com/questions/4908378/javascript-array-of-functions) – Yair Nevet Jan 30 '13 at 20:04

1 Answers1

1

I am not sure I understand the question, but it seems you need dojo/promise/all:

require(["dojo/Deferred", "dojo/promise/all"], function(Deferred, all) {

    var taskParcels = new Deferred();
    var taskZoning = new Deferred();

    var deferred = all([taskParcels, taskZoning])

    deferred.then(function(result) {
        console.log(result);
    });

    taskParcels.resolve('hello');  
    setTimeout(function() {
        taskZoning.resolve('world');
    }, 1000);

});

See it in action: http://jsfiddle.net/phusick/S3b4B/

phusick
  • 7,342
  • 1
  • 21
  • 26
  • Thanks. I edited to include info on what I'm trying to accomplish – Craig Jan 30 '13 at 20:42
  • Does it mean you need to combine two or more deferreds to fire single callback? If so, the aforementioned example is what you are looking for, but it works only in Dojo 1.8. You can achieve the same via `dojo/DeferredList` for previous versions of Dojo: `var deferred = new DeferredList([identifyTaskParcels.execute(identifyparams), identifyTaskZoning.execute(identifyParams)]); deferred.addCallback(function(result) { /* this is executed only after both deferreds are resolved */ });` I modified the [jsFiddle](http://jsfiddle.net/phusick/S3b4B/) to employ `DeferredList`. – phusick Jan 30 '13 at 21:03
  • Makes sense to use that, however, it now gives me: SCRIPT445: Object doesn't support this action , at the front of the callback line. – Craig Jan 30 '13 at 21:27
  • I'm not able to identify what is going wrong there. I rewrote the code to legacy Dojo to make sure it works and it does (in IE9 too). Maybe it will help: http://jsfiddle.net/phusick/9xBfX/ – phusick Jan 30 '13 at 21:40
  • well I appreciate your help. I must be going about it the wrong way, your code works and answers my question, just doesn't solve my problem. Again, thanks for the effort. – Craig Jan 31 '13 at 13:32
  • I was thinking and was able to write something that returns a popup from both services, just not at the same time. It is edited above. The "zoning" code shows up when clicked on map load at the original scale, the "parcels" code shows up when zoomed to the right scale. However, I would like both to return results? I feel like I'm really close to getting this figured out. – Craig Jan 31 '13 at 14:53