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