Commit fe189193 authored by Sebastian's avatar Sebastian

osm-tags

parent adcabe70
......@@ -254,15 +254,18 @@ export class OsmNode {
return (this.osmType != "" && this.osmId != -1)
}
getOSMTagKeys(){
clearOsmTags(){
this.osmtags.length=0;
}
getOsmTagKeys(){
let keys = new Array<String>();
for(let tag in this.osmtags){
keys.push(tag);
}
return keys;
}
getOSMTagValue(key){
getOsmTagValue(key){
return this.osmtags[key];
}
......@@ -273,12 +276,15 @@ export class OsmNode {
}
}
addOsmTag(tag: Tag){
this.osmtags.push(tag);
}
hasOsmTag(tag:Tag){
return (this.osmtags.indexOf(tag,0)>-1);
}
addTag(tag:Tag){
if(!this.tags){
this.tags = new Array<Tag>();
......@@ -419,6 +425,16 @@ export class OsmNode {
}
return Date();
}
getOsmType(){
return this.osmType;
}
getOsmId(){
return this.osmId;
}
hasOsmTags(){
return this.osmtags.length != 0;
}
debugString():string{
let debugString : string;
debugString = "Name: " + this.name + "\n";
......@@ -438,7 +454,11 @@ export class OsmNode {
debugString += "null\n";
}
for(let tag of this.tags){
debugString += "\t ["+tag.key + "]=["+tag.value+"]\n";
debugString += "Tag\t ["+tag.key + "]=["+tag.value+"]\n";
}
debugString += "OSM-Tags: \n";
for(let tag of this.osmtags){
debugString += "OSM-Tag\t ["+tag.key + "]=["+tag.value+"]\n";
}
debugString += "DataGroups:\n";
if(!this.dataGroups){
......
export class Tag{
constructor(public key:String,public value:String, public id?: number){};
constructor(public key:String,public value:String, public id?: number){};
}
\ No newline at end of file
......@@ -255,6 +255,16 @@
id="elementTyp">{{nodeService.detailView.osmType}}</span>
</div>
</div>
<div *ngFor="let tag of nodeService.detailView.osmtags"
class="form-group row item-detail">
<label for="elementKey" class="col-sm-4 col-form-label">
<strong>{{translateTagKey(tag.key)}}</strong>
</label>
<div class="col">
<span class="form-control-plaintext" id="elementKey">{{tag.value}}</span><i aria-hidden="true" class="fa fa-link fa-lg"></i>
</div>
</div>
<div *ngFor="let tag of nodeService.detailView.tags"
class="form-group row item-detail">
<label for="elementKey" class="col-sm-4 col-form-label">
......
......@@ -143,14 +143,25 @@ export class SearchComponent implements OnInit {
translateTagValue(value:string){
switch(value){
default:{
return value;
}
}
}
translateTagKey(key:string){
switch(key){
case 'contact:website':{
return 'web';
}
case 'addr:street':{
return 'Straße';
}
case 'addr:housename':{
return 'Gebäudename';
}
case 'addr:housenumber':{
return 'Hausnr.';
}
......
......@@ -11,10 +11,12 @@ import { Message } from '../models/Message';
import { OsmNode } from '../models/OsmNode';
import { Rectangle } from '../models/Rectangle';
@Injectable({
providedIn: 'root'
})
export class GeoportalApiService {
httpOptions = {
......
......@@ -73,11 +73,19 @@ export class OsmNodeService {
}
showDetails(node:OsmNode){
this.detailView = node;
if(node != null){
this.overpass.getOsmTags(node);
}else{
this.debug("Warning: showDetails called with null");
}
this.showDetailsWidget();
if(node){
if(!node.hasCoordinates()){
this.fillNode(node);
}
this.updateElementFromServer(node);
}
......@@ -262,5 +270,8 @@ export class OsmNodeService {
);
}
}
debug(msg: string){
this.logger.debug("OsmNodeService: "+msg);
}
}
......@@ -2,6 +2,8 @@ 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 { OsmNode } from '../models/OsmNode';
import { Tag } from '../models/Tag';
import { map, tap, catchError} from 'rxjs/operators';
import { Observable } from 'rxjs';
......@@ -12,32 +14,80 @@ export class OverpassService {
private apiURL="http://overpass-api.de/api/interpreter";
constructor(private httpClient: HttpClient, private cache: CacheService, private logger: LogService) { }
debug(msg:string){
this.logger.debug("OverpassService: "+msg);
}
getNodesByIdArray(ids :Array<number>){
this.logger.debug("Getting array of nodes.");
this.debug("Getting array of nodes.");
let query="";
for(let id of ids){
query += "node(" + id + ");";
}
return this.httpClient.get(this.apiURL + '?data=[out:json];(' + query + ');out;');
}
}
getOsmTags(node: OsmNode){
this.debug("Reading osm-tags from overpass.");
let query="";
switch(node.getOsmType()){
case 'node':{
query='node('+node.getOsmId()+');';
break;
}
case 'way':{
query='way('+node.getOsmId()+');';
break;
}
case 'relation':{
query='relation('+node.getOsmId()+');';
break;
}
default:{
this.debug("unsupported type: "+ node.getOsmType());
return false;
}
}
this.httpClient.get(this.apiURL + '?data=[out:json];(' + query + ');out;').subscribe(
(data)=>{
if(data['elements'] && data['elements'].length == 1){
if(data['elements'][0]['tags']){
let tags = data['elements'][0]['tags'];
node.clearOsmTags();
for(let key in tags){
let tag = new Tag(key,tags[key]);
node.addOsmTag(tag);
//this.debug("Adding tag: "+JSON.stringify(tag));
}
}else{
//this.debug("no tags in this response: \n" +JSON.stringify(data,null,3));
}
}else{
//this.debug("no elements in this response.");
}
},
(error)=>{
this.debug(JSON.stringify(error));
}
);
}
getNodeById(id:number){
let query="node(" + id + ");";
this.logger.debug("overpass.service: getting node: "+id);
this.debug("getting node: "+id);
return this.httpClient.get(this.apiURL + '?data=[out:json];' + query + 'out;');
}
getWayById(id:number){
this.logger.debug("overpass.service: getting way: "+id);
this.debug("getting way: "+id);
let query="way(" + id + ");";
return this.httpClient.get(this.apiURL + '?data=[out:json];' + query + 'out;');
}
getRelationById(id:number){
this.logger.debug("overpass.service: getting way: "+id);
this.debug("getting way: "+id);
let query="relation(" + id + ");";
return this.httpClient.get(this.apiURL + '?data=[out:json];' + query + 'out;');
}
......
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