mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	feat(geomap): reload markers after adding a new note
This commit is contained in:
		
							parent
							
								
									f76b454d5a
								
							
						
					
					
						commit
						986a1c25be
					
				@ -43,6 +43,7 @@ export default class GeoMapTypeWidget extends TypeWidget {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    private geoMapWidget: GeoMapWidget;
 | 
					    private geoMapWidget: GeoMapWidget;
 | 
				
			||||||
    private clipboard?: Clipboard;
 | 
					    private clipboard?: Clipboard;
 | 
				
			||||||
 | 
					    private L!: Leaflet;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static getType() {
 | 
					    static getType() {
 | 
				
			||||||
        return "geoMap";
 | 
					        return "geoMap";
 | 
				
			||||||
@ -64,6 +65,7 @@ export default class GeoMapTypeWidget extends TypeWidget {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async #onMapInitialized(L: Leaflet) {
 | 
					    async #onMapInitialized(L: Leaflet) {
 | 
				
			||||||
 | 
					        this.L = L;
 | 
				
			||||||
        const map = this.geoMapWidget.map;
 | 
					        const map = this.geoMapWidget.map;
 | 
				
			||||||
        if (!map) {
 | 
					        if (!map) {
 | 
				
			||||||
            throw new Error("Unable to load map.");
 | 
					            throw new Error("Unable to load map.");
 | 
				
			||||||
@ -86,7 +88,23 @@ export default class GeoMapTypeWidget extends TypeWidget {
 | 
				
			|||||||
        map.setView(center, zoom);
 | 
					        map.setView(center, zoom);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Restore markers.
 | 
					        // 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() {
 | 
				
			||||||
 | 
					        const map = this.geoMapWidget.map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!this.note || !map) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const childNotes = await this.note.getChildNotes();
 | 
					        const childNotes = await this.note.getChildNotes();
 | 
				
			||||||
 | 
					        const L = this.L;
 | 
				
			||||||
        for (const childNote of childNotes) {
 | 
					        for (const childNote of childNotes) {
 | 
				
			||||||
            const latLng = childNote.getAttributeValue("label", LOCATION_ATTRIBUTE);
 | 
					            const latLng = childNote.getAttributeValue("label", LOCATION_ATTRIBUTE);
 | 
				
			||||||
            if (!latLng) {
 | 
					            if (!latLng) {
 | 
				
			||||||
@ -98,11 +116,6 @@ export default class GeoMapTypeWidget extends TypeWidget {
 | 
				
			|||||||
                .addTo(map)
 | 
					                .addTo(map)
 | 
				
			||||||
                .bindPopup(childNote.title);
 | 
					                .bindPopup(childNote.title);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
        const updateFn = () => this.spacedUpdate.scheduleUpdate();
 | 
					 | 
				
			||||||
        map.on("moveend", updateFn);
 | 
					 | 
				
			||||||
        map.on("zoomend", updateFn);
 | 
					 | 
				
			||||||
        map.on("click", (e) => this.#onMapClicked(e));
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async #onMapClicked(e: LeafletMouseEvent) {
 | 
					    async #onMapClicked(e: LeafletMouseEvent) {
 | 
				
			||||||
@ -158,4 +171,11 @@ export default class GeoMapTypeWidget extends TypeWidget {
 | 
				
			|||||||
        await this.geoMapWidget.refresh();
 | 
					        await this.geoMapWidget.refresh();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
 | 
				
			||||||
 | 
					        const attributeRows = loadResults.getAttributeRows();
 | 
				
			||||||
 | 
					        if (attributeRows.find((at) => at.name === LOCATION_ATTRIBUTE)) {
 | 
				
			||||||
 | 
					            this.#reloadMarkers();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user