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 _message: string;
|
||||||
private _items: BlakusItem[];
|
private _items: BlakusItem[];
|
||||||
private _locationServiceBaseURL = 'https://api.kartes.lv/v3/KVDM_mwwKi/'
|
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() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -93,45 +93,21 @@ export class HelloWorldModel extends Observable {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
overpassQuery(query: string) {
|
getBlakus(params = new URLSearchParams()) {
|
||||||
const url = new URL(`interpreter?data=${encodeURIComponent(query)}`, this._overpassBaseURL).toString();
|
const url = new URL(`blakus?${params.toString()}`, this._blakusBaseURL).toString();
|
||||||
console.log('overpass query', url)
|
console.log('blakus query', url)
|
||||||
return Http.getJSON<OverpassResult>(url)
|
return Http.getJSON<OverpassResult["elements"]>(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOverpassAmenities({latitude, longitude}: Location) {
|
async getOverpassAmenities({latitude, longitude}: Location) {
|
||||||
const radius = 1000; // meters
|
const params = new URLSearchParams();
|
||||||
const query = `
|
params.set('lat', latitude.toString());
|
||||||
[out:json][timeout:25];
|
params.set('lon', longitude.toString());
|
||||||
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']))));
|
|
||||||
}
|
|
||||||
|
|
||||||
async getOverpassInfo({latitude, longitude}: Location) {
|
const result = await this.getBlakus(params);
|
||||||
|
console.log(result);
|
||||||
const radius = 1000; // meters
|
this.items = result.map(({ tags }) => ({ title: tags.name, amenity: tags.amenity, tags}))
|
||||||
const amenities = ['restaurant', 'cafe', 'bar', 'pub', 'biergarten', 'fast_food', 'food_court', 'ice_cream'];
|
// .filter(i => amenities.includes(i.amenity));
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async postalPolygons(country = 'LV', code: string, mode: 'isolate' | 'collect' | 'union' = 'union') {
|
async postalPolygons(country = 'LV', code: string, mode: 'isolate' | 'collect' | 'union' = 'union') {
|
||||||
@ -152,13 +128,7 @@ export class HelloWorldModel extends Observable {
|
|||||||
|
|
||||||
async onLocationTap() {
|
async onLocationTap() {
|
||||||
const location = await DeviceLocation.getDeviceLocation();
|
const location = await DeviceLocation.getDeviceLocation();
|
||||||
await this.getOverpassInfo(location);
|
await this.getOverpassAmenities(location);
|
||||||
// await this.getOverpassAmenities(location);
|
|
||||||
// const { index } = await this.reverseGeocode(location);
|
|
||||||
// const [country, code] = index.split('-');
|
|
||||||
// await this.postalPolygons(country, code);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onTap() {
|
onTap() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user