mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-09 17:52:32 +08:00
feat(geomap): restore view coordinates
This commit is contained in:
parent
5cefd4f50a
commit
f66f437c8e
@ -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();
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user