diff --git a/proxy.conf.json b/proxy.conf.json index 70c21305f4f69a5eddeb234cf6d4b134a539301d..cc19a811554725a5abb0feb49e8f7fae9c58e77d 100644 --- a/proxy.conf.json +++ b/proxy.conf.json @@ -14,12 +14,6 @@ "changeOrigin": true, "logLevel": "info" }, - "/geocoding/photon/api": { - "target": "https://download.data.grandlyon.com", - "secure": false, - "changeOrigin": true, - "logLevel": "info" - }, "/wfs/grandlyon": { "target": "https://download.data.grandlyon.com", "secure": false, diff --git a/src/app/home/home.component.spec.ts b/src/app/home/home.component.spec.ts index d389cc50d4660f6f2a92755adc25ad9c3c7d0eab..4bc5950f6a1619d1bed7a4eb96a87c539b75e5c2 100644 --- a/src/app/home/home.component.spec.ts +++ b/src/app/home/home.component.spec.ts @@ -31,20 +31,6 @@ describe('HomeComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); - - it('getCoord(): should get coord', async () => { - await new Promise((resolve) => { - component.getCoord('Rue de la Mairie ', 'Feyzin').subscribe( - (val) => { - expect(val.geometry.getLat()).toEqual(4.8591584); - expect(val.geometry.getLon()).toEqual(45.6727968); - resolve(); - }, - (err) => { - resolve(); - } - ); - }); }); it('getAddress(): should getAddress', () => { diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 0f968db5bae501bc161985d9fa0a3f699ad78256..265131817965101ff76329120865a78598f3d7d0 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -38,12 +38,9 @@ export class HomeComponent implements OnInit { Promise.all( structures.map((structure) => { if (this.geolocation) { - return this.getStructurePosition(structure).then((val) => { - return this.structureService.updateOpeningStructure(val, DateTime.local()); - }); - } else { - return this.structureService.updateOpeningStructure(structure, DateTime.local()); + structure = this.getStructurePosition(structure); } + return this.structureService.updateOpeningStructure(structure, DateTime.local()); }) ).then((structureList) => { structureList = _.sortBy(structureList, ['distance']); @@ -58,31 +55,18 @@ export class HomeComponent implements OnInit { /** * Get structures positions and add marker corresponding to those positons on the map */ - private getStructurePosition(structure: Structure): Promise<Structure> { - return new Promise((resolve, reject) => { - this.getCoord(structure.n, structure.voie, structure.commune).subscribe((coord: GeoJson) => { - structure.address = structure.voie + ' - ' + coord.properties.postcode + ' ' + coord.properties.city; - structure.distance = parseInt( - this.geoJsonService.getDistance( - coord.geometry.getLon(), - coord.geometry.getLat(), - this.currentLocation.geometry.getLon(), - this.currentLocation.geometry.getLat(), - 'M' - ), - 10 - ); - resolve(structure); - }); - }); - } - - /** - * Get coord with a street reference - * @param idVoie Street reference - */ - public getCoord(numero: string, voie: string, zipcode: string): Observable<GeoJson> { - return this.geoJsonService.getCoord(numero, voie, zipcode); + private getStructurePosition(structure: Structure): Structure { + structure.distance = parseInt( + this.geoJsonService.getDistance( + structure.getLon(), + structure.getLat(), + this.currentLocation.geometry.getLon(), + this.currentLocation.geometry.getLat(), + 'M' + ), + 10 + ); + return structure; } public getLocation(): void { diff --git a/src/app/map/components/map.component.ts b/src/app/map/components/map.component.ts index 84a68b693016845ba1fc4f5631c1abcb44baaccc..6bccd2d4488c9a939e0217e72d55d327145618d8 100644 --- a/src/app/map/components/map.component.ts +++ b/src/app/map/components/map.component.ts @@ -108,22 +108,20 @@ export class MapComponent implements OnChanges { } private getStructuresPositions(structureListe: Structure[]): void { - structureListe.forEach((element: Structure) => { - this.getCoord(element.n, element.voie, element.commune).subscribe((coord: GeoJson) => { - this.mapService - .createMarker( - coord.geometry.getLon(), - coord.geometry.getLat(), - MarkerType.structure, - element.id, - this.buildToolTip(element) - ) - .addTo(this.map) - // store structure before user click on button - .on('popupopen', () => { - this.currentStructure = element; - }); - }); + structureListe.forEach((structure: Structure) => { + this.mapService + .createMarker( + structure.getLon(), + structure.getLat(), + MarkerType.structure, + structure.id, + this.buildToolTip(structure) + ) + .addTo(this.map) + // store structure before user click on button + .on('popupopen', () => { + this.currentStructure = structure; + }); }); } @@ -159,14 +157,6 @@ export class MapComponent implements OnChanges { return `<h1>${mdmProperties.nom}</h1><p>${mdmProperties.adresse}</p>`; } - /** - * Get coord with a street reference - * @param idVoie Street reference - */ - public getCoord(numero: string, voie: string, zipcode: string): Observable<GeoJson> { - return this.geoJsonService.getCoord(numero, voie, zipcode); - } - /** * Add marker when map is ready to be showned * @param map map diff --git a/src/app/models/structure.model.ts b/src/app/models/structure.model.ts index 221dd15cf608b56b2ba6ce9fe1056d0a363a8671..bcc5b4a08fdd369fb3f25aefd33f9463338df9ef 100644 --- a/src/app/models/structure.model.ts +++ b/src/app/models/structure.model.ts @@ -40,6 +40,7 @@ export class Structure { public accesAuxDroits: string[]; public distance?: number; public address?: string; + public coord?: number[]; constructor(obj?: any) { Object.assign(this, obj, { @@ -109,4 +110,12 @@ export class Structure { } } } + + public getLat(): number { + return this.coord[0]; + } + + public getLon(): number { + return this.coord[1]; + } } diff --git a/src/app/services/geojson.service.spec.ts b/src/app/services/geojson.service.spec.ts index a947152a8b9a78cd5c5eba10ef1d73f5bdfac840..71045a64d867491b1fe53f051ffd73cb0159749d 100644 --- a/src/app/services/geojson.service.spec.ts +++ b/src/app/services/geojson.service.spec.ts @@ -21,19 +21,4 @@ describe('GeojsonService', () => { it('should be created', () => { expect(service).toBeTruthy(); }); - - it('should get coord with query string Rue de la Mairie Feyzin ', async () => { - await new Promise((resolve) => { - service.getCoord('Rue de la Mairie', 'Feyzin').subscribe( - (val) => { - expect(val.geometry.getLat()).toEqual(4.8591584); - expect(val.geometry.getLon()).toEqual(45.6727968); - resolve(); - }, - (err) => { - resolve(); - } - ); - }); - }); }); diff --git a/src/app/services/geojson.service.ts b/src/app/services/geojson.service.ts index 5f15ae6d84f1e101b7def155dde13eb0b2035609..befafee6c17fcf7131e2642cf957f0596c45e952 100644 --- a/src/app/services/geojson.service.ts +++ b/src/app/services/geojson.service.ts @@ -43,16 +43,6 @@ export class GeojsonService { .pipe(map((data: { features: any[] }) => _.map(data.features, this.parseToGeoJson))); } - /** - * Get GeoLocation with an address - * @param address Address - */ - public getCoord(numero: string, address: string, zipcode: string): Observable<GeoJson> { - return this.http - .get('/geocoding/photon/api' + '?q=' + numero + ' ' + address + ' ' + zipcode) - .pipe(map((data: { features: any[]; type: string }) => new GeoJson(data.features[0]))); - } - // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // ::: ::: // ::: This routine calculates the distance between two points (given the :::