From fef52f812a3ba2d845c473e8ab5e617537c89fd3 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 097c80c..e57bef0 100644 --- a/pkgs/maps/main.fnl +++ b/pkgs/maps/main.fnl @@ -150,6 +150,8 @@ label.readout { (* tile-size (- ny bounds.min.y)) (+ math.pi angle))))) +(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) @@ -158,7 +160,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 @@ -203,7 +207,6 @@ label.readout { 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 b3cb152..7defc3e 100644 --- a/pkgs/maps/tiles.fnl +++ b/pkgs/maps/tiles.fnl @@ -109,7 +109,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) @@ -129,6 +129,7 @@ (cqueues.sleep (math.random 2 6)))) (print "got " k) (f:write json) + (cb) true))) [] ; return no lines for now ))))