Connect ns app to api - currently a playground
All checks were successful
CI / main (push) Successful in 5m24s
All checks were successful
CI / main (push) Successful in 5m24s
This commit is contained in:
parent
3dd43deec0
commit
eee02f6a56
@ -47,7 +47,7 @@ export class HelloWorldModel extends Observable {
|
||||
private _message: string;
|
||||
private _items: BlakusItem[];
|
||||
private _locationServiceBaseURL = 'https://api.kartes.lv/v3/KVDM_mwwKi/'
|
||||
private _overpassBaseURL = 'https://overpass-api.de/api/';
|
||||
private _blakusBaseURL = 'https://192.168.0.155:3000';
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@ -93,45 +93,21 @@ export class HelloWorldModel extends Observable {
|
||||
return result;
|
||||
}
|
||||
|
||||
overpassQuery(query: string) {
|
||||
const url = new URL(`interpreter?data=${encodeURIComponent(query)}`, this._overpassBaseURL).toString();
|
||||
console.log('overpass query', url)
|
||||
return Http.getJSON<OverpassResult>(url)
|
||||
getBlakus(params = new URLSearchParams()) {
|
||||
const url = new URL(`blakus?${params.toString()}`, this._blakusBaseURL).toString();
|
||||
console.log('blakus query', url)
|
||||
return Http.getJSON<OverpassResult["elements"]>(url)
|
||||
}
|
||||
|
||||
async getOverpassAmenities({latitude, longitude}: Location) {
|
||||
const radius = 1000; // meters
|
||||
const query = `
|
||||
[out:json][timeout:25];
|
||||
node["amenity"](around:${radius}, ${latitude}, ${longitude});
|
||||
out tags;
|
||||
`;
|
||||
const result = await this.overpassQuery(query);
|
||||
console.log('yep');
|
||||
console.log(Array.from(new Set(result.elements.map(el => el.tags['amenity']))));
|
||||
}
|
||||
const params = new URLSearchParams();
|
||||
params.set('lat', latitude.toString());
|
||||
params.set('lon', longitude.toString());
|
||||
|
||||
async getOverpassInfo({latitude, longitude}: Location) {
|
||||
|
||||
const radius = 1000; // meters
|
||||
const amenities = ['restaurant', 'cafe', 'bar', 'pub', 'biergarten', 'fast_food', 'food_court', 'ice_cream'];
|
||||
|
||||
const query = `
|
||||
[out:json];
|
||||
node(around:${radius}, ${latitude}, ${longitude})["amenity"~"${amenities.join('|')}"];
|
||||
out body;
|
||||
>;
|
||||
out skel qt;
|
||||
`;
|
||||
|
||||
const result = await this.overpassQuery(query);
|
||||
this.items = result.elements
|
||||
.map(({ tags }) => ({ title: tags.name, amenity: tags.amenity, tags}))
|
||||
.filter(i => amenities.includes(i.amenity)); // query returns some random results. need to look into this
|
||||
|
||||
console.log(localize('app.name'))
|
||||
|
||||
console.log(result.elements);
|
||||
const result = await this.getBlakus(params);
|
||||
console.log(result);
|
||||
this.items = result.map(({ tags }) => ({ title: tags.name, amenity: tags.amenity, tags}))
|
||||
// .filter(i => amenities.includes(i.amenity));
|
||||
}
|
||||
|
||||
async postalPolygons(country = 'LV', code: string, mode: 'isolate' | 'collect' | 'union' = 'union') {
|
||||
@ -152,13 +128,7 @@ export class HelloWorldModel extends Observable {
|
||||
|
||||
async onLocationTap() {
|
||||
const location = await DeviceLocation.getDeviceLocation();
|
||||
await this.getOverpassInfo(location);
|
||||
// await this.getOverpassAmenities(location);
|
||||
// const { index } = await this.reverseGeocode(location);
|
||||
// const [country, code] = index.split('-');
|
||||
// await this.postalPolygons(country, code);
|
||||
|
||||
|
||||
await this.getOverpassAmenities(location);
|
||||
}
|
||||
|
||||
onTap() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user