diff --git a/src/app/home/home.component.spec.ts b/src/app/home/home.component.spec.ts index 6aeea5f08a025669387b5c6e93fe67711ac7317d..d389cc50d4660f6f2a92755adc25ad9c3c7d0eab 100644 --- a/src/app/home/home.component.spec.ts +++ b/src/app/home/home.component.spec.ts @@ -34,10 +34,10 @@ describe('HomeComponent', () => { it('getCoord(): should get coord', async () => { await new Promise((resolve) => { - component.getCoord(21356).subscribe( + component.getCoord('Rue de la Mairie ', 'Feyzin').subscribe( (val) => { - expect(val.geometry.getLat()).toEqual(69800); - expect(val.geometry.getLon).toEqual(69800); + expect(val.geometry.getLat()).toEqual(4.8591584); + expect(val.geometry.getLon()).toEqual(45.6727968); resolve(); }, (err) => { diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index c96c6f15b2e1c9b5837c08df00599c15094aa6ae..78dfe60ef1e40003f87730bba651114555c1c07a 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -94,7 +94,7 @@ export class HomeComponent implements OnInit { */ private getStructurePosition(structure: Structure): Promise<Structure> { return new Promise((resolve, reject) => { - this.getCoord(structure.voie).subscribe((coord: GeoJson) => { + this.getCoord(structure.voie, structure.commune).subscribe((coord: GeoJson) => { structure.address = coord.properties.name + ' - ' + coord.properties.postcode + ' ' + coord.properties.city; structure.distance = parseInt( this.geoJsonService.getDistance( @@ -115,8 +115,8 @@ export class HomeComponent implements OnInit { * Get coord with a street reference * @param idVoie Street reference */ - public getCoord(idVoie: number): Observable<GeoJson> { - return this.geoJsonService.getAddressByIdVoie(idVoie).pipe(mergeMap((res) => this.geoJsonService.getCoord(res))); + public getCoord(voie: string, zipcode: string): Observable<GeoJson> { + return this.geoJsonService.getCoord(voie, zipcode); } public getLocation(): void { diff --git a/src/app/map/components/map.component.ts b/src/app/map/components/map.component.ts index 29937bdddf56cc5d01dc6b0a64ff3ef47a87a28d..f41fb5da9e7c1bc6451209efb129dbc5d9ccb009 100644 --- a/src/app/map/components/map.component.ts +++ b/src/app/map/components/map.component.ts @@ -107,7 +107,7 @@ export class MapComponent implements OnChanges { private getStructuresPositions(structureListe: Structure[]): void { structureListe.forEach((element: Structure) => { - this.getCoord(element.voie).subscribe((coord: GeoJson) => { + this.getCoord(element.voie, element.commune).subscribe((coord: GeoJson) => { this.mapService .createMarker(coord.geometry.getLon(), coord.geometry.getLat(), element.id, this.buildToolTip(element)) .addTo(this.map) @@ -151,8 +151,8 @@ export class MapComponent implements OnChanges { * Get coord with a street reference * @param idVoie Street reference */ - public getCoord(idVoie: number): Observable<GeoJson> { - return this.geoJsonService.getAddressByIdVoie(idVoie).pipe(mergeMap((res) => this.geoJsonService.getCoord(res))); + public getCoord(voie: string, zipcode: string): Observable<GeoJson> { + return this.geoJsonService.getCoord(voie, zipcode); } /** diff --git a/src/app/models/structure.model.ts b/src/app/models/structure.model.ts index 35d8222e53a67976ed033774c91d893bf51d994d..221dd15cf608b56b2ba6ce9fe1056d0a363a8671 100644 --- a/src/app/models/structure.model.ts +++ b/src/app/models/structure.model.ts @@ -13,7 +13,8 @@ export class Structure { public typeDeStructure: string; public description: string; public n: string; - public voie: number; + public voie: string; + public commune: string; public telephone: string; public courriel: string; public siteWeb: string; diff --git a/src/app/services/geojson.service.spec.ts b/src/app/services/geojson.service.spec.ts index f6b6c9bda4c9fe63ebbd5a76bf63bc2486b3268a..a947152a8b9a78cd5c5eba10ef1d73f5bdfac840 100644 --- a/src/app/services/geojson.service.spec.ts +++ b/src/app/services/geojson.service.spec.ts @@ -22,27 +22,12 @@ describe('GeojsonService', () => { expect(service).toBeTruthy(); }); - it('should get address for id 26061 ', async () => { + it('should get coord with query string Rue de la Mairie Feyzin ', async () => { await new Promise((resolve) => { - service.getAddressByIdVoie(26061).subscribe( + service.getCoord('Rue de la Mairie', 'Feyzin').subscribe( (val) => { - expect(val.zipcode).toEqual('69800'); - expect(val.text).toEqual('13ème Rue Cité Berliet'); - resolve(); - }, - (err) => { - resolve(); - } - ); - }); - }); - - it('should get coord with query string avenue foch 69006 ', async () => { - await new Promise((resolve) => { - service.getCoord(new Address({ text: 'avenue foch', citycode: '69006' })).subscribe( - (val) => { - expect(val.geometry.getLat()).toEqual(4.8429024); - expect(val.geometry.getLon()).toEqual(45.7733884); + expect(val.geometry.getLat()).toEqual(4.8591584); + expect(val.geometry.getLon()).toEqual(45.6727968); resolve(); }, (err) => { diff --git a/src/app/services/geojson.service.ts b/src/app/services/geojson.service.ts index 36c0f3f56210c9b619bfe9df721c5ce01a2496c9..ef92bb87a79598f340ceb656c7de0dbc7251abee 100644 --- a/src/app/services/geojson.service.ts +++ b/src/app/services/geojson.service.ts @@ -12,16 +12,6 @@ import * as _ from 'lodash'; export class GeojsonService { constructor(private http: HttpClient) {} - /** - * Retrive an address with a street national reference - * @param idVoie Number - */ - public getAddressByIdVoie(idVoie: number): Observable<Address> { - return this.http - .get('/base-adresse/base-adresse-nationale/streets' + '?id=' + idVoie) - .pipe(map((data: { data: any[]; err: number }) => new Address(data.data[0]))); - } - /** * Retrive an address by geolocation * @param idVoie Number @@ -57,9 +47,9 @@ export class GeojsonService { * Get GeoLocation with an address * @param address Address */ - public getCoord(address: Address): Observable<GeoJson> { + public getCoord(address: string, zipcode: string): Observable<GeoJson> { return this.http - .get('/geocoding/photon/api' + '?q=' + address.queryString()) + .get('/geocoding/photon/api' + '?q=' + address + ' ' + zipcode) .pipe(map((data: { features: any[]; type: string }) => new GeoJson(data.features[0]))); } diff --git a/src/app/structure-list/components/card/card.component.ts b/src/app/structure-list/components/card/card.component.ts index 4050fe75977be0d50656f01a435fc478ffb41f4a..6af5fbd47a47ef2b3fa39d769bdfb545e87e0eff 100644 --- a/src/app/structure-list/components/card/card.component.ts +++ b/src/app/structure-list/components/card/card.component.ts @@ -1,10 +1,6 @@ import { Component, Input, Output, OnInit, EventEmitter } from '@angular/core'; import { Structure } from '../../../models/structure.model'; import { GeojsonService } from '../../../services/geojson.service'; -import { GeoJson } from '../../../map/models/geojson.model'; -import { Observable } from 'rxjs'; -import { mergeMap } from 'rxjs/operators'; - @Component({ selector: 'app-card', templateUrl: './card.component.html', @@ -29,14 +25,6 @@ export class CardComponent implements OnInit { } } - /** - * Get coord with a street reference - * @param idVoie Street reference - */ - public getCoord(idVoie: number): Observable<GeoJson> { - return this.geoJsonService.getAddressByIdVoie(idVoie).pipe(mergeMap((res) => this.geoJsonService.getCoord(res))); - } - public cardClicked(): void { this.showDetails.emit(this.structure); }