Commit 8dd604db authored by Ratnadeep Rajendra Kharade's avatar Ratnadeep Rajendra Kharade
Browse files

Added functionality to show no go areas for user

parent 07e4cef8
...@@ -217,10 +217,10 @@ export class HirebikePage implements OnInit { ...@@ -217,10 +217,10 @@ export class HirebikePage implements OnInit {
var waypoint1 = this.destinationPosition.lat + ',' + this.destinationPosition.lng; var waypoint1 = this.destinationPosition.lat + ',' + this.destinationPosition.lng;
this.loadingService.showLoader(); this.loadingService.showLoader();
this.storage.get('token').then((token) => { this.storage.get('token').then((token) => {
let url = 'http://193.196.52.237:8081/routing?startlng='+ this.bikePosition.lng + '&startlat=' + this.bikePosition.lat + '&destinationlng='+ this.destinationPosition.lng + '&destinationlat=' + this.destinationPosition.lat; let url = 'http://193.196.52.237:8081/routing?startlng=' + this.bikePosition.lng + '&startlat=' + this.bikePosition.lat + '&destinationlng=' + this.destinationPosition.lng + '&destinationlat=' + this.destinationPosition.lat;
const headers = new HttpHeaders().set("Authorization", "Bearer " + token); const headers = new HttpHeaders().set("Authorization", "Bearer " + token);
let bikeApi = this.httpClient.get(url, { headers }); let bikeApi = this.httpClient.get(url, { headers });
bikeApi.subscribe((resp:any) => { bikeApi.subscribe((resp: any) => {
console.log('my data: ', resp); console.log('my data: ', resp);
this.loadingService.hideLoader(); this.loadingService.hideLoader();
this.isBikeHired = true; this.isBikeHired = true;
...@@ -232,12 +232,12 @@ export class HirebikePage implements OnInit { ...@@ -232,12 +232,12 @@ export class HirebikePage implements OnInit {
let firstRoute = firstRouteResp.response.route[0]; let firstRoute = firstRouteResp.response.route[0];
this.selectedRoute = firstRoute; this.selectedRoute = firstRoute;
this.gotRouteOptions = true; this.gotRouteOptions = true;
this.displayNoGoAreas(resp);
}, (error) => { }, (error) => {
console.log(error); console.log(error);
this.loadingService.hideLoader(); this.loadingService.hideLoader();
}); });
}); });
// let resp = { // let resp = {
// "data": { // "data": {
// "routes": [ // "routes": [
...@@ -269,13 +269,58 @@ export class HirebikePage implements OnInit { ...@@ -269,13 +269,58 @@ export class HirebikePage implements OnInit {
// } // }
} }
displayRouteOptions(resp, selectedRouteIndex){ displayNoGoAreas(resp) {
for (let i = resp.data.routes.length - 1; i >= 0 ; i--) { let routes = resp.data.routes;
let allNoGoAreas = [];
let finalNoGoAreas = [];
for (let i = 0; i < routes.length; i++) {
for (let j = 0; j < routes[i].actualNoGoAreas.length; j++){
allNoGoAreas.push(routes[i].actualNoGoAreas[j]);
}
}
console.log(allNoGoAreas);
finalNoGoAreas = [...new Set(allNoGoAreas)];
console.log(finalNoGoAreas);
//let group = new H.map.Group();
//this.addRectangleToMap();
for (let i = 0; i < finalNoGoAreas.length; i++){
let coords = finalNoGoAreas[i].split(" ");
let boundingBox = new H.geo.Rect(Number(coords[0]).toPrecision(15), Number(coords[1]).toPrecision(15), Number(coords[2]).toPrecision(15), Number(coords[3]).toPrecision(15));
this.map.addObject(
new H.map.Rect(boundingBox, {
style: {
fillColor: 'rgba(255, 0, 0, 0.5)',
strokeColor: 'rgba(0, 0, 0, 0.7)',
lineWidth: 2
},
})
);
}
}
/**
* Adds a rectangle to the map
*/
addRectangleToMap() {
var boundingBox = new H.geo.Rect(53.1, 13.1, 43.1, 40.1);
this.map.addObject(
new H.map.Rect(boundingBox, {
style: {
fillColor: 'rgba(255, 0, 0, 0.2)',
strokeColor: 'rgba(255, 255, 255, 0.5)',
lineWidth: 1
},
})
);
}
displayRouteOptions(resp, selectedRouteIndex) {
for (let i = resp.data.routes.length - 1; i >= 0; i--) {
let routeResp = JSON.parse(resp.data.routes[i].route); let routeResp = JSON.parse(resp.data.routes[i].route);
let route = routeResp.response.route[0]; let route = routeResp.response.route[0];
//console.log(route); //console.log(route);
this.setRouteOptions(route, i, resp.data.routes[i].mode, selectedRouteIndex); this.setRouteOptions(route, i, resp.data.routes[i].mode, selectedRouteIndex);
if(i !== selectedRouteIndex) { if (i !== selectedRouteIndex) {
this.drawRouteLine(route, i); this.drawRouteLine(route, i);
} }
} }
...@@ -284,7 +329,7 @@ export class HirebikePage implements OnInit { ...@@ -284,7 +329,7 @@ export class HirebikePage implements OnInit {
this.drawRouteLine(route, selectedRouteIndex, 'rgba(102, 157, 246, 0.9)'); this.drawRouteLine(route, selectedRouteIndex, 'rgba(102, 157, 246, 0.9)');
} }
displayRouteSummaryAtTop(resp){ displayRouteSummaryAtTop(resp) {
let firstRoute = JSON.parse(resp.data.routes[0].route).response.route[0]; let firstRoute = JSON.parse(resp.data.routes[0].route).response.route[0];
console.log(firstRoute); console.log(firstRoute);
let waypointLabels = []; let waypointLabels = [];
...@@ -302,10 +347,10 @@ export class HirebikePage implements OnInit { ...@@ -302,10 +347,10 @@ export class HirebikePage implements OnInit {
content += 'Total distance: ' + route.summary.distance + 'm. '; content += 'Total distance: ' + route.summary.distance + 'm. ';
content += 'Travel Time: ' + Math.floor(route.summary.travelTime / 60) + ' min'; content += 'Travel Time: ' + Math.floor(route.summary.travelTime / 60) + ' min';
console.log(content); console.log(content);
if(index === selectedRouteIndex) { if (index === selectedRouteIndex) {
selected = true; selected = true;
} }
this.routeList[index] = {route:route, summary:content, mode:mode, selected: selected}; this.routeList[index] = { route: route, summary: content, mode: mode, selected: selected };
} }
isRouteSelected = false; isRouteSelected = false;
...@@ -356,18 +401,18 @@ export class HirebikePage implements OnInit { ...@@ -356,18 +401,18 @@ export class HirebikePage implements OnInit {
this.map.addObject(polyline); this.map.addObject(polyline);
} }
removeRouteLines(){ removeRouteLines() {
for(let key in this.routeLines) { for (let key in this.routeLines) {
this.map.removeObject(this.routeLines[key]); this.map.removeObject(this.routeLines[key]);
} }
} }
getRouteType(mode){ getRouteType(mode) {
if (mode === "NORMAL") { if (mode === "NORMAL") {
return "Fastest Route"; return "Fastest Route";
} else if(mode === "ACCIDENTS") { } else if (mode === "ACCIDENTS") {
return "Safe Route"; return "Safe Route";
} else if(mode === "AIR_POLLUTION") { } else if (mode === "AIR_POLLUTION") {
return "Green Route"; return "Green Route";
} else { } else {
return "Safe and Green Route"; return "Safe and Green Route";
...@@ -379,13 +424,13 @@ export class HirebikePage implements OnInit { ...@@ -379,13 +424,13 @@ export class HirebikePage implements OnInit {
this.startRideSubject.next('some value'); this.startRideSubject.next('some value');
this.loadingService.showLoader(); this.loadingService.showLoader();
this.storage.get('token').then((token) => { this.storage.get('token').then((token) => {
const bikeId=this.bikeDetails.id; const bikeId = this.bikeDetails.id;
let url = 'http://193.196.52.237:8081/rent' + '?bikeId=' + this.bikeDetails.id; let url = 'http://193.196.52.237:8081/rent' + '?bikeId=' + this.bikeDetails.id;
const headers = new HttpHeaders().set("Authorization", "Bearer " + token); const headers = new HttpHeaders().set("Authorization", "Bearer " + token);
let bikeApi = this.httpClient.get(url, { headers }); let bikeApi = this.httpClient.get(url, { headers });
bikeApi.subscribe((resp) => { bikeApi.subscribe((resp) => {
console.log('my data: ', resp); console.log('my data: ', resp);
this.loadingService.hideLoader(); this.loadingService.hideLoader();
this.toastService.showToast("Trip Started"); this.toastService.showToast("Trip Started");
this.isBikeHired = true; this.isBikeHired = true;
...@@ -462,7 +507,7 @@ export class HirebikePage implements OnInit { ...@@ -462,7 +507,7 @@ export class HirebikePage implements OnInit {
} }
] ]
}); });
await alert.present(); await alert.present();
}, (error) => { }, (error) => {
console.log(error); console.log(error);
...@@ -781,8 +826,8 @@ export class HirebikePage implements OnInit { ...@@ -781,8 +826,8 @@ export class HirebikePage implements OnInit {
}); });
} }
ionViewDidLeave(){ ionViewDidLeave() {
if(this.mapElement) { if (this.mapElement) {
this.mapElement.nativeElement.remove(); this.mapElement.nativeElement.remove();
} }
// if(this.locationService.liveLocationSubject) { // if(this.locationService.liveLocationSubject) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment