mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-28 10:32:27 +08:00
fix(geomap): stuck viewport and zoom when switching between two geomaps
This commit is contained in:
parent
c7d75b759c
commit
16caae191e
@ -135,10 +135,22 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
|||||||
throw new Error(t("geo-map.unable-to-load-map"));
|
throw new Error(t("geo-map.unable-to-load-map"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.note) {
|
this.#restoreViewportAndZoom();
|
||||||
return;
|
|
||||||
|
// Restore markers.
|
||||||
|
await this.#reloadMarkers();
|
||||||
|
|
||||||
|
const updateFn = () => this.spacedUpdate.scheduleUpdate();
|
||||||
|
map.on("moveend", updateFn);
|
||||||
|
map.on("zoomend", updateFn);
|
||||||
|
map.on("click", (e) => this.#onMapClicked(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async #restoreViewportAndZoom() {
|
||||||
|
const map = this.geoMapWidget.map;
|
||||||
|
if (!map || !this.note) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const blob = await this.note.getBlob();
|
const blob = await this.note.getBlob();
|
||||||
|
|
||||||
let parsedContent: MapData = {};
|
let parsedContent: MapData = {};
|
||||||
@ -150,14 +162,6 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
|||||||
const center = parsedContent.view?.center ?? DEFAULT_COORDINATES;
|
const center = parsedContent.view?.center ?? DEFAULT_COORDINATES;
|
||||||
const zoom = parsedContent.view?.zoom ?? DEFAULT_ZOOM;
|
const zoom = parsedContent.view?.zoom ?? DEFAULT_ZOOM;
|
||||||
map.setView(center, zoom);
|
map.setView(center, zoom);
|
||||||
|
|
||||||
// Restore markers.
|
|
||||||
await this.#reloadMarkers();
|
|
||||||
|
|
||||||
const updateFn = () => this.spacedUpdate.scheduleUpdate();
|
|
||||||
map.on("moveend", updateFn);
|
|
||||||
map.on("zoomend", updateFn);
|
|
||||||
map.on("click", (e) => this.#onMapClicked(e));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async #reloadMarkers() {
|
async #reloadMarkers() {
|
||||||
@ -343,6 +347,7 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
|||||||
|
|
||||||
async doRefresh(note: FNote) {
|
async doRefresh(note: FNote) {
|
||||||
await this.geoMapWidget.refresh();
|
await this.geoMapWidget.refresh();
|
||||||
|
this.#restoreViewportAndZoom();
|
||||||
await this.#reloadMarkers();
|
await this.#reloadMarkers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user