Select to view content in your preferred language

filter identify response

585
1
07-02-2012 10:50 AM
danbecker
Frequent Contributor
the executeIdentifyTask function is fired from either a map click or grid row click.

Since the executeIdentifyTask is responsible for identifying/formatting/displaying popups, I'd like to use the existing executeIdentifyTask to display a popup after a grid row click.

If a grid click, I want to display the popup, stripping out any close-by identify results that may have been included.

If grid click, I lower the identifyParams.tolerance, but I still pickup a few unwanted results around the facility point geometry that was grid-clicked

dojo.connect(grid1, "onRowClick", onRowClickHandler);
dojo.connect(map,"onClick",executeIdentifyTask);

function onRowClickHandler(evt){
       var selectedFac;
       //other non-pertinent code
       map.centerAndZoom(selectedFac.geometry, 15);
       executeIdentifyTask(selectedFac);
}


function executeIdentifyTask(evt) {

       var lids = []; //array to hold layer id's to identify
       var anchorPt; //facility point, substitute for a mouse click
       var siteCode; //id for the grid row that was clicked
       var j; //index of response object that was grid clicked
       var res; //filtered array of response objects

       //lets detect if this was fired by a map click or a grid click

 if (evt.mapPoint == undefined){
  //grid click, only identify the facility point corresponding to the grid row that was clicked i.e. lower identify tolerance
                identifyParams.tolerance = 1;
  anchorPt = evt.geometry;
  siteCode = evt.attributes.site_code;
                //set lids to include only facil layer
  lids.push(0);
 }

        identifyParams.layerIds = lids;
        var deferred = identifyTask.execute(identifyParams);
        deferred.addCallback(function(response) {
                if (!(siteCode == undefined)){
   for (var i in response){
    var fac = response;
    if (fac.feature.attributes.site_code == siteCode){
     j = i;
     break;     
    }
   }
   res = response;
  }
  else{
                        //no filtering the identify response; this was fired by map click
   res = response;
  }
                
                return dojo.map(res, function(result) {
                        //if res is set to response, script never gets here, ends at break above <----problem        
   var feature = result.feature;
                        //esri.dijit.PopupTemplate's set here
                        return feature;
                }
        })
}


any advice would be great! Thanks.
0 Kudos
1 Reply
danbecker
Frequent Contributor
after some brainstorming, I decided to do away with the identifyTask and replace it with a findTask when a grid row click is detected. The existing code to process the response can remain exactly the same since both the identifyTask and findTask returns a dojo.deferred

incase anyone's interested, here's the solution:

function executeIdentifyTask(evt) {
    if (evt.mapPoint == undefined){
 //grid click, lets switch to a find task
 anchorPt = evt.geometry;
 siteCode = evt.attributes.site_code[0];
 lids.push(0);   
 var findTask2 = new esri.tasks.FindTask("https://mydomain.com/MapServer/");
 var fParams = new esri.tasks.FindParameters();
 fParams.searchText = siteCode;
 fParams.returnGeometry = true;
 fParams.searchFields = ["site_code"];
 fParams.layerIds = lids; //set lids to include only facil layer
 fParams.contains = false;
 var deferred = findTask2.execute(fParams);  
    }  
    else{
 //map click; 
 identifyParams.tolerance = 5;
 anchorPt = evt.mapPoint;
 //since LAYER_OPTION_VISIBLE only pertains to scale visibility, not TOC checked/not checked, we have to manually set the identifyParams.layerIds
 dojo.forEach(legendLayers, function(layer){
  //layer must be checked in toc AND not be parcels, bndry or prtct;
  if (layer.layer.visible === true && (!(layer.layer.id == "parcels" || layer.layer.id == "bndry" || layer.layer.id == "prtct"))){
   lids.push(map.getLayer(layer.layer.id).layerId); //set lids to include all visible facilities
  }   
 })
       //click dependent identifyparams
       identifyParams.layerIds = lids;           
       identifyParams.width  = map.width;
       identifyParams.height = map.height;
       identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;    
       identifyParams.geometry = anchorPt;
       identifyParams.mapExtent = map.extent;
       var deferred = identifyTask.execute(identifyParams); 
    }

    deferred.addCallback(function(response) {
        //set esri.dijit.PopupTemplate for each layer
    });
};
0 Kudos