Commit 517bea05 authored by Sebastian Bruch's avatar Sebastian Bruch

nominatim + fixes

parent bb204729
......@@ -59,9 +59,9 @@ export class OsmNode {
this.name = "";
if(data['id'] && data['osmId'] && data['type']){
if(data['id'] && data['osmId'] && data['osmType']){
this.osmId = data['osmId'];
this.osmType = data['type'].toLowerCase();;
this.osmType = data['osmType'].toLowerCase();;
this.id = data['id'];
}else{
if(data['id'] && data['type']){
......@@ -70,7 +70,7 @@ export class OsmNode {
}
}
if(data['type']){
this.osmType = this.osmType.toLowerCase();
this.osmType = data['type'].toLowerCase();
}
if(data['tags']){
......
......@@ -41,6 +41,9 @@
<div class ="searchbox-subheading">Elemente:</div>
<div *ngFor="let elem of osmNodes">
<div [ngClass]="{'list-group-item':true,'list-group-item-action':true,'selected-item':isCurrentElement(elem) }" (click)="show(elem)"><i class="fa fa-map-marker fa-lg" aria-hidden="true"></i> {{elem.name}}</div>
</div>
<div *ngFor="let elem of nominatimNodes">
<div [ngClass]="{'list-group-item':true,'list-group-item-action':true,'selected-item':isCurrentElement(elem) }" (click)="show(elem)"><i class="fa fa-map-marker fa-lg" aria-hidden="true"></i> {{elem.name}}</div>
</div>
</div>
......
......@@ -9,8 +9,10 @@ import { LogService } from '../services/log.service';
import { MapService } from '../services/map.service';
import { DataGroup } from '../models/DataGroup';
import { OsmNode } from '../models/OsmNode';
import { OsmNodeFactory } from '../models/OsmNodeFactory';
import { OsmNodeService } from '../services/osm-node.service';
import { NominatimService } from '../services/nominatim.service';
import { AuthService } from '../services/auth.service';
import OlMap from 'ol/Map';
import OlView from 'ol/View';
......@@ -29,6 +31,7 @@ export class SearchComponent implements OnInit {
searchPattern="";
allOsmNodes:Array<OsmNode>;
osmNodes:Array<OsmNode>;
nominatimNodes:Array<OsmNode>;
dataGroups:Array<DataGroup>;
currentElement:OsmNode;
......@@ -41,9 +44,14 @@ export class SearchComponent implements OnInit {
private geoElementService: GeoElementService,
private mapService: MapService,
private authService: AuthService,
private spinner: NgxSpinnerService
private spinner: NgxSpinnerService,
private nominatimService: NominatimService
) {
this.osmNodes = new Array<OsmNode>();
this.nominatimNodes = new Array<OsmNode>();
this.allOsmNodes = new Array<OsmNode>();
this.dataGroups = new Array<DataGroup>();
this.searchForm = this.formBuilder.group({
searchPattern: ['', Validators.required],
searchInDescription: ['',]
......@@ -100,8 +108,12 @@ export class SearchComponent implements OnInit {
parseSearchResult(result){
this.searched=true;
this.osmNodes.length = 0;
this.allOsmNodes.length = 0;
this.dataGroups.length = 0;
this.logger.debug("Search result.");
if(result){
if(result['dataGroups']){
this.dataGroups = new Array<DataGroup>();
for(let data of result['dataGroups']){
......@@ -109,33 +121,59 @@ export class SearchComponent implements OnInit {
}
}
if(result['geoElements']){
this.osmNodes = new Array<OsmNode>();
this.allOsmNodes = new Array<OsmNode>();
for(let data of result['geoElements']){
let node = new OsmNode(data);
let node = OsmNodeFactory.create(data);
this.nodeService.fillBliDimensions(node);
node.osmId = data['osmId'];
if(this.searchForm.value.searchInDescription){
this.logger.debug("Pushing anyway.");
this.osmNodes.push(node);
if(this.osmNodes.indexOf(node) == -1){
this.osmNodes.push(node);
}
}else{
this.logger.debug(" for " + this.searchForm.value.searchPattern);
if(node.name.toLowerCase().indexOf(this.searchForm.value.searchPattern.toLowerCase()) > -1){
this.osmNodes.push(node);
if(this.osmNodes.indexOf(node) == -1){
this.osmNodes.push(node);
}
}
}
this.allOsmNodes.push(node);
if(this.allOsmNodes.indexOf(node) == -1){
this.allOsmNodes.push(node);
}
}
}
this.spinner.hide();
this.mapService.showNodes(this.osmNodes);
this.mapService.fitView();
if(this.osmNodes.length > 0){
this.mapService.showNodes(this.osmNodes);
this.mapService.fitView();
}
}
this.hasResults = (this.osmNodes.length > 0 || this.dataGroups.length > 0);
this.hasResults = (this.osmNodes.length > 0 || this.nominatimNodes.length > 0 || this.dataGroups.length > 0);
}
parseNominatimResult(response){
this.nominatimNodes.length = 0;
console.log("Nominatim-result:");
console.log(JSON.stringify(response));
for(let item of response){
let nodeData={
id:item['osm_id'],
lon:parseFloat(item['lon']),
lat:parseFloat(item['lat']),
type:item['osm_type'],
name:item['display_name']
};
let node = OsmNodeFactory.create(nodeData);
console.log("From nominatim: ");
console.log(JSON.stringify(node));
this.nominatimNodes.push(node);
this.allOsmNodes.push(node);
this.hasResults = (this.osmNodes.length > 0 || this.nominatimNodes.length > 0 || this.dataGroups.length > 0);
}
}
parseError(error){
this.spinner.hide();
}
......@@ -148,6 +186,7 @@ export class SearchComponent implements OnInit {
this.hasResults = false;
//this.spinner.show();
this.apiService.searchGeoElements(this.searchForm.value.searchPattern).subscribe((response)=>{this.parseSearchResult(response);},(error)=>{this.parseError(error);});
this.nominatimService.search(this.searchForm.value.searchPattern).subscribe((response)=>{this.parseNominatimResult(response)},(error)=>{console.log("error reading from nominatim");});
}
ngOnInit() {
}
......
......@@ -230,6 +230,7 @@
this.currentNodeSet=new Array<OsmNode>();
this.currentNodeSet.push(node);
this.logger.debug("Going to "+JSON.stringify(node,null,3));
this.view = new OlView({
center: fromLonLat([(node.lon),(node.lat)]),
zoom: 14
......@@ -247,7 +248,7 @@
});
this.map.addLayer(this.iconLayer);
this.fitView();
}
removeConnection(lhs:OsmNode,rhs:OsmNode){
......
import { TestBed } from '@angular/core/testing';
import { NominatimService } from './nominatim.service';
describe('NominatimService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: NominatimService = TestBed.get(NominatimService);
expect(service).toBeTruthy();
});
});
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpResponse, HttpErrorResponse } from '@angular/common/http';
import { LogService } from '../services/log.service';
import { CacheService } from '../services/cache.service';
import { map, tap, catchError} from 'rxjs/operators';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class NominatimService {
apiURL="https://nominatim.openstreetmap.org/"
constructor(private httpClient: HttpClient, private cache: CacheService, private logger: LogService) { }
search(term:String){
return this.httpClient.get(this.apiURL+"?q="+term+"&format=jsonv2");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment