AnsweredAssumed Answered

QueryTask.execute issue

Question asked by Sara_EL_MALKI on May 15, 2017
Latest reply on May 15, 2017 by Sara_EL_MALKI

Hi everyone,

I am facing an issue that I can't solve so far,

 

I am using a QueryFeatures function which returns many items , for EACH item of the result I wanna do a QUERY and repeat it UNTIL IT IS SUCCESSUL, 

my problems are: - the query still loops after being successful

                             -the order of the functions executed

this code displays me First all the ALERTS of the while as example:

(id troncon 1) (id troncon 5) (id troncon 8) When the length is satisfied then it starts printing me alert EXECUTING, EXECUTING EXECUTING

INSTEAD it must print me id troncon 1 then EXECUTING, id trondon 5 EXECUTING id troncon 8 EXECUTING

I hope that I am clear and I hope you can help me as soon as possible 

 

 

FLayer2 = map.getLayer("troncon");

FLayer2.setSelectionSymbol(symbolLine1);
FLayer2.selectFeatures(selectionQuery,esri.layers.FeatureLayer.SELECTION_NEW);
FLayer2.on("selection-complete", zoomToVoie);
FLayer2.queryFeatures(selectionQuery, selectInVoie);
}
function selectInVoie(response){
var feature;
var features = response.features;
var queryTaskAdr = new QueryTask("....../1"); //ADRESSES
var idTroncon;
var found=false;
//SELECTION OF THE DOT
var line = new SimpleLineSymbol();
line.setWidth(3.25);
var marker = new SimpleMarkerSymbol();
marker.setOutline(line);
marker.setColor(new Color([255, 0, 0, 1])); // A RED DOT
marker.setAngle(360);

var i=0;
while( (i < features.length) && (!found) ){  //REPEAT THE WHILE UNTIL THE variable FOUND=TRUE
feature = features[i];
idTroncon=feature.attributes[FLayer2.objectIdField];
alert("idTroncon "+idTroncon);
var queryAdr = new Query();
queryAdr.where = "Text_ = '"+TheAdr+"' AND ID_TRONCON ="+idTroncon;
queryAdr.outSpatialReference = {wkid:102100};
queryAdr.returnGeometry = true;
queryAdr.outFields = ["objectid"];

queryTaskAdr.execute(queryAdr, function(fset) {
alert(' EXECUTING');
if (fset.features.length === 1) { //POINT FOUND  //BREAK
var objectidOfAdr=fset.features[0].attributes['objectid']; 
var geoAdr=fset.features[0].geometry

var FLayer1 = map.getLayer("adresse"); 
FLayer1.setSelectionSymbol(marker);
var selectionQuery1 = new Query();
selectionQuery1.where = "objectid ="+objectidOfAdr;
FLayer1.selectFeatures(selectionQuery1,esri.layers.FeatureLayer.SELECTION_NEW);

ExtentAdr=new Extent(geoAdr.x, geoAdr.y, (geoAdr.x)+50, (geoAdr.y)+50, geoAdr.spatialReference);
FLayer1.on("selection-complete", zoomToAdr);
found=true;
}

});

i++; //INCREMENT
}
}

function zoomToVoie(){
map.setExtent(ExtentOfVoie);
}
}

Outcomes