list component changes
This commit is contained in:
@@ -1,21 +1,25 @@
|
|||||||
<div *ngIf="isNear">
|
<div *ngIf="isNear">
|
||||||
|
<h1>
|
||||||
|
Posizione {{locationParams}} non trovata
|
||||||
|
</h1>
|
||||||
|
<div *ngFor="let locations of locations, let i = index">
|
||||||
|
<h3>
|
||||||
|
<a href="location/{{locations.location}}">{{locations.location}}</a>
|
||||||
|
</h3>
|
||||||
|
<h4>Distance: {{distance[i]}}</h4>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div *ngIf="!isNear && location">
|
<div *ngIf="!isNear && location && location.waypoints">
|
||||||
<h1>
|
<h1>
|
||||||
{{location.location}}
|
{{location.location}}
|
||||||
</h1>
|
</h1>
|
||||||
<div *ngFor="let waypoinst of location.waypoints">
|
{{location.waypoints[0].name}}
|
||||||
|
<div *ngFor="let waypoinst of location.waypoints, let i = index">
|
||||||
<h3>
|
<h3>
|
||||||
{{waypoinst.name}}
|
<a class="link link-primary" href="location/{{location.location}}/{{waypoinst.id}}"> {{waypoinst.name}}</a>
|
||||||
</h3>
|
</h3>
|
||||||
<h4>Distance: {{getDistance(waypoinst.lat, location.lon)}}</h4>
|
<h4>Distance: {{distance[i]}}</h4>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<h1></h1>
|
|
||||||
|
|
||||||
<h3></h3>
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Component, OnInit} from '@angular/core';
|
import {Component, OnInit, SimpleChanges, OnChanges} from '@angular/core';
|
||||||
import {Locations} from "../interface/data";
|
import {Locations} from "../interface/data";
|
||||||
import {ReadjsonService} from "../service/readjson.service";
|
import {ReadjsonService} from "../service/readjson.service";
|
||||||
import {ActivatedRoute} from "@angular/router";
|
import {ActivatedRoute} from "@angular/router";
|
||||||
@@ -9,8 +9,8 @@ import {positionService} from "../service/position.service";
|
|||||||
templateUrl: './list.component.html',
|
templateUrl: './list.component.html',
|
||||||
styleUrls: ['./list.component.css']
|
styleUrls: ['./list.component.css']
|
||||||
})
|
})
|
||||||
export class ListComponent implements OnInit {
|
export class ListComponent implements OnInit, OnChanges {
|
||||||
private locationParams: string | undefined
|
locationParams: string | undefined
|
||||||
locations: Partial<Locations>[] | undefined;
|
locations: Partial<Locations>[] | undefined;
|
||||||
location: Partial<Locations> | undefined;
|
location: Partial<Locations> | undefined;
|
||||||
|
|
||||||
@@ -18,7 +18,8 @@ export class ListComponent implements OnInit {
|
|||||||
|
|
||||||
isNear: boolean = true;
|
isNear: boolean = true;
|
||||||
|
|
||||||
distance: number = 0;
|
distance: number[] = [];
|
||||||
|
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute, private readjsonService: ReadjsonService, private positionService: positionService) {
|
constructor(private route: ActivatedRoute, private readjsonService: ReadjsonService, private positionService: positionService) {
|
||||||
}
|
}
|
||||||
@@ -30,14 +31,27 @@ export class ListComponent implements OnInit {
|
|||||||
this.readjsonService.getLocations().subscribe(locations => {
|
this.readjsonService.getLocations().subscribe(locations => {
|
||||||
this.locations = locations;
|
this.locations = locations;
|
||||||
if (this.locationParams != null) {
|
if (this.locationParams != null) {
|
||||||
this.readjsonService.getLocation(this.locationParams).subscribe(location => {
|
this.readjsonService.getLocation(this.locationParams ?? "").subscribe(async location => {
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.checkDataPopulated();
|
this.readjsonService.getWaypoints(this.locationParams ?? "").subscribe(waypoints => {
|
||||||
|
if (this.location) {
|
||||||
|
this.location.waypoints = waypoints ?? []
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await this.checkDataPopulated();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
|
if (changes['positionCord'] && (changes['positionCord'])) {
|
||||||
|
console.log("onChanges")
|
||||||
this.setDistance();
|
this.setDistance();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private checkDataPopulated(): void {
|
private checkDataPopulated(): void {
|
||||||
if (this.locations && this.location) {
|
if (this.locations && this.location) {
|
||||||
@@ -47,6 +61,7 @@ export class ListComponent implements OnInit {
|
|||||||
this.location = this.locations[i];
|
this.location = this.locations[i];
|
||||||
console.log("Location trovata:", this.location);
|
console.log("Location trovata:", this.location);
|
||||||
this.isNear = false;
|
this.isNear = false;
|
||||||
|
this.setDistance();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,10 +69,20 @@ export class ListComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private setDistance(): void {
|
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);
|
const intervalId = setInterval(() => {
|
||||||
console.log("Distanza: " + this.distance + " km");
|
if (this.location) {
|
||||||
|
if (this.location?.waypoints) {
|
||||||
|
console.log("setDistance"+this.location);
|
||||||
|
for (let i = 0; i < this.location.waypoints.length; i++) {
|
||||||
|
console.log("for")
|
||||||
|
this.distance.push(this.positionService.getDistanceBetweenCoordinates(this.location.waypoints[i].lat, this.location?.lon, this.positionCord.lat, this.positionCord.lon));
|
||||||
}
|
}
|
||||||
|
clearInterval(intervalId);
|
||||||
|
}
|
||||||
|
console.log("ciao" + this.distance[0])
|
||||||
|
}}, 1000);
|
||||||
|
//da aggiungere il cambiamento in tutti i punti, forse fatto ma sono stanco
|
||||||
}
|
}
|
||||||
|
|
||||||
getDistance(latLocation: number | undefined, lonLocation: number | undefined): any {
|
getDistance(latLocation: number | undefined, lonLocation: number | undefined): any {
|
||||||
@@ -71,4 +96,5 @@ export class ListComponent implements OnInit {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export class positionService{
|
|||||||
return deg * (Math.PI / 180)
|
return deg * (Math.PI / 180)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getLocation() {
|
async getLocation(): Promise<any> {
|
||||||
console.log('get location');
|
console.log('get location');
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (navigator.geolocation) {
|
if (navigator.geolocation) {
|
||||||
@@ -65,4 +65,5 @@ export class positionService{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,17 +40,32 @@ export class ReadjsonService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
getWaypoints(location: string, id: number): Observable<waypoint[]> {
|
getWaypoint(location: string, id: number): Observable<waypoint[]> {
|
||||||
return this.locations.pipe(
|
return this.locations.pipe(
|
||||||
map((locations) => {
|
map((locations) => {
|
||||||
const foundLocation: Locations | undefined = locations.find((loc: Locations) => loc.location === location);
|
const foundLocation: Locations | undefined = locations.find((loc: Locations) => loc.location === location);
|
||||||
if (foundLocation?.waypoints) {
|
if (foundLocation?.waypoints) {
|
||||||
return foundLocation ? foundLocation.waypoints.filter((way: waypoint) => way.id === id) : [];
|
return foundLocation ? foundLocation.waypoints.filter((way: waypoint) => way.id === id) : [];
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return []
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
tap(data => console.log("data requested", data))
|
tap(data => console.log("data requested", data))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getWaypoints(location: string): Observable<waypoint[]> {
|
||||||
|
return this.locations.pipe(
|
||||||
|
map((locations) => {
|
||||||
|
const foundLocation: Locations | undefined = locations.find((loc: Locations) => loc.location === location);
|
||||||
|
if (foundLocation?.waypoints) {
|
||||||
|
return foundLocation ? foundLocation.waypoints : [];
|
||||||
|
} else {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
tap(data => console.log("data requested", data))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ import {Injectable} from "@angular/core";
|
|||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class TranslateService {
|
export class TranslateService {
|
||||||
constructor(private deepLService: DeepLService) {
|
constructor(private deepLService: DeepLService) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async getData(input: string, lang: string): Promise<string> {
|
async getData(input: string, lang: string): Promise<string> {
|
||||||
const response = await this.deepLService.translate(input, lang).toPromise();
|
const response = await this.deepLService.translate(input, lang).toPromise();
|
||||||
|
|||||||
Reference in New Issue
Block a user