diff --git a/src/app/search/search.component.css b/src/app/search/search.component.css index 6b2ddd5..33caa27 100644 --- a/src/app/search/search.component.css +++ b/src/app/search/search.component.css @@ -1,11 +1,3 @@ -#inputFrom:focus + .autocomplete-items-from{ - visibility:visible; -} - -#inputTo:focus + .autocomplete-items-to{ - visibility:visible; -} - .searchField{ display:block; float:left; @@ -32,7 +24,7 @@ } .autocomplete-items { - visibility: visible; /* without debugging it should be display:none */ + /*display: block; */ position: absolute; border: 1px solid #d4d4d4; border-bottom: none; diff --git a/src/app/search/search.component.html b/src/app/search/search.component.html index 29eb8e8..f80e3b3 100644 --- a/src/app/search/search.component.html +++ b/src/app/search/search.component.html @@ -1,6 +1,7 @@ +
- +
@@ -8,8 +9,9 @@
+
+ (click)="selectPhoton(true, item);" >
- +
diff --git a/src/app/search/search.component.ts b/src/app/search/search.component.ts index f9f015b..7ff608a 100644 --- a/src/app/search/search.component.ts +++ b/src/app/search/search.component.ts @@ -5,11 +5,8 @@ import { Photon, PhotonFeatureCollection } from '../interfaces/photon'; import { PhotonService } from '../services/photon.service'; import { OsrmService } from '../services/osrm.service'; import { Osrm } from '../interfaces/osrm'; -import { MapComponent } from '../map/map.component'; import { EventEmitter } from '@angular/core'; - - @Component({ selector: 'app-search', templateUrl: './search.component.html', @@ -42,41 +39,51 @@ export class SearchComponent{ private nominatimService: NominatimService, private photonService: PhotonService, private osrmService: OsrmService, - ) { } + ) { } + + getFormattedPhotonValue(p: Photon): string{ + let formatted: string = ""; + + if(p.properties.name){ + formatted += " " + p.properties.name; + } + if(p.properties.housenumber){ + formatted += " " + p.properties.housenumber; + } + if(p.properties.postcode){ + formatted += " " + p.properties.postcode; + } + if(p.properties.city){ + formatted += " " + p.properties.city; + } + if(p.properties.countrycode){ + formatted += " " + p.properties.countrycode; + } + + return formatted; + } + selectPhoton(isFrom: boolean, p: Photon): void{ if(isFrom){ this.selectedPhotonFrom = p; this.longFrom = p.geometry?.coordinates[0]; this.latFrom = p.geometry?.coordinates[1]; - this.inputFromValue = p.properties.name - - if(p.properties.housenumber){ - this.inputFromValue += " " + p.properties.housenumber; - } - - if(p.properties.postcode){ - this.inputFromValue += " " + p.properties.postcode; - } - - if(p.properties.city){ - this.inputFromValue += " " + p.properties.city; - } - - if(p.properties.countrycode){ - this.inputFromValue += " " + p.properties.countrycode; - } - + this.inputFromValue = p.properties.name; + this.inputFromValue = this.getFormattedPhotonValue(p); + this.photonItemsFrom = []; }else{ this.selectedPhotonTo = p; this.longTo = p.geometry?.coordinates[0]; this.latTo = p.geometry?.coordinates[1]; this.inputToValue = p.properties.name + " " + p.properties.countrycode; + this.inputToValue = this.getFormattedPhotonValue(p); + this.photonItemsTo = []; } + } // Gets called in "app.component.html" when an input changes its value - getValue(valueFrom:string, valueTo:string): void{ - console.log("From " + valueFrom + " to " + valueTo); + getValue(value:string, isFrom: boolean): void{ //this.updateAutoCompleteList([{display_name: 'Hallo'}, {display_name: 'Test2'}], [{display_name: 'Halload'}, {display_name: 'Test4'}]); @@ -87,27 +94,22 @@ export class SearchComponent{ this.nominatimService.sendQueryRequest(valueTo) .subscribe((response: Nominatim[]) => this.nominatimItemsTo = response); */ + this.photonItemsFrom = []; this.photonItemsTo = []; - this.photonService.sendQueryRequest(valueFrom) + this.photonService.sendQueryRequest(value) .subscribe((response: PhotonFeatureCollection) => response.features?.forEach(feature => { - this.photonItemsFrom.push(feature); - this.longFrom = this.photonItemsFrom[0].geometry?.coordinates![0]; - this.latFrom = this.photonItemsFrom[0].geometry?.coordinates![1]; - console.log("longFrom: " + this.longFrom) - console.log("latFrom: " + this.latFrom) + if(isFrom){ + this.photonItemsFrom.push(feature); + this.longFrom = this.photonItemsFrom[0].geometry?.coordinates![0]; + this.latFrom = this.photonItemsFrom[0].geometry?.coordinates![1]; + }else{ + this.photonItemsTo.push(feature); + this.longTo = this.photonItemsFrom[0].geometry?.coordinates![0]; + this.latTo = this.photonItemsFrom[0].geometry?.coordinates![1]; + } })); - - this.photonService.sendQueryRequest(valueTo) - .subscribe((response: PhotonFeatureCollection) => response.features?.forEach(feature => { - this.photonItemsTo.push(feature); - this.longTo = this.photonItemsTo[0].geometry?.coordinates![0]; - this.latTo = this.photonItemsTo[0].geometry?.coordinates![1] - console.log("LongTo: " + this.longTo) - console.log("LatTo: " + this.latTo) - })); - } getRoute(): void{