angularjs - How to handle multiple async tasks in angular.js and NgMap -
working on application geolocation using ngmap , angularjs. goal trail, markeur can browse set of points can exist given time. asynchronous spots browse ie have multiple asynchronous tasks work independently of others. me please resolve problem ?
the $scope.zoomer2 function role retrieve route 2 points (origin , destination) , trace in view.
$scope.zoomer2 = function(event){ if (debut == null){ debut = event.latlng; console.log(' debut == null '+debut); } else if (fin == null){ fin = event.latlng; $scope.directi.push( {origin:debut, destination:fin} ); console.log(' fin == null '+fin); console.log(' contenu de directi '); console.log($scope.directi); debut = null; fin = null; $timeout(function(){ $scope.tracer(event); }, 1000); } else if (fin != null){ fin = null; console.log(' fin != null => '+fin); } else if (debut != null){ debut = null; console.log(' debut != null => '+debut); } }
the $scope.getdistance function role calculate distance between 2 points
$scope.rad = function(x) { return x * math.pi / 180; }; $scope.getdistance = function(p1, p2) { var r = 6378137; var dlat = $scope.rad(p2.lat() - p1.lat()); var dlong = $scope.rad(p2.lng() - p1.lng()); var = math.sin(dlat / 2) * math.sin(dlat / 2) + math.cos($scope.rad(p1.lat())) * math.cos($scope.rad(p2.lat())) * math.sin(dlong / 2) * math.sin(dlong / 2); var c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)); var d = r * c; return math.ceil(d/10)*10; };
the $scope.tracer function role browse pointsarray index, problem asynchronous task cons both asynchronous tasking not work @ same time.
normally value $scope.pointsarray [z] must same outside , in $interval when z = 0.
but not case , don't know.
$scope.tracer = function(event){
$scope.debut = null; $scope.fin = null; var map = $scope.map; var zoom = map.getzoom(); z = $scope.directi.length-1; $scope.pointsarray[z] = []; ( var = 0; < map.directionsrenderers[z].directions.routes[0].legs[0].steps.length; i++){ console.log(' boucle 1', map.directionsrenderers[z].directions.routes[0].legs[0].steps[i]); console.log(' la taille de length '+map.directionsrenderers[z].directions.routes[0].legs[0].steps[i].path.length); ( var j = 0; j < map.directionsrenderers[z].directions.routes[0].legs[0].steps[i].path.length; j++){ console.log(' boucle 2 latitude longitude ', map.directionsrenderers[z].directions.routes[0].legs[0].steps[i].path[j].lat(), map.directionsrenderers[z].directions.routes[0].legs[0].steps[i].path[j].lng()); $scope.pointsarray[z].push({'lat':map.directionsrenderers[z].directions.routes[0].legs[0].steps[i].path[j].lat(), 'lng':map.directionsrenderers[z].directions.routes[0].legs[0].steps[i].path[j].lng()}); } } $q.when().then(function(tabs = $scope.pointsarray[z]){ var deferred = $q.defer(); var j = 0; console.log($scope.pointsarray[z]); $interval(function(tabs = $scope.pointsarray[z]){ console.log($scope.pointsarray[z]); if ( j >= $scope.pointsarray[z].length-1) return; console.log($scope.pointsarray[z][j].lat,$scope.pointsarray[z][j].lng); p1 = new google.maps.latlng($scope.pointsarray[z][j].lat,$scope.pointsarray[z][j].lng); p2 = new google.maps.latlng($scope.pointsarray[z][j+1].lat,$scope.pointsarray[z][j+1].lng); console.log(' ************************* 1 '); console.log(' cc 1 '); distance = 0; $interval(function(){ if (distance >= $scope.getdistance(p1, p2)) return; distance = distance + 10; map.markers[z].setposition(p1); console.log(' la valeur de la distance est ===>>> '+distance); deferred.resolve(distance); }, distance); console.log(' ************************* 2 '); console.log(' la valeur de j '+j); j++; }, 1000); return deferred.promise; });};
help me please ?
Comments
Post a Comment