mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 18:39:22 +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;
|
this.map = map;
|
||||||
if (this.initCallback) {
|
if (this.initCallback) {
|
||||||
this.initCallback();
|
this.initCallback();
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
|
import type { LatLng } from "leaflet";
|
||||||
import type FNote from "../../entities/fnote.js";
|
import type FNote from "../../entities/fnote.js";
|
||||||
import GeoMapWidget from "../geo_map.js";
|
import GeoMapWidget from "../geo_map.js";
|
||||||
import TypeWidget from "./type_widget.js"
|
import TypeWidget from "./type_widget.js"
|
||||||
|
|
||||||
const TPL = `<div class="note-detail-geo-map note-detail-printable"></div>`;
|
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 {
|
export default class GeoMapTypeWidget extends TypeWidget {
|
||||||
|
|
||||||
private geoMapWidget: GeoMapWidget;
|
private geoMapWidget: GeoMapWidget;
|
||||||
@ -27,8 +34,23 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
|||||||
super.doRender();
|
super.doRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
#onMapInitialized() {
|
async #onMapInitialized() {
|
||||||
this.geoMapWidget.map?.on("moveend", () => this.spacedUpdate.scheduleUpdate());
|
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 {
|
getData(): any {
|
||||||
@ -37,7 +59,7 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = {
|
const data: MapData = {
|
||||||
view: {
|
view: {
|
||||||
center: map.getBounds().getCenter()
|
center: map.getBounds().getCenter()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user