mirror of
https://github.com/zadam/trilium.git
synced 2025-11-15 09:45:52 +01:00
feat(geo_map): add basic support for gpx files
This commit is contained in:
@@ -104,6 +104,7 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
||||
private _state: State;
|
||||
private L!: Leaflet;
|
||||
private currentMarkerData: MarkerData;
|
||||
private gpxLoaded?: boolean;
|
||||
|
||||
static getType() {
|
||||
return "geoMap";
|
||||
@@ -172,6 +173,11 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
||||
this.currentMarkerData = {};
|
||||
const childNotes = await this.note.getChildNotes();
|
||||
for (const childNote of childNotes) {
|
||||
if (childNote.mime === "application/gpx+xml") {
|
||||
this.#processNoteWithGpxTrack(childNote);
|
||||
continue;
|
||||
}
|
||||
|
||||
const latLng = childNote.getAttributeValue("label", LOCATION_ATTRIBUTE);
|
||||
if (latLng) {
|
||||
this.#processNoteWithMarker(childNote, latLng);
|
||||
@@ -179,6 +185,26 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
||||
}
|
||||
}
|
||||
|
||||
async #processNoteWithGpxTrack(note: FNote) {
|
||||
if (!this.L || !this.geoMapWidget.map) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.gpxLoaded) {
|
||||
await import("leaflet-gpx");
|
||||
this.gpxLoaded = true;
|
||||
}
|
||||
|
||||
// TODO: This is not very efficient as it's probably a string response that is parsed and then converted back to string and parsed again.
|
||||
const xmlResponse = await server.get<XMLDocument>(`notes/${note.noteId}/open`);
|
||||
const stringResponse = new XMLSerializer().serializeToString(xmlResponse);
|
||||
|
||||
const track = new this.L.GPX(stringResponse, {
|
||||
|
||||
});
|
||||
track.addTo(this.geoMapWidget.map);
|
||||
}
|
||||
|
||||
#processNoteWithMarker(note: FNote, latLng: string) {
|
||||
const map = this.geoMapWidget.map;
|
||||
if (!map) {
|
||||
|
||||
Reference in New Issue
Block a user