always use callback in tiles.fetch (formerly polylines)
This commit is contained in:
parent
406cedbce1
commit
4aa140c264
@ -67,6 +67,7 @@ label.readout {
|
||||
:zoom 17
|
||||
:course 0 ; direction of travel
|
||||
:orientation 0 ; map rotation angle from north
|
||||
:tiles {}
|
||||
}
|
||||
)
|
||||
|
||||
@ -198,6 +199,13 @@ label.readout {
|
||||
|
||||
(var map-surface nil)
|
||||
|
||||
(fn fetch-tiles [bounds tbl zoom]
|
||||
(for [x bounds.min.x bounds.max.x]
|
||||
(for [y bounds.min.y bounds.max.y]
|
||||
(let [k (tiles.name x y zoom)]
|
||||
(when (not (. tbl k))
|
||||
(tiles.fetch cq x y zoom #(tset tbl k $1)))))))
|
||||
|
||||
(fn draw-onto-map-surface [surface bounds zoom]
|
||||
(let [{ : num-tiles-x : num-tiles-y } bounds
|
||||
road-width 14
|
||||
@ -205,9 +213,7 @@ 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
|
||||
#(set map-surface nil)
|
||||
))))
|
||||
(merge lines (or (. app-state.tiles (tiles.name x y zoom)) {}))))
|
||||
|
||||
(let [seen-road-names {}
|
||||
g (cairo.Context.create surface)]
|
||||
@ -314,6 +320,7 @@ label.readout {
|
||||
(let [bounds
|
||||
(map-bounds app-state.lat app-state.lon app-state.zoom)]
|
||||
(when (not (bounds= old-bounds bounds))
|
||||
(fetch-tiles bounds app-state.tiles app-state.zoom)
|
||||
(set map-surface nil)))
|
||||
(set app-state.orientation
|
||||
(+ app-state.orientation
|
||||
|
@ -112,33 +112,26 @@
|
||||
(fn tile-name [x y zoom]
|
||||
(.. x "_" y "_" zoom))
|
||||
|
||||
(fn polylines [cq x y zoom cb]
|
||||
(let [k (tile-name x y zoom)
|
||||
(fn fetch [cq x y zoom cb]
|
||||
(let [k (tile-name x y zoom)
|
||||
pathname (.. "/tmp/tiles/" k ".json")]
|
||||
(if (file-exists? pathname)
|
||||
(let [data (with-open [i (io.open pathname :r)] (i:read "*a"))]
|
||||
(if (= data "")
|
||||
[]
|
||||
(canvas (. (json.decode data) :elements) zoom)))
|
||||
(let [payload (with-open [i (io.open pathname :r)] (i:read "*a"))]
|
||||
(when (not (= payload ""))
|
||||
(cb (canvas (. (json.decode payload) :elements) zoom))))
|
||||
(let [out (io.open pathname :w)]
|
||||
(cq:wrap (fn []
|
||||
(print "getting " k)
|
||||
(var json nil)
|
||||
(var payload nil)
|
||||
(with-open [f out]
|
||||
(while (not json)
|
||||
(set json (unparsed-for-xyz x y zoom))
|
||||
(when (not json)
|
||||
(while (not payload)
|
||||
(set payload (unparsed-for-xyz x y zoom))
|
||||
(when (not payload)
|
||||
(print "sleeping " k)
|
||||
(cqueues.sleep (math.random 2 6))))
|
||||
(print "got " k)
|
||||
(f:write json)
|
||||
(cb)
|
||||
true)))
|
||||
[] ; return no lines for now
|
||||
))))
|
||||
(f:write payload)
|
||||
(cb (canvas (. (json.decode payload) :elements) zoom))
|
||||
true)))))))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{ : polylines : latlon->tile :name tile-name }
|
||||
{ : fetch : latlon->tile :name tile-name }
|
||||
|
Loading…
Reference in New Issue
Block a user