AnsweredAssumed Answered

Directions are not coming inside iPromise

Question asked by siva.lntgis on Jul 27, 2018

Hi

We are trying to get the routes from user location. we are calculating the distance between the user location and remaining points inside the promise to get the points which lies within our mentioned region.

the routes are not coming when i execute the getDirection inside the iPromise.

 

Please refer the below screenshot.

 

when i tried the same without iPromise, the results are coming as expected, but i'm not calculating the distance here.

 

refer the code snippet for the same:

 

function zoomToLocation() {
var pt = new Point(longitude, latitude);
currPosition = pt; //new Point(longitude,latitude,new SpatialReference({wkid:4326}));;
addGraphic(pt);
map.centerAndZoom(pt, 12);
UsrLocation = new Point(longitude, latitude, new SpatialReference({
wkid: 4326
}));
if (UsrLocation != null && UsrLocation != undefined) {
console.log("gothe the user location " + UsrLocation);
var sleep = function (milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds) {
break;
}
}
}
task = array.map(toPoints, lang.hitch(this, function (toPoint) {
var distParams = new esri.tasks.DistanceParameters();
distParams.distanceUnit = esri.tasks.GeometryService.UNIT_KILOMETER;

distParams.geometry1 = UsrLocation;
distParams.geometry2 = toPoint;
distParams.geodesic = true;
return distParams;
}));
for (i = 0; i < task.length; i++) {
promises.push(geometryService.distance(task[i]));
}
var iPromises = new all(promises);
iPromises.then(lang.hitch(this, function (distance) {
if (isNaN(distance)) {
for (var i = 0; i < distance.length; i++) {
if (distance[i] > 35) {
outOfLimitGraLyr.add((new Graphic(toPoints[i], symbol3)));
} else {
routeInputGraLyr.add((new Graphic(toPoints[i])));
}
count++;
}
}
alert(distance);
if (routeInputGraLyr.graphics.length != 0 && count == distance.length) {
directions.addStops(routeInputGraLyr.graphics);
directions.addStop(UsrLocation, 0);//useMyCurrentLocation
// directions.useMyCurrentLocation(0);
directions.getDirections();
} else {
alert(
"Sorry, No Routes are available to show,please check your cases are within your limits of 35Km limits");
console.log("Sorry, No Routes are available to show,please check your cases are within your limits of 35Km limits");
}
if (outOfLimitGraLyr.graphics.length > 0) {
alert("The Points plotted in blue colors are far away from your location");
console.log("The Points plotted in blue colors are far away from your location");
}
}), lang.hitch(this, function (err) {
console.info(err);
}));
}
}

 

Thanks & Regards

Siva

Outcomes