commit fef52f812a3ba2d845c473e8ab5e617537c89fd3
parent cdd7ea3a94d3f4fe12fb1a596400a62bbc3c00b0
Author: Daniel Barlow <dan@telent.net>
Date: Mon, 2 Jun 2025 13:33:51 +0100
add on-completion callback to tile fetcher, invalidate map-surface
Diffstat:
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git 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
@@ -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
))))