Refactor to use routes, make POIs linkable

This commit is contained in:
2026-01-16 13:22:00 +07:00
parent f95b4d6328
commit fad1eae552
10 changed files with 427 additions and 114 deletions

View File

@@ -22,4 +22,31 @@ out center;
const data = await res.json();
return data.elements;
}
async getPoiById(id) {
// Assuming 'id' is just the numeric ID.
// Overpass needs type(id). But we might not know the type (node, way, relation).
// We can query all types for this ID.
// However, typical usage often passes just the numeric ID.
// A query for just ID(numeric) is tricky without type.
// Let's assume 'node' first or try to query all three types by ID.
const query = `
[out:json][timeout:25];
(
node(${id});
way(${id});
relation(${id});
);
out center;
`.trim();
const url = `https://overpass-api.de/api/interpreter?data=${encodeURIComponent(
query
)}`;
const res = await fetch(url);
if (!res.ok) throw new Error('Overpass request failed');
const data = await res.json();
return data.elements[0]; // Return the first match
}
}

View File

@@ -2,9 +2,12 @@ import Service from '@ember/service';
import RemoteStorage from 'remotestoragejs';
import Places from '@remotestorage/module-places';
import Widget from 'remotestorage-widget';
import { tracked } from '@glimmer/tracking';
export default class StorageService extends Service {
rs;
@tracked savedPlaces = [];
@tracked version = 0; // Shared version tracker for bookmarks
constructor() {
super(...arguments);
@@ -21,9 +24,46 @@ export default class StorageService extends Service {
// const widget = new Widget(this.rs);
// widget.attach();
this.rs.on('ready', () => {
this.loadAllPlaces();
});
this.rs.scope('/places/').on('change', () => {
this.loadAllPlaces();
});
}
get places() {
return this.rs.places;
}
notifyChange() {
this.version++;
this.loadAllPlaces();
}
async loadAllPlaces() {
try {
const places = await this.rs.places.listAll();
if (places && Array.isArray(places)) {
this.savedPlaces = places;
} else {
this.savedPlaces = [];
}
console.log('Loaded saved places:', this.savedPlaces.length);
} catch (e) {
console.error('Failed to load places:', e);
}
}
findPlaceById(id) {
// Search by internal ID first
let place = this.savedPlaces.find((p) => p.id === id);
if (place) return place;
// Then search by OSM ID
place = this.savedPlaces.find((p) => p.osmId === id);
return place;
}
}