From c717b7504f7f038cb3fabef1fad46f836bbd4283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Stra=C3=9Fburger?= Date: Tue, 20 Sep 2016 21:46:31 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8D=20calculating=20optimal=20zoom=20l?= =?UTF-8?q?evel=20to=20show=20full=20tile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + termap.coffee | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a0b93d0..4c9b579 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ Discover the world in your console! * [ ] API * [ ] setCenter * [ ] setZoom +* [x] start with zoom level which shows full vector tile * [x] accurate mouse drag&drop * [x] handle console resize * [ ] turn this into a [`blessed-contrib`](https://github.com/yaronn/blessed-contrib) widget diff --git a/termap.coffee b/termap.coffee index 5b1f25b..786e608 100644 --- a/termap.coffee +++ b/termap.coffee @@ -48,10 +48,10 @@ class Termap layers: housenum_label: - minZoom: 3 + minZoom: 2 color: 8 building: - minZoom: 10 + minZoom: 3.5 color: 8 poi_label: @@ -84,7 +84,7 @@ class Termap lng: 12.096956 zoom: 2 - view: [-400, -80] + view: [0, 0] scale: 4 @@ -115,6 +115,8 @@ class Termap @height = Math.ceil(process.stdout.rows/4)*4*4 @canvas = new Canvas @width, @height + @zoom = Math.log(4096/@width)/Math.LN2 + _onResize: (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]) _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) -> return if @isDrawing @@ -282,6 +285,6 @@ class Termap termap = new Termap() # 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._draw()