From b17060bd5f3c969298906c549432f3187ca242a9 Mon Sep 17 00:00:00 2001 From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com> Date: Fri, 2 Dec 2022 11:02:25 +0000 Subject: [PATCH] fix(orientation): distance display when no position sharing --- src/app/carto/carto.component.ts | 19 ++++++++++--------- .../components/card/card.component.html | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/app/carto/carto.component.ts b/src/app/carto/carto.component.ts index 062631697..b0dd61c14 100644 --- a/src/app/carto/carto.component.ts +++ b/src/app/carto/carto.component.ts @@ -49,6 +49,7 @@ export class CartoComponent implements OnInit { // Set user location if provided if (this.userLatitude && this.userLongitude) { this.userLocate = [this.userLongitude, this.userLatitude]; + this.getAddress(this.userLongitude, this.userLatitude); } if (navigator.geolocation) { this.getLocation(this.filters); @@ -74,7 +75,7 @@ export class CartoComponent implements OnInit { if (this.isLocationRequest(queryString.value)) { this.getCoordByAddress(queryString.value).then((res) => { this.currentLocation = res; - this.updateStructuresdistance( + this.updateStructuresDistance( this.structures, this.currentLocation.geometry.getLon(), this.currentLocation.geometry.getLat() @@ -83,7 +84,7 @@ export class CartoComponent implements OnInit { } else { this.structureService.getStructures(filters).subscribe((structures) => { if (structures) { - this.updateStructuresdistance(structures, this.userLongitude, this.userLatitude, false); + this.updateStructuresDistance(structures, this.userLongitude, this.userLatitude, false); } else { this.structures = null; } @@ -93,7 +94,7 @@ export class CartoComponent implements OnInit { this.searchedValue = null; this.structureService.getStructures(filters).subscribe((structures) => { if (structures) { - this.updateStructuresdistance(structures, this.userLongitude, this.userLatitude); + this.updateStructuresDistance(structures, this.userLongitude, this.userLatitude); } else { this.structures = null; } @@ -111,10 +112,10 @@ export class CartoComponent implements OnInit { * Update structure distance according to user actual position. * @param structures structures data to update * @param lon user longitude - * @param lat user latitde + * @param lat user latitude * @param sortByDistance if set to `true`, structures data is sort by distance. Default value is `true` */ - private updateStructuresdistance( + private updateStructuresDistance( structures: Structure[], lon: number, lat: number, @@ -122,11 +123,11 @@ export class CartoComponent implements OnInit { ): void { Promise.all( structures.map(async (structure) => { - if (this.geolocation) { + if (lon && lat) { structure = this.getStructurePosition(structure, lon, lat); - if (this.isAdmin) { - structure.isClaimed = await this.isClaimed(structure).toPromise(); - } + } + if (this.isAdmin) { + structure.isClaimed = await this.isClaimed(structure).toPromise(); } return structure; }) diff --git a/src/app/structure-list/components/card/card.component.html b/src/app/structure-list/components/card/card.component.html index ff36325a2..651aa12a7 100644 --- a/src/app/structure-list/components/card/card.component.html +++ b/src/app/structure-list/components/card/card.component.html @@ -14,7 +14,7 @@ <span class="typeStructure" [ngClass]="{ typeStructureOrientation: isOrientation }">{{ structure.getLabelTypeStructure() }}</span> - <span *ngIf="isOrientation" class="distance"> + <span *ngIf="isOrientation && structure.distance" class="distance"> {{ this.formatDistance() }} </span> </div> -- GitLab