diff --git a/src/app/carto/carto.component.ts b/src/app/carto/carto.component.ts index 062631697b2161ba842b1c1800ecfbe817dcfef0..b0dd61c148d62259acc0d8007d08211884f3deff 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 ff36325a2e578e64ef0263bcca5301a3631b2b3b..651aa12a75f7aad9a56c2a5960099d002798fb2d 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>