mirror of
https://github.com/rastapasta/mapscii.git
synced 2025-03-19 16:36:55 +01:00
🐁 keep drawing the map while dragging it
This commit is contained in:
parent
df6c6fd932
commit
80edcc3f04
@ -27,14 +27,12 @@ module.exports = class Termap
|
|||||||
mouseDragging: false
|
mouseDragging: false
|
||||||
|
|
||||||
center:
|
center:
|
||||||
lat: 49.019855
|
lat: 0
|
||||||
lng: 12.096956
|
lng: 0
|
||||||
|
|
||||||
zoom: 2
|
zoom: 0
|
||||||
view: [0, 0]
|
view: [0, 0]
|
||||||
|
|
||||||
scale: 4
|
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
@_initControls()
|
@_initControls()
|
||||||
@_initRenderer()
|
@_initRenderer()
|
||||||
@ -66,14 +64,14 @@ module.exports = class Termap
|
|||||||
|
|
||||||
_resizeRenderer: (cb) ->
|
_resizeRenderer: (cb) ->
|
||||||
@width = process.stdout.columns >> 1 << 2
|
@width = process.stdout.columns >> 1 << 2
|
||||||
@height = process.stdout.rows * 4
|
@height = process.stdout.rows * 4 - 4
|
||||||
|
|
||||||
@renderer.setSize @width, @height
|
@renderer.setSize @width, @height
|
||||||
|
|
||||||
_onClick: (event) ->
|
_onClick: (event) ->
|
||||||
if @mouseDragging and event.button is "left"
|
if @mouseDragging and event.button is "left"
|
||||||
@view[0] -= (@mouseDragging.x-@mousePosition.x)*2
|
@view[0] -= (@mouseDragging.x-@mousePosition.x)<<1
|
||||||
@view[1] -= (@mouseDragging.y-@mousePosition.y)*4
|
@view[1] -= (@mouseDragging.y-@mousePosition.y)<<2
|
||||||
@_draw()
|
@_draw()
|
||||||
|
|
||||||
@mouseDragging = false
|
@mouseDragging = false
|
||||||
@ -88,7 +86,15 @@ module.exports = class Termap
|
|||||||
return unless event.x <= process.stdout.columns and event.y <= process.stdout.rows
|
return unless event.x <= process.stdout.columns and event.y <= process.stdout.rows
|
||||||
|
|
||||||
# start dragging
|
# start dragging
|
||||||
if not @mouseDragging and event.button is "left"
|
if event.button is "left"
|
||||||
|
if @mouseDragging
|
||||||
|
@view[0] -= (@mouseDragging.x-event.x)<<1
|
||||||
|
@view[1] -= (@mouseDragging.y-event.y)<<2
|
||||||
|
|
||||||
|
if not @renderer.isDrawing and @renderer.lastDrawAt < Date.now()-100
|
||||||
|
@_draw()
|
||||||
|
@mouseDragging = x: event.x, y: event.y
|
||||||
|
else
|
||||||
@mouseDragging = x: event.x, y: event.y
|
@mouseDragging = x: event.x, y: event.y
|
||||||
|
|
||||||
# update internal mouse tracker
|
# update internal mouse tracker
|
||||||
@ -121,23 +127,26 @@ module.exports = class Termap
|
|||||||
@renderer.draw @view, @zoom
|
@renderer.draw @view, @zoom
|
||||||
@renderer.notify @_getFooter()
|
@renderer.notify @_getFooter()
|
||||||
|
|
||||||
|
_getTiles: ->
|
||||||
|
|
||||||
_getBBox: ->
|
_getBBox: ->
|
||||||
[x, y] = mercator.forward [@center.lng, @center.lat]
|
[x, y] = mercator.ll [@center.lng, @center.lat]
|
||||||
width = @width * Math.pow(2, @zoom)
|
width = @width * Math.pow(2, @zoom)
|
||||||
height = @height * Math.pow(2, @zoom)
|
height = @height * Math.pow(2, @zoom)
|
||||||
|
zoom = 18-@zoom
|
||||||
mercator.inverse([x - width/2, y + width/2]).concat mercator.inverse([x + width/2, y - width/2])
|
[width, height, zoom]
|
||||||
|
#mercator.inverse([x - width/2, y + width/2]).concat mercator.inverse([x + width/2, y - width/2])
|
||||||
|
|
||||||
_getFooter: ->
|
_getFooter: ->
|
||||||
"center: [#{utils.digits @center.lat, 2}, #{utils.digits @center.lng, 2}] zoom: #{utils.digits @zoom, 2}"
|
#{}"center: [#{utils.digits @center.lat, 2}, #{utils.digits @center.lng, 2}] zoom: #{utils.digits @zoom, 2}"
|
||||||
# bbox: [#{@_getBBox().map((z) -> utils.digits(z, 2)).join(',')}]"
|
"bbox: [#{@_getBBox().map((z) -> utils.digits(z, 2)).join(', ')}]"
|
||||||
|
#{}"#{@mouseDragging.x} #{@mouseDragging.y} #{@mousePosition.x} #{@mousePosition.y}"
|
||||||
|
|
||||||
zoomBy: (step) ->
|
zoomBy: (step) ->
|
||||||
return unless @scale+step > 0
|
return @zoom = 0 if @zoom+step < 0
|
||||||
|
|
||||||
before = @scale
|
before = @zoom
|
||||||
@scale += step
|
|
||||||
@zoom += step
|
@zoom += step
|
||||||
|
|
||||||
@view[0] = @view[0]*before/@scale + if step > 0 then 8 else -8
|
@view[0] = @view[0]*before/@zoom + if step > 0 then 8 else -8
|
||||||
@view[1] = @view[1]*before/@scale + if step > 0 then 8 else -8
|
@view[1] = @view[1]*before/@zoom + if step > 0 then 8 else -8
|
||||||
|
BIN
tiles/regensburg.z10.pbf.gz
Normal file
BIN
tiles/regensburg.z10.pbf.gz
Normal file
Binary file not shown.
BIN
tiles/regensburg.z12.pbf.gz
Normal file
BIN
tiles/regensburg.z12.pbf.gz
Normal file
Binary file not shown.
BIN
tiles/sf.z7.pbf.gz
Normal file
BIN
tiles/sf.z7.pbf.gz
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user