fix non tanto fix positionNotFoundFunction

This commit is contained in:
2023-04-30 10:53:23 +02:00
parent 66aa99fe4f
commit f9f0bd2e19
2 changed files with 31 additions and 30 deletions

View File

@@ -17,7 +17,7 @@
<a class="link link-primary" href="location/{{locations.location}}">{{locations.location}}</a> <a class="link link-primary" href="location/{{locations.location}}">{{locations.location}}</a>
</h3> </h3>
<div> <div>
<h4 *ngIf="locations.distance &&! positionNotFound">{{translations.distance}}{{locations.distance}} km</h4> <h4 *ngIf="locations.distance && !positionNotFound">{{translations.distance}}{{locations.distance}} km</h4>
<h4 *ngIf="positionNotFound && !locations.distance">{{translations.positionNotFoundErrorMessage}}</h4> <h4 *ngIf="positionNotFound && !locations.distance">{{translations.positionNotFoundErrorMessage}}</h4>
</div> </div>
</div> </div>

View File

@@ -25,7 +25,6 @@ export class ListComponent implements OnInit, OnChanges {
isNear: boolean = true; isNear: boolean = true;
distance: number[] = [];
translations: listTranslations = {} as listTranslations translations: listTranslations = {} as listTranslations
@@ -48,42 +47,52 @@ export class ListComponent implements OnInit, OnChanges {
}); });
this.locationService.getLocation(this.locationParams ?? "").subscribe(location => { this.locationService.getLocation(this.locationParams ?? "").subscribe(location => {
this.location = location; this.location = location;
console.log("location", this.location) if (this.location.location != null || this.location.location != undefined) {
if (this.location != null) {
this.isNear = false; this.isNear = false;
this.waypointService.getWaypoints(this.location.location).subscribe(waypoints => { this.waypointService.getWaypoints(this.location.location).subscribe(waypoints => {
this.waypoints = waypoints; this.waypoints = waypoints;
console.log("waypoints", this.waypoints) console.log("waypoints", this.waypoints)
this.setDistance() this.setDistance()
}); });
} else {
this.locationService.getLocations().subscribe(locations => {
this.locations = locations;
console.log("locations", this.locations)
this.setDistance()
});
} }
}); });
this.locationService.getLocations().subscribe(locations => {
this.locations = locations;
console.log("locations", this.locations)
this.setDistance()
});
this.getPosition(); this.getPosition();
//this.positionNotFoundFunction(); this.positionNotFoundFunction();
} }
/*
positionNotFoundFunction() { positionNotFoundFunction() {
if (!this.positionNotFound) { if (!this.positionNotFound) {
setTimeout(() => { setTimeout(() => {
if (this.waypoints||this.locations) { if (!this.positionCord) {
if (!this.waypoints[0].distance||!this.locations[0].distance) {
}
}
if (!this.distance[0]) {
this.positionNotFound = true; this.positionNotFound = true;
} else {
if (this.waypoints) {
if (!this.waypoints[0].distance) {
this.positionNotFound = true;
} else {
this.positionNotFound = false;
}
}
if (this.locations) {
if (!this.locations[0].distance) {
this.positionNotFound = true;
} else {
this.positionNotFound = false;
}
}
} }
}, 5000); }, 5000);
} }
} }
*/
ngOnChanges(changes: SimpleChanges) { ngOnChanges(changes: SimpleChanges) {
if (changes['positionCord'] && (changes['positionCord'])) { if (changes['positionCord'] && (changes['positionCord'])) {
console.log("onChanges") console.log("onChanges")
@@ -108,21 +117,13 @@ export class ListComponent implements OnInit, OnChanges {
} }
private setDistance(): void { private setDistance(): void {
if (this.waypoints){ if (this.waypoints) {
console.log("setDistance")
console.log("waypoints lenght " + this.waypoints.length);
for (let i = 0; i < this.waypoints.length; i++) { for (let i = 0; i < this.waypoints.length; i++) {
console.log("for" + i);
console.log("lat" + this.waypoints[i].lat);
this.waypoints[i].distance = this.positionService.getDistanceBetweenCoordinates(this.waypoints[i].lat, this.waypoints[i].lon, this.positionCord.lat, this.positionCord.lon); this.waypoints[i].distance = this.positionService.getDistanceBetweenCoordinates(this.waypoints[i].lat, this.waypoints[i].lon, this.positionCord.lat, this.positionCord.lon);
} }
} else{ } else {
if (this.locations && this.location) { if (this.locations) {
console.log("setDistance")
console.log("location lenght " + this.locations.length);
for (let i = 0; i < this.locations.length; i++) { for (let i = 0; i < this.locations.length; i++) {
console.log("for" + i);
console.log("lat" + this.locations[i].lat);
this.locations[i].distance = this.positionService.getDistanceBetweenCoordinates(this.locations[i].lat, this.locations[i].lon, this.positionCord.lat, this.positionCord.lon); this.locations[i].distance = this.positionService.getDistanceBetweenCoordinates(this.locations[i].lat, this.locations[i].lon, this.positionCord.lat, this.positionCord.lon);
} }
} }