diff --git a/proxy.conf.json b/proxy.conf.json index f5d9180245f7dc46708cd6947716af80568f6e29..0feeb012e6b5ff251979cd7b736db83dd9b2ab88 100644 --- a/proxy.conf.json +++ b/proxy.conf.json @@ -26,8 +26,8 @@ "changeOrigin": true, "logLevel": "info" }, - "/geocoding/photon/api": { - "target": "https://download.data.grandlyon.com", + "/geocoding/photon-bal/api": { + "target": "https://download.data.grandlyon.com/geocoding/photon-bal/api", "secure": false, "changeOrigin": true, "logLevel": "info" diff --git a/src/app/carto/carto.component.html b/src/app/carto/carto.component.html index 13bcaeb923859bef2003cdf6f99363223042e1aa..3b47fe933de308ac7066bcfff0b613af0fd8dfe4 100644 --- a/src/app/carto/carto.component.html +++ b/src/app/carto/carto.component.html @@ -30,6 +30,7 @@ (selectedStructure)="showDetailStructure($event)" (locatationTrigger)="locatationTrigger($event)" [isMapPhone]="isMapPhone" + [searchedValue]="searchedValue" class="right-pane" [ngClass]="{ mapPhone: isMapPhone == true }" ></app-map> diff --git a/src/app/carto/carto.component.ts b/src/app/carto/carto.component.ts index e04b0f12de273f01559f5bf1f401a1c35acbf318..d55b420b7a1fb498be0ff97edfc08ae2d418f814 100644 --- a/src/app/carto/carto.component.ts +++ b/src/app/carto/carto.component.ts @@ -24,6 +24,7 @@ export class CartoComponent implements OnInit { public userLatitude: number; public userLongitude: number; public isMapPhone = false; + public searchedValue = null; public locate = false; // Use to sync location between search and map constructor(private structureService: StructureService, private geoJsonService: GeojsonService) {} @@ -41,6 +42,7 @@ export class CartoComponent implements OnInit { public getStructures(filters: Filter[]): void { const queryString = _.find(filters, { name: 'query' }); if (queryString) { + this.searchedValue = queryString.value; if (this.isLocationRequest(queryString.value)) { this.getCoordByAddress(queryString.value).then((res) => { this.currentLocation = res; @@ -60,6 +62,7 @@ export class CartoComponent implements OnInit { }); } } else { + this.searchedValue = null; this.structureService.getStructures(filters).subscribe((structures) => { if (structures) { this.updateStructuresdistance(structures, this.userLongitude, this.userLatitude); diff --git a/src/app/map/components/map.component.ts b/src/app/map/components/map.component.ts index a038e5759181bc0f6703cf58fa585d5c1ae26117..1b80b2b5693af01ab724d8606e8fc3c732f0c692 100644 --- a/src/app/map/components/map.component.ts +++ b/src/app/map/components/map.component.ts @@ -22,9 +22,10 @@ export class MapComponent implements OnChanges { @Input() public selectedMarkerId: string; @Input() public isMapPhone: boolean; @Input() public locate = false; + @Input() public searchedValue: string; @Output() selectedStructure: EventEmitter<Structure> = new EventEmitter<Structure>(); @Output() locatationTrigger: EventEmitter<boolean> = new EventEmitter<boolean>(); - private lc; + private lc; // Locate control private currentStructure: Structure; public map: Map; @@ -51,6 +52,10 @@ export class MapComponent implements OnChanges { } ngOnChanges(changes: SimpleChanges): void { + if (changes.searchedValue && !changes.searchedValue.firstChange) { + if (changes.searchedValue.currentValue) this.processTownCoordinate(changes.searchedValue.currentValue); + else this.map.setView(this.mapOptions.center, this.mapOptions.zoom); + } if (changes.isMapPhone) { if (this.isMapPhone) { setTimeout(() => { @@ -91,6 +96,18 @@ export class MapComponent implements OnChanges { } } + public processTownCoordinate(queryString: string): void { + this.geoJsonService.getTownshipCoord(queryString).subscribe( + (townData) => { + const bounds = new L.LatLngBounds(townData.map((dataArray) => dataArray.reverse())); + this.map.fitBounds(bounds); + }, + (err) => { + this.map.setView(this.mapOptions.center, this.mapOptions.zoom); + } + ); + } + /** * Get structures positions and add marker corresponding to those positons on the map */ @@ -108,8 +125,8 @@ export class MapComponent implements OnChanges { } } - private getStructuresPositions(structureListe: Structure[]): void { - structureListe.forEach((structure: Structure) => { + private getStructuresPositions(structureList: Structure[]): void { + structureList.forEach((structure: Structure) => { this.mapService .createMarker( structure.getLat(), diff --git a/src/app/map/services/map.service.ts b/src/app/map/services/map.service.ts index 901b4d615a3b201c076ad3223320b512d51ab6c3..5918d6a5bd1b49eecb9d62e221d9bdab51a49276 100644 --- a/src/app/map/services/map.service.ts +++ b/src/app/map/services/map.service.ts @@ -1,7 +1,10 @@ +import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { DivIcon, divIcon, Map } from 'leaflet'; import { Marker } from 'leaflet'; +import { Observable } from 'rxjs'; import { MarkerType } from '../components/markerType.enum'; +import { AddressGeometry } from '../models/addressGeometry.model'; @Injectable({ providedIn: 'root', @@ -31,7 +34,7 @@ export class MapService { iconSize: [19, 24], iconAnchor: [9, 0], }); - constructor() {} + constructor(private http: HttpClient) {} public createMarker(lat: number, lon: number, markerType: MarkerType, id?: string, tooltip?: string): Marker { const marker = new Marker([lat, lon], { diff --git a/src/app/services/geojson.service.ts b/src/app/services/geojson.service.ts index ac3bfe1e2cedf2c0375deda7deadfde9112ab341..5b4670c864e51c7923f17c4b817357cef3bf39c1 100644 --- a/src/app/services/geojson.service.ts +++ b/src/app/services/geojson.service.ts @@ -49,10 +49,14 @@ export class GeojsonService { */ public getCoord(numero: string, address: string, zipcode: string): Observable<GeoJson> { return this.http - .get('/geocoding/photon/api' + '?q=' + numero + ' ' + address + ' ' + zipcode, { headers: { skip: 'true' } }) + .get('/geocoding/photon-bal/api' + '?q=' + numero + ' ' + address + ' ' + zipcode, { headers: { skip: 'true' } }) .pipe(map((data: { features: any[]; type: string }) => new GeoJson(data.features[0]))); } + public getTownshipCoord(town: string): Observable<Array<any>> { + return this.http.get<Array<any>>(`/api/structures/coordinates/` + town); + } + // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // ::: ::: // ::: This routine calculates the distance between two points (given the :::