From 248c274e8a1319c5e9d9e98880426a35c7d0d4d9 Mon Sep 17 00:00:00 2001 From: Janis Meister Date: Fri, 14 Jan 2022 09:52:34 +0100 Subject: [PATCH] now using photon --- src/app/app.component.ts | 12 ++++-------- src/app/interfaces/photon.ts | 7 ++++++- src/app/photon.service.ts | 6 +++--- src/app/search/search.component.html | 18 +++++++++++++++-- src/app/search/search.component.ts | 29 +++++++++++++++++++++++----- 5 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 1b07991..dc78066 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,8 +1,5 @@ -import { Component, OnInit, AfterViewInit, ElementRef, ViewChild} from '@angular/core'; -import { Nominatim } from './interfaces/nominatim'; -import { NominatimService } from './nominatim.service'; -import { Photon } from './interfaces/photon'; -import { PhotonService } from './photon.service'; +import { Component, AfterViewInit, ElementRef, ViewChild} from '@angular/core'; + import { defaults as defaultControls } from 'ol/control'; import { fromLonLat } from 'ol/proj'; @@ -25,7 +22,7 @@ export class AppComponent implements AfterViewInit { @ViewChild("inputautocompleteList") autocompleteList: ElementRef; - constructor(private nominatimService: NominatimService, private photonService: PhotonService) { } + constructor() { } updateAutoCompleteList(): void{ this.autocompleteList.nativeElement.innerHTML = "Fsd"; @@ -39,8 +36,7 @@ export class AppComponent implements AfterViewInit { this.nominatimService.sendQueryRequest(valueFrom) .subscribe((response: Nominatim[]) => console.log(response));*/ - this.photonService.sendQueryRequest(valueFrom) - .subscribe((response: Photon[]) => console.log(response)); + } diff --git a/src/app/interfaces/photon.ts b/src/app/interfaces/photon.ts index fc57a09..4a69e29 100644 --- a/src/app/interfaces/photon.ts +++ b/src/app/interfaces/photon.ts @@ -18,5 +18,10 @@ interface PhotonProperties{ export interface Photon{ geometry?: PhotonGeometry; type?: string; - properties?: PhotonProperties; + properties: PhotonProperties; +} + +export interface PhotonFeatureCollection{ + features?: Array; + type?: string; } \ No newline at end of file diff --git a/src/app/photon.service.ts b/src/app/photon.service.ts index cfad5b8..8f98415 100644 --- a/src/app/photon.service.ts +++ b/src/app/photon.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; -import { Photon } from './interfaces/photon'; +import { Photon, PhotonFeatureCollection } from './interfaces/photon'; import { Observable } from 'rxjs'; @Injectable({ @@ -12,7 +12,7 @@ export class PhotonService{ constructor(private http: HttpClient) { } // sends a query request to Photon and gets response (https://photon.komoot.io/) - sendQueryRequest(q: string): Observable { - return this.http.get("https://photon.komoot.io/api/?q=" + q); + sendQueryRequest(q: string): Observable { + return this.http.get("https://photon.komoot.io/api/?q=" + q); } } \ No newline at end of file diff --git a/src/app/search/search.component.html b/src/app/search/search.component.html index 8a3264a..4f500f8 100644 --- a/src/app/search/search.component.html +++ b/src/app/search/search.component.html @@ -2,19 +2,33 @@
-
+ +
{{ item.display_name }}
+ +
+ {{ item.properties.name }} + +
+
-
+ +
{{ item.display_name }}
+ +
+ {{ item.properties.name }} + +
+
\ No newline at end of file diff --git a/src/app/search/search.component.ts b/src/app/search/search.component.ts index f949500..21aa988 100644 --- a/src/app/search/search.component.ts +++ b/src/app/search/search.component.ts @@ -1,6 +1,8 @@ import { Component, OnInit, ElementRef, ViewChild} from '@angular/core'; import { Nominatim } from '../interfaces/nominatim'; import { NominatimService } from '../nominatim.service'; +import { Photon, PhotonFeatureCollection } from '../interfaces/photon'; +import { PhotonService } from '../photon.service'; @Component({ selector: 'app-search', @@ -11,10 +13,13 @@ import { NominatimService } from '../nominatim.service'; export class SearchComponent implements OnInit { @ViewChild("inputautocompleteList") autocompleteList: ElementRef; - itemsFrom: Nominatim[] = []; - itemsTo: Nominatim[] = []; + nominatimItemsFrom: Nominatim[] = []; + nominatimItemsTo: Nominatim[] = []; - constructor(private nominatimService: NominatimService) { } + photonItemsFrom: Photon[] = []; + photonItemsTo: Photon[] = []; + + constructor(private nominatimService: NominatimService, private photonService: PhotonService) { } // Gets called in "app.component.html" when an input changes its value @@ -23,12 +28,26 @@ export class SearchComponent implements OnInit { //this.updateAutoCompleteList([{display_name: 'Hallo'}, {display_name: 'Test2'}], [{display_name: 'Halload'}, {display_name: 'Test4'}]); + /* this.nominatimService.sendQueryRequest(valueFrom) - .subscribe((response: Nominatim[]) => this.itemsFrom = response); + .subscribe((response: Nominatim[]) => this.nominatimItemsFrom = response); this.nominatimService.sendQueryRequest(valueTo) - .subscribe((response: Nominatim[]) => this.itemsTo = response); + .subscribe((response: Nominatim[]) => this.nominatimItemsTo = response); + */ + + this.photonService.sendQueryRequest(valueFrom) + .subscribe((response: PhotonFeatureCollection) => response.features?.forEach(feature => { + this.photonItemsFrom.push(feature); + })); + + this.photonService.sendQueryRequest(valueFrom) + .subscribe((response: PhotonFeatureCollection) => response.features?.forEach(feature => { + this.photonItemsTo.push(feature); + })); + console.log(this.photonItemsFrom) + } ngOnInit(): void { }