From 39a2e494229a1afaf397c5a9b399ffd0c397dc14 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Mon, 2 Jun 2025 13:33:51 +0100 Subject: [PATCH] add on-completion callback to tile fetcher, invalidate map-surface --- pkgs/maps/main.fnl | 7 +++++-- pkgs/maps/tiles.fnl | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl index 73db50c..f6e894a 100644 --- a/pkgs/maps/main.fnl +++ b/pkgs/maps/main.fnl @@ -91,6 +91,8 @@ label.readout { (local cq (cqueues.new)) +(var map-surface nil) + (fn cairo-the-map [window] (let [{ : lat : lon : zoom } app-state { : num-tiles-x : num-tiles-y &as bounds } (map-bounds lat lon zoom) @@ -98,7 +100,9 @@ label.readout { (for [x bounds.min.x bounds.max.x] (for [y bounds.min.y bounds.max.y] - (merge lines (tiles.polylines cq x y zoom)))) + (merge lines (tiles.polylines cq x y zoom + #(set map-surface nil) + )))) (let [map-surface (window:create_similar_surface @@ -126,7 +130,6 @@ label.readout { (g:stroke) map-surface))) -(var map-surface nil) (fn on-osm-draw [widget g] (when (not map-surface) diff --git a/pkgs/maps/tiles.fnl b/pkgs/maps/tiles.fnl index 7a4f306..9880df4 100644 --- a/pkgs/maps/tiles.fnl +++ b/pkgs/maps/tiles.fnl @@ -104,7 +104,7 @@ ;; we'd like to have a way for completed background fetch to signal ;; so that the map can be redrawn -(fn polylines [cq x y zoom] +(fn polylines [cq x y zoom cb] (let [k (.. x "_" y "_" zoom) pathname (.. "/tmp/tiles/" k ".json")] (if (file-exists? pathname) @@ -124,6 +124,7 @@ (cqueues.sleep (math.random 2 6)))) (print "got " k) (f:write json) + (cb) true))) [] ; return no lines for now ))))