diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl index dc35283..2c6f418 100644 --- a/pkgs/maps/main.fnl +++ b/pkgs/maps/main.fnl @@ -71,7 +71,7 @@ label.readout { (collect [k v (pairs table2) &into table1] k v)) -(var map-surface nil) + (fn map-bounds [lat lon zoom] (let [num-tiles-x (+ 1 (math.ceil (/ map-width tile-size))) @@ -122,6 +122,7 @@ label.readout { (g:stroke) map-surface))) +(var map-surface nil) (fn on-osm-draw [widget g] (when (not map-surface) @@ -177,16 +178,24 @@ label.readout { (fn update-app-state [new-vals] - (merge app-state new-vals) - (each [name widget (pairs state-widgets)] - (case name - :speed (widget:set_label - (string.format "%.1f km/h" (* app-state.speed 3.6))) - :osm (: (widget:get_window) :invalidate_rect nil) - :arrow (: (widget:get_window) :invalidate_rect nil) - :time (widget:set_label - (hhmmss (+ utc-offset app-state.time-of-day))) - ))) + (let [old-bounds + (map-bounds app-state.lat app-state.lon app-state.zoom)] + (merge app-state new-vals) + (let [bounds + (map-bounds app-state.lat app-state.lon app-state.zoom)] + (when (or + (not (= old-bounds.min.x bounds.min.x)) + (not (= old-bounds.min.y bounds.min.y))) + (set map-surface nil))) + (each [name widget (pairs state-widgets)] + (case name + :speed (widget:set_label + (string.format "%.1f km/h" (* app-state.speed 3.6))) + :osm (: (widget:get_window) :invalidate_rect nil) + :arrow (: (widget:get_window) :invalidate_rect nil) + :time (widget:set_label + (hhmmss (+ utc-offset app-state.time-of-day))) + )))) (fn readouts []