diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl index 09e7945..83d45c2 100644 --- a/pkgs/maps/main.fnl +++ b/pkgs/maps/main.fnl @@ -180,7 +180,7 @@ label.readout { (var map-surface nil) -(fn cairo-the-map [window] +(fn draw-onto-map-surface [surface] (let [{ : lat : lon : zoom } app-state { : num-tiles-x : num-tiles-y &as bounds } (map-bounds lat lon zoom) road-width 14 @@ -192,13 +192,8 @@ label.readout { #(set map-surface nil) )))) - (let [map-surface - (window:create_similar_surface - cairo.Content.COLOR - (* tile-size (+ 1 num-tiles-x)) - (* tile-size (+ 1 num-tiles-y))) - seen-road-names {} - g (cairo.Context.create map-surface)] + (let [seen-road-names {} + g (cairo.Context.create surface)] (g:set_source_rgb 0.7 0.8 0.8) (g:rectangle 0 0 (* tile-size num-tiles-x) (* tile-size num-tiles-y)) @@ -233,18 +228,23 @@ label.readout { (g:fill) (g:restore))))) - map-surface))) + surface))) (fn on-osm-draw [widget g] - (when (not map-surface) - (let [window (widget:get_window)] - (set map-surface (cairo-the-map window)))) - (let [(tile-x tile-y) (tiles.latlon->tile app-state.lat app-state.lon app-state.zoom) bounds (map-bounds-tile tile-x tile-y) offset-x (- (* tile-size (- tile-x bounds.min.x)) (/ map-width 2)) offset-y (- (* tile-size (- tile-y bounds.min.y)) (/ map-height 2))] + (when (not map-surface) + (let [window (widget:get_window)] + (set map-surface + (doto + (window:create_similar_surface + cairo.Content.COLOR + (* tile-size bounds.num-tiles-x) + (* tile-size bounds.num-tiles-y)) + draw-onto-map-surface)))) (g:set_source_surface map-surface (- offset-x) (- offset-y)) (g:set_operator cairo.Operator.SOURCE)