🎨 some side work for the telnet version

This commit is contained in:
Michael Straßburger 2017-04-29 23:51:15 +02:00
parent e79d91186b
commit 309a237bda
3 changed files with 24 additions and 18 deletions

View File

@ -78,7 +78,7 @@ module.exports = class BrailleBuffer
frame: ->
output = []
currentColor = null
delimeter = "\n"
delimeter = "\r\n"
for idx in [0...@pixelBuffer.length]
output.push delimeter if idx and (idx % (@width/2)) is 0

View File

@ -62,7 +62,7 @@ module.exports = class Mapscii
_initKeyboard: ->
keypress config.input
config.input.setRawMode true
config.input.setRawMode true if config.input.setRawMode
config.input.resume()
config.input.on 'keypress', (ch, key) => @_onKey key
@ -108,7 +108,8 @@ module.exports = class Mapscii
z = utils.baseZoom @zoom
center = utils.ll2tile @center.lon, @center.lat, z
@mousePosition = utils.tile2ll center.x+(dx/size), center.y+(dy/size), z
@mousePosition = utils.normalize utils.tile2ll center.x+(dx/size), center.y+(dy/size), z
_onClick: (event) ->
@_updateMousePosition event
@ -153,13 +154,17 @@ module.exports = class Mapscii
@notify @_getFooter()
_onKey: (key) ->
if config.keyCallback and not config.keyCallback key
return
# check if the pressed key is configured
draw = switch key?.name
when "q"
process.exit 0
when "w" then @zoomy = 1
when "s" then @zoomy = -1
when "q", "esc", "c"
if config.endCallback
config.endCallback()
null
else
process.exit 0
when "a" then @zoomBy config.zoomStep
when "z" then @zoomBy -config.zoomStep
@ -174,9 +179,9 @@ module.exports = class Mapscii
if draw isnt null
@_draw()
else
#else
# display debug info for unhandled keys
@notify JSON.stringify key
#@notify JSON.stringify key
_draw: ->
@renderer
@ -218,11 +223,4 @@ module.exports = class Mapscii
@setCenter @center.lat+lat, @center.lon+lon
setCenter: (lat, lon) ->
lon += 360 if lon < -180
lon -= 360 if lon > 180
lat = 85.0511 if lat > 85.0511
lat = -85.0511 if lat < -85.0511
@center.lat = lat
@center.lon = lon
@center = utils.normalize lon: lon, lat: lat

View File

@ -55,5 +55,13 @@ utils =
digits: (number, digits) ->
Math.floor(number*Math.pow(10, digits))/Math.pow(10, digits)
normalize: (ll) ->
ll.lon += 360 if ll.lon < -180
ll.lon -= 360 if ll.lon > 180
ll.lat = 85.0511 if ll.lat > 85.0511
ll.lat = -85.0511 if ll.lat < -85.0511
ll
module.exports = utils