This commit is contained in:
2023-04-14 17:32:14 +02:00
parent 360b12d1c4
commit 3d0a96e7a7
4 changed files with 24 additions and 13 deletions

View File

@@ -24,7 +24,7 @@
</li> </li>
<li *ngFor="let luogo of luoghiNear()"> <li *ngFor="let luogo of luoghiNear()">
{{luogo.nome}} {{luogo.location}}
</li> </li>
</ul> </ul>

View File

@@ -3,6 +3,7 @@ export interface Locations {
region: string; region: string;
lat: number; lat: number;
lon: number; lon: number;
distance?: number;
waypoints?: waypoint[]; waypoints?: waypoint[];
} }

View File

@@ -3,6 +3,8 @@ import {Locations} from "../interface/data";
import {ReadjsonService} from "../service/readjson.service"; import {ReadjsonService} from "../service/readjson.service";
import {Observable} from "rxjs"; import {Observable} from "rxjs";
import {ActivatedRoute} from "@angular/router"; import {ActivatedRoute} from "@angular/router";
import {Cord} from "../interface/cord";
import {positionService} from "../service/position.service";
@Component({ @Component({
selector: 'app-list', selector: 'app-list',
@@ -16,25 +18,27 @@ export class ListComponent implements OnInit {
isNear: boolean = true; isNear: boolean = true;
positionCord: any;
constructor(private route: ActivatedRoute ,private readjsonService: ReadjsonService) {} distance: number = 0;
ngOnInit(): void { constructor(private route: ActivatedRoute ,private readjsonService: ReadjsonService, private positionService: positionService) {}
async ngOnInit() {
this.route.params.subscribe(params => { this.route.params.subscribe(params => {
this.locationParams = params['location']; this.locationParams = params['location'];
}); });
this.readjsonService.getLocations().subscribe(locations => { this.readjsonService.getLocations().subscribe(locations => {
this.locations = locations; this.locations = locations;
this.checkDataPopulated(); if (this.locationParams != null) {
this.readjsonService.getLocation(this.locationParams).subscribe(location => {
this.location = location;
this.checkDataPopulated();
});
}
}); });
this.positionCord = await this.readjsonService.getLocations();
if (this.locationParams != null) { this.setDistance();
this.readjsonService.getLocation(this.locationParams).subscribe(location => {
this.location = location;
this.checkDataPopulated();
});
}
} }
private checkDataPopulated(): void { private checkDataPopulated(): void {
@@ -50,5 +54,10 @@ export class ListComponent implements OnInit {
} }
} }
} }
private setDistance(): void{
if (this.location && this.isNear){
this.distance = this.positionService.getDistanceBetweenCoordinates(this.location.lat, this.location.lon, this.positionCord.lat, this.positionCord.lon);
console.log("Distanza: " + this.distance + " km");
}
}
} }

View File

@@ -38,6 +38,7 @@ export class ReadjsonService{
tap(data => console.log("data requested", data)) tap(data => console.log("data requested", data))
); );
} }
/* /*
getWaypoints(location: string, id: number): Observable<waypoint[]> { getWaypoints(location: string, id: number): Observable<waypoint[]> {
return this.locations.pipe( return this.locations.pipe(