🔍 calculating minZoom based on terminal width, fit map on startup

This commit is contained in:
Michael Straßburger 2016-10-03 16:42:14 +02:00
parent dd755ba8a8
commit 043e271985

View File

@ -37,6 +37,8 @@ module.exports = class Termap
zoom: 0 zoom: 0
view: [0, 0] view: [0, 0]
minZoom: null
constructor: (options) -> constructor: (options) ->
@config[key] = val for key, val of options @config[key] = val for key, val of options
@ -69,12 +71,14 @@ module.exports = class Termap
@_draw() @_draw()
@_resizeRenderer() @_resizeRenderer()
@zoom = 4-Math.log(4096/@width)/Math.LN2 @zoom = @minZoom
_resizeRenderer: (cb) -> _resizeRenderer: (cb) ->
@width = @config.output.columns >> 1 << 2 @width = @config.output.columns >> 1 << 2
@height = @config.output.rows * 4 - 4 @height = @config.output.rows * 4 - 4
@minZoom = 4-Math.log(4096/@width)/Math.LN2
@renderer.setSize @width, @height @renderer.setSize @width, @height
_onClick: (event) -> _onClick: (event) ->
@ -168,7 +172,7 @@ module.exports = class Termap
#features.map((f) -> JSON.stringify f.feature.properties).join(" - ") #features.map((f) -> JSON.stringify f.feature.properties).join(" - ")
zoomBy: (step) -> zoomBy: (step) ->
return @zoom = 0 if @zoom+step < 0 return @zoom = @minZoom if @zoom+step < @minZoom
before = @zoom before = @zoom
@zoom += step @zoom += step