feat(geomap): restore view coordinates

This commit is contained in:
Elian Doran 2025-01-20 22:19:07 +02:00
parent 5cefd4f50a
commit f66f437c8e
No known key found for this signature in database
2 changed files with 25 additions and 4 deletions

View File

@ -39,7 +39,6 @@ export default class GeoMapWidget extends NoteContextAwareWidget {
});
map.setView([51.505, -0.09], 13);
this.map = map;
if (this.initCallback) {
this.initCallback();

View File

@ -1,9 +1,16 @@
import type { LatLng } from "leaflet";
import type FNote from "../../entities/fnote.js";
import GeoMapWidget from "../geo_map.js";
import TypeWidget from "./type_widget.js"
const TPL = `<div class="note-detail-geo-map note-detail-printable"></div>`;
interface MapData {
view?: {
center: LatLng | [ number, number ];
}
}
export default class GeoMapTypeWidget extends TypeWidget {
private geoMapWidget: GeoMapWidget;
@ -27,8 +34,23 @@ export default class GeoMapTypeWidget extends TypeWidget {
super.doRender();
}
#onMapInitialized() {
this.geoMapWidget.map?.on("moveend", () => this.spacedUpdate.scheduleUpdate());
async #onMapInitialized() {
const map = this.geoMapWidget.map;
if (!map) {
throw new Error("Unable to load map.");
}
const blob = await this.note?.getBlob();
let parsedContent: MapData = {};
if (blob) {
parsedContent = JSON.parse(blob.content);
}
console.log(parsedContent);
const center = parsedContent.view?.center ?? [51.505, -0.09];
map.setView(center, 13);
map.on("moveend", () => this.spacedUpdate.scheduleUpdate());
}
getData(): any {
@ -37,7 +59,7 @@ export default class GeoMapTypeWidget extends TypeWidget {
return;
}
const data = {
const data: MapData = {
view: {
center: map.getBounds().getCenter()
}