diff --git a/src/app/carto/carto.component.ts b/src/app/carto/carto.component.ts index 30f8c25b4b2ec461e130865c833148fb015c099c..52857d854d48f3ef0e0635e3b81c38172ea3e0cd 100644 --- a/src/app/carto/carto.component.ts +++ b/src/app/carto/carto.component.ts @@ -63,7 +63,7 @@ export class CartoComponent implements OnInit { } else { this.structureService.getStructures(filters).subscribe((structures) => { if (structures) { - this.updateStructuresdistance(structures, this.userLongitude, this.userLatitude); + this.updateStructuresdistance(structures, this.userLongitude, this.userLatitude, false); } else { this.structures = null; } @@ -87,7 +87,19 @@ export class CartoComponent implements OnInit { }); } - private updateStructuresdistance(structures: Structure[], lon: number, lat: number): void { + /** + * Update structure distance according to user actual position. + * @param structures structures data to update + * @param lon user longitude + * @param lat user latitde + * @param sortByDistance if set to `true`, structures data is sort by distance. Default value is `true` + */ + private updateStructuresdistance( + structures: Structure[], + lon: number, + lat: number, + sortByDistance: boolean = true + ): void { Promise.all( structures.map((structure) => { if (this.geolocation) { @@ -96,7 +108,9 @@ export class CartoComponent implements OnInit { return this.structureService.updateOpeningStructure(structure); }) ).then((structureList) => { - structureList = _.sortBy(structureList, ['distance']); + if (sortByDistance) { + structureList = _.sortBy(structureList, ['distance']); + } this.structures = structureList; }); }