Add overpass service
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { Component, signal } from '@angular/core';
|
import { Component, signal } from '@angular/core';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { LeafletModule } from '@bluehalo/ngx-leaflet';
|
import { LeafletModule } from '@bluehalo/ngx-leaflet';
|
||||||
|
import { Overpass } from '../overpass';
|
||||||
import * as L from 'leaflet';
|
import * as L from 'leaflet';
|
||||||
|
|
||||||
import * as D from './details';
|
import * as D from './details';
|
||||||
@@ -44,10 +45,13 @@ export class Map {
|
|||||||
OpenStreetMap: this.osm,
|
OpenStreetMap: this.osm,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
constructor(private overpass: Overpass) {}
|
||||||
|
|
||||||
onMapReady(map: L.Map) {
|
onMapReady(map: L.Map) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.layerControl.addTo(this.map);
|
this.layerControl.addTo(this.map);
|
||||||
this.loadBuildings().addTo(this.map);
|
this.loadBuildings().addTo(this.map);
|
||||||
|
this.queryBuildings();
|
||||||
console.log('Map is ready');
|
console.log('Map is ready');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,4 +94,11 @@ export class Map {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
queryBuildings() {
|
||||||
|
this.overpass.fetchBuildings('E').subscribe((data) => {
|
||||||
|
console.log('Fetched building data from Overpass API:', data);
|
||||||
|
// Here you would typically process the data and add it to the map
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/app/overpass.spec.ts
Normal file
16
src/app/overpass.spec.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { Overpass } from './overpass';
|
||||||
|
|
||||||
|
describe('Overpass', () => {
|
||||||
|
let service: Overpass;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(Overpass);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
26
src/app/overpass.ts
Normal file
26
src/app/overpass.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class Overpass {
|
||||||
|
private readonly apiUrl = 'https://overpass-api.de/api/interpreter';
|
||||||
|
|
||||||
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
|
fetchBuildings(building_name: string) {
|
||||||
|
const header = { 'Content-Type': 'text/plain' };
|
||||||
|
const query = `
|
||||||
|
[out:json][timeout:25];
|
||||||
|
nwr["name"="${building_name}"](49.014442, 8.387954, 49.017847, 8.395448)->.building;
|
||||||
|
(
|
||||||
|
nwr["indoor"="room"](area.building);
|
||||||
|
);
|
||||||
|
(._;>;);
|
||||||
|
out body;
|
||||||
|
`;
|
||||||
|
|
||||||
|
return this.http.post(this.apiUrl, query, { headers: header });
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user