🔍 calculating optimal zoom level to show full tile

This commit is contained in:
Michael Straßburger 2016-09-20 21:46:31 +02:00
parent 014eab2b70
commit c717b7504f
2 changed files with 9 additions and 5 deletions

View File

@ -56,6 +56,7 @@ Discover the world in your console!
* [ ] API * [ ] API
* [ ] setCenter * [ ] setCenter
* [ ] setZoom * [ ] setZoom
* [x] start with zoom level which shows full vector tile
* [x] accurate mouse drag&drop * [x] accurate mouse drag&drop
* [x] handle console resize * [x] handle console resize
* [ ] turn this into a [`blessed-contrib`](https://github.com/yaronn/blessed-contrib) widget * [ ] turn this into a [`blessed-contrib`](https://github.com/yaronn/blessed-contrib) widget

View File

@ -48,10 +48,10 @@ class Termap
layers: layers:
housenum_label: housenum_label:
minZoom: 3 minZoom: 2
color: 8 color: 8
building: building:
minZoom: 10 minZoom: 3.5
color: 8 color: 8
poi_label: poi_label:
@ -84,7 +84,7 @@ class Termap
lng: 12.096956 lng: 12.096956
zoom: 2 zoom: 2
view: [-400, -80] view: [0, 0]
scale: 4 scale: 4
@ -115,6 +115,8 @@ class Termap
@height = Math.ceil(process.stdout.rows/4)*4*4 @height = Math.ceil(process.stdout.rows/4)*4*4
@canvas = new Canvas @width, @height @canvas = new Canvas @width, @height
@zoom = Math.log(4096/@width)/Math.LN2
_onResize: (cb) -> _onResize: (cb) ->
process.stdout.on 'resize', cb process.stdout.on 'resize', cb
@ -263,7 +265,8 @@ class Termap
mercator.inverse([x - width/2, y + width/2]).concat mercator.inverse([x + width/2, y - width/2]) mercator.inverse([x - width/2, y + width/2]).concat mercator.inverse([x + width/2, y - width/2])
_getFooter: -> _getFooter: ->
"center: [lat: #{utils.digits @center.lat, 3} lng: #{utils.digits @center.lng, 3}] zoom: #{@zoom} bbox: [#{@_getBBox().map((z) -> utils.digits(z, 3)).join(',')}]" "center: [#{utils.digits @center.lat, 2}, #{utils.digits @center.lng, 2}] zoom: #{@zoom}"
# bbox: [#{@_getBBox().map((z) -> utils.digits(z, 2)).join(',')}]"
notify: (text) -> notify: (text) ->
return if @isDrawing return if @isDrawing
@ -282,6 +285,6 @@ class Termap
termap = new Termap() termap = new Termap()
# TODO: abstracing this class, create loader class # TODO: abstracing this class, create loader class
data = fs.readFileSync __dirname+"/tiles/regensburg.pbf.gz" data = fs.readFileSync __dirname+"/tiles/world.pbf.gz"
termap.features = termap._getFeatures termap._parseTile data termap.features = termap._getFeatures termap._parseTile data
termap._draw() termap._draw()