mirror of
https://github.com/DerTyp7/osm-routing-angular.git
synced 2025-11-02 06:02:30 +01:00
added search
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import { Component, ElementRef, Output, ViewChild } from '@angular/core';
|
||||
import { Photon, PhotonFeatureCollection } from '../interfaces/photon';
|
||||
import { PhotonService } from '../services/photon.service';
|
||||
import { Component, Output } from '@angular/core';
|
||||
import { EventEmitter } from '@angular/core';
|
||||
import { PythonBackendService } from '../services/python-backend.service';
|
||||
import { RouteResponse } from '../interfaces/routeResponse';
|
||||
import { SearchResponse, SearchWay } from '../interfaces/searchResponse';
|
||||
|
||||
@Component({
|
||||
selector: 'app-search',
|
||||
@@ -13,67 +12,31 @@ import { RouteResponse } from '../interfaces/routeResponse';
|
||||
export class SearchComponent {
|
||||
|
||||
@Output() emitter = new EventEmitter<RouteResponse>();
|
||||
@ViewChild("inputautocompleteList") autocompleteList: ElementRef;
|
||||
|
||||
searchItemsFrom: SearchWay[] = [];
|
||||
searchItemsTo: SearchWay[] = [];
|
||||
|
||||
|
||||
photonItemsFrom: Photon[] = [];
|
||||
photonItemsTo: Photon[] = [];
|
||||
selectedSearchWayFrom: SearchWay;
|
||||
selectedSearchWayTo: SearchWay;
|
||||
|
||||
inputFromValue: string;
|
||||
inputToValue: string;
|
||||
|
||||
longFrom: number = 0;
|
||||
latFrom: number = 0;
|
||||
longTo: number = 0;
|
||||
latTo: number = 0;
|
||||
|
||||
selectedPhotonFrom: Photon;
|
||||
selectedPhotonTo: Photon;
|
||||
getRouteBtnEnabled: boolean = true;
|
||||
|
||||
constructor(
|
||||
private photonService: PhotonService,
|
||||
private pythonBackendService: PythonBackendService,
|
||||
) { }
|
||||
|
||||
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 = <number> p.geometry?.coordinates[0];
|
||||
this.latFrom = <number> p.geometry?.coordinates[1];
|
||||
this.inputFromValue = <string> p.properties.name;
|
||||
this.inputFromValue = this.getFormattedPhotonValue(p);
|
||||
this.photonItemsFrom = [];
|
||||
} else {
|
||||
this.selectedPhotonTo = p;
|
||||
this.longTo = <number>p.geometry?.coordinates[0];
|
||||
this.latTo = <number>p.geometry?.coordinates[1];
|
||||
this.inputToValue = <string> p.properties.name + " " + p.properties.countrycode;
|
||||
this.inputToValue = this.getFormattedPhotonValue(p);
|
||||
this.photonItemsTo = [];
|
||||
select(isFrom: boolean, item: SearchWay): void{
|
||||
if(isFrom){
|
||||
this.selectedSearchWayFrom = item;
|
||||
this.inputFromValue = item.name;
|
||||
this.searchItemsFrom = [];
|
||||
}else{
|
||||
this.selectedSearchWayTo = item;
|
||||
this.inputToValue = item.name;
|
||||
this.searchItemsTo = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,39 +44,28 @@ export class SearchComponent {
|
||||
* Gets called in "app.component.html" when an input changes its value
|
||||
*/
|
||||
getValue(value: string, isFrom: boolean): void {
|
||||
this.searchItemsFrom = [];
|
||||
this.searchItemsTo = [];
|
||||
|
||||
//this.updateAutoCompleteList([{display_name: 'Hallo'}, {display_name: 'Test2'}], [{display_name: 'Halload'}, {display_name: 'Test4'}]);
|
||||
|
||||
/*
|
||||
this.nominatimService.sendQueryRequest(valueFrom)
|
||||
.subscribe((response: Nominatim[]) => this.nominatimItemsFrom = response);
|
||||
|
||||
this.nominatimService.sendQueryRequest(valueTo)
|
||||
.subscribe((response: Nominatim[]) => this.nominatimItemsTo = response);
|
||||
*/
|
||||
|
||||
this.photonItemsFrom = [];
|
||||
this.photonItemsTo = [];
|
||||
|
||||
this.photonService.sendQueryRequest(value)
|
||||
.subscribe((response: PhotonFeatureCollection) => response.features?.forEach(feature => {
|
||||
if (isFrom) {
|
||||
this.photonItemsFrom.push(feature);
|
||||
this.longFrom = <number>this.photonItemsFrom[0].geometry?.coordinates![0];
|
||||
this.latFrom = <number>this.photonItemsFrom[0].geometry?.coordinates![1];
|
||||
} else {
|
||||
this.photonItemsTo.push(feature);
|
||||
this.longTo = <number>this.photonItemsFrom[0].geometry?.coordinates![0];
|
||||
this.latTo = <number>this.photonItemsFrom[0].geometry?.coordinates![1];
|
||||
}
|
||||
})
|
||||
);
|
||||
this.pythonBackendService.sendSearchQueryRequest(value, "10")
|
||||
.subscribe((response: SearchResponse) => response.ways?.forEach(way =>{
|
||||
if(isFrom){
|
||||
this.searchItemsFrom.push(way);
|
||||
this.selectedSearchWayFrom = way;
|
||||
}else{
|
||||
this.searchItemsTo.push(way);
|
||||
this.selectedSearchWayTo = way;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
getRoute(): void{
|
||||
this.pythonBackendService.sendQueryRequest(this.latFrom.toString(), this.longFrom.toString(), this.latTo.toString(), this.longTo.toString())
|
||||
this.getRouteBtnEnabled = false;
|
||||
this.pythonBackendService.sendRouteQueryRequest(this.selectedSearchWayFrom.id.toString(), this.selectedSearchWayTo.id.toString())
|
||||
.subscribe((response: RouteResponse) => {
|
||||
console.log(response);
|
||||
this.emitter.emit(response);
|
||||
this.getRouteBtnEnabled = true;
|
||||
/*
|
||||
this.mapComponent.updateSidebar(response);
|
||||
this.mapComponent.drawPath(response);
|
||||
|
||||
Reference in New Issue
Block a user