mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 21:19:01 +01:00 
			
		
		
		
	feat(mindmap): save view center coordinates
This commit is contained in:
		
							parent
							
								
									2b8ee31be3
								
							
						
					
					
						commit
						5cefd4f50a
					
				@ -1,3 +1,4 @@
 | 
			
		||||
import type { Map } from "leaflet";
 | 
			
		||||
import library_loader from "../services/library_loader.js";
 | 
			
		||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
 | 
			
		||||
 | 
			
		||||
@ -17,8 +18,12 @@ const TPL = `\
 | 
			
		||||
 | 
			
		||||
export default class GeoMapWidget extends NoteContextAwareWidget {
 | 
			
		||||
 | 
			
		||||
    constructor(widgetMode: "type") {
 | 
			
		||||
    map?: Map;
 | 
			
		||||
    private initCallback?: () => void;
 | 
			
		||||
 | 
			
		||||
    constructor(widgetMode: "type", initCallback?: () => void) {
 | 
			
		||||
        super();
 | 
			
		||||
        this.initCallback = initCallback;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    doRender() {
 | 
			
		||||
@ -35,6 +40,10 @@ export default class GeoMapWidget extends NoteContextAwareWidget {
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
                map.setView([51.505, -0.09], 13);
 | 
			
		||||
                this.map = map;
 | 
			
		||||
                if (this.initCallback) {
 | 
			
		||||
                    this.initCallback();
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
 | 
			
		||||
                    attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
 | 
			
		||||
 | 
			
		||||
@ -15,7 +15,8 @@ export default class GeoMapTypeWidget extends TypeWidget {
 | 
			
		||||
    constructor() {
 | 
			
		||||
        super();
 | 
			
		||||
 | 
			
		||||
        this.geoMapWidget = new GeoMapWidget("type");
 | 
			
		||||
        this.geoMapWidget = new GeoMapWidget("type", () => this.#onMapInitialized());
 | 
			
		||||
 | 
			
		||||
        this.child(this.geoMapWidget);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -26,6 +27,27 @@ export default class GeoMapTypeWidget extends TypeWidget {
 | 
			
		||||
        super.doRender();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #onMapInitialized() {
 | 
			
		||||
        this.geoMapWidget.map?.on("moveend", () => this.spacedUpdate.scheduleUpdate());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    getData(): any {
 | 
			
		||||
        const map = this.geoMapWidget.map;
 | 
			
		||||
        if (!map) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const data = {
 | 
			
		||||
            view: {
 | 
			
		||||
                center: map.getBounds().getCenter()
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        return {
 | 
			
		||||
            content: JSON.stringify(data)
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async doRefresh(note: FNote) {
 | 
			
		||||
        await this.geoMapWidget.refresh();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user