fetch enough tiles to cover the display
This commit is contained in:
parent
995880e5a3
commit
86682a2ad6
@ -75,39 +75,51 @@ label.readout {
|
|||||||
;; on the screen, and enough tiles either side of it
|
;; on the screen, and enough tiles either side of it
|
||||||
;; to fill the width of the screen plus a bit
|
;; to fill the width of the screen plus a bit
|
||||||
|
|
||||||
(fn osm-widget []
|
(fn cairo-the-map [self g]
|
||||||
(let [height tile-size
|
(let [{ : lat : lon : zoom } app-state
|
||||||
num-tiles-x (+ 1 (math.ceil (/ map-width tile-size)))
|
num-tiles-x (+ 0 (math.ceil (/ map-width tile-size)))
|
||||||
num-tiles-y (+ 1 (math.ceil (/ map-height tile-size)))
|
num-tiles-y (+ 0 (math.ceil (/ map-height tile-size)))
|
||||||
|
; _ (print app-state.lat app-state.lon)
|
||||||
(tile-x tile-y) (tiles.latlon->tile app-state.lat app-state.lon app-state.zoom)
|
(tile-x tile-y) (tiles.latlon->tile app-state.lat app-state.lon app-state.zoom)
|
||||||
min-tile-x (math.floor (- tile-x (/ num-tiles-x 2)))
|
min-tile-x (math.floor (- tile-x (/ num-tiles-x 2)))
|
||||||
max-tile-x (math.ceil (+ tile-x (/ num-tiles-x 2)))
|
max-tile-x (math.ceil (+ tile-x (/ num-tiles-x 2)))
|
||||||
min-tile-y (math.floor (- tile-y (/ num-tiles-y 2)))
|
min-tile-y (math.floor (- tile-y (/ num-tiles-y 2)))
|
||||||
max-tile-y (math.ceil (+ tile-y (/ num-tiles-y 2)))
|
max-tile-y (math.ceil (+ tile-y (/ num-tiles-y 2)))
|
||||||
|
|
||||||
|
left-edge (- tile-x (/ map-width 2 tile-size))
|
||||||
|
top-edge (- tile-y (/ map-height 2 tile-size))
|
||||||
|
|
||||||
lines []]
|
lines []]
|
||||||
|
|
||||||
(for [x min-tile-x max-tile-x]
|
(for [x min-tile-x max-tile-x]
|
||||||
(for [y min-tile-y max-tile-y]
|
(for [y min-tile-y max-tile-y]
|
||||||
(print :x x :y y)
|
(merge lines (tiles.polylines x y zoom))))
|
||||||
(merge lines (tiles.polylines x y app-state.zoom))))
|
|
||||||
|
|
||||||
(Gtk.Label {
|
;; put tile-x and tile-y in the centre of the visible area.
|
||||||
:width height :height height
|
(g:translate (* tile-size (- min-tile-x left-edge))
|
||||||
:on_draw
|
(* tile-size (- min-tile-y top-edge)))
|
||||||
(fn [self g]
|
|
||||||
(print app-state.lat app-state.lon )
|
(g:set_source_rgb 0.2 0.2 0.4)
|
||||||
(g:set_source_rgb 0.2 0.2 0.4)
|
(g:set_line_width 3)
|
||||||
(g:set_line_width 3)
|
(each [_ line (pairs lines)]
|
||||||
(each [_ line (pairs lines)]
|
(case line
|
||||||
(case line
|
[[sx sy] & more]
|
||||||
[[sx sy] & more]
|
(do
|
||||||
(do
|
(g:move_to (* tile-size (- sx min-tile-x))
|
||||||
(g:move_to sx sy)
|
(* tile-size (- sy min-tile-y)))
|
||||||
(each [_ [x y] (ipairs more)]
|
(each [_ [x y] (ipairs more)]
|
||||||
(g:line_to x y)))))
|
(let [x1 (* tile-size (- x min-tile-x))
|
||||||
(g:stroke)
|
y1 (* tile-size (- y min-tile-y))]
|
||||||
true)
|
(g:line_to x1 y1))))))
|
||||||
})))
|
(g:stroke)
|
||||||
|
true))
|
||||||
|
|
||||||
|
|
||||||
|
(fn osm-widget []
|
||||||
|
(Gtk.Label {
|
||||||
|
:width map-width :height map-height
|
||||||
|
:on_draw cairo-the-map
|
||||||
|
}))
|
||||||
|
|
||||||
(fn readout [name text]
|
(fn readout [name text]
|
||||||
(let [w
|
(let [w
|
||||||
|
@ -45,7 +45,6 @@
|
|||||||
|
|
||||||
(fn overpass [lat lon zoom]
|
(fn overpass [lat lon zoom]
|
||||||
(let [width (/ 360 (^ 2 zoom))
|
(let [width (/ 360 (^ 2 zoom))
|
||||||
_ (print :w zoom width)
|
|
||||||
n (+ lat width) ;XXX adjust for latitude
|
n (+ lat width) ;XXX adjust for latitude
|
||||||
w (- lon width)
|
w (- lon width)
|
||||||
s lat
|
s lat
|
||||||
@ -73,13 +72,12 @@
|
|||||||
(let [node (. nodes nd)
|
(let [node (. nodes nd)
|
||||||
(tx ty) (latlon->tile node.lat node.lon 17)]
|
(tx ty) (latlon->tile node.lat node.lon 17)]
|
||||||
;;(print e.tags.name e.id e.name node.lat node.lon)
|
;;(print e.tags.name e.id e.name node.lat node.lon)
|
||||||
[ (* 256 (- tx offset-x)) (* 256 (- ty offset-y)) ])))))
|
[ tx ty ])))))
|
||||||
lines))
|
lines))
|
||||||
|
|
||||||
(fn polylines [x y zoom]
|
(fn polylines-from-net [x y zoom]
|
||||||
(let [(lat lon) (tile->latlon x y zoom)
|
(let [(lat lon) (tile->latlon x y zoom)
|
||||||
o (overpass lat lon zoom)
|
o (overpass lat lon zoom)
|
||||||
_ (print :polylines x y o)
|
|
||||||
r
|
r
|
||||||
(req.new_from_uri
|
(req.new_from_uri
|
||||||
"https://overpass-api.de/api/interpreter")
|
"https://overpass-api.de/api/interpreter")
|
||||||
@ -91,4 +89,16 @@
|
|||||||
data (json.decode (stream:get_body_as_string))]
|
data (json.decode (stream:get_body_as_string))]
|
||||||
(canvas data.elements (math.floor tx) (math.floor ty)))))
|
(canvas data.elements (math.floor tx) (math.floor ty)))))
|
||||||
|
|
||||||
|
(local cache {})
|
||||||
|
|
||||||
|
(fn polylines [x y zoom]
|
||||||
|
(let [k (.. x "/" y "/" zoom)
|
||||||
|
lines (. cache k)]
|
||||||
|
(print k (not (not lines)))
|
||||||
|
(if lines
|
||||||
|
(do (print "cached! " x y zoom) lines)
|
||||||
|
(let [lines (polylines-from-net x y zoom)]
|
||||||
|
(tset cache k lines)
|
||||||
|
lines))))
|
||||||
|
|
||||||
{ : polylines : latlon->tile }
|
{ : polylines : latlon->tile }
|
||||||
|
Loading…
Reference in New Issue
Block a user