👓 adding layer.minZoom display control

This commit is contained in:
Michael Straßburger 2016-09-18 21:15:21 +02:00
parent 545b9246c9
commit 9dcf71d411
2 changed files with 27 additions and 17 deletions

View File

@ -3,24 +3,28 @@
Discover the world in your console! termap allows you to render and navigate Discover the world in your console! termap allows you to render and navigate
VectorTile based maps in your console. VectorTile based maps in your console.
* No native dependencies, 100% JavaScript/CoffeeScript * No native dependencies, 100% Coffee-/JavaScript
* Use your mouse or keyboard to navigate the map
* Use tile servers or local MBTiles and VectorTiles * Use tile servers or local MBTiles and VectorTiles
## How to install it? ## How to get it?
`npm install -g termap` `npm install -g termap`
## Behind the scenes ## Behind the scenes
### Libraries ### Libraries
* [`pbf`](https://github.com/mapbox/pbf) for Protobuf parsing * [`pbf`](https://github.com/mapbox/pbf) for Protobuf decoding
* [`vector-tile`](https://github.com/mapbox/vector-tile-js) for [VectorTile](https://github.com/mapbox/vector-tile-spec/tree/master/2.1) parsing * [`vector-tile`](https://github.com/mapbox/vector-tile-js) for [VectorTile](https://github.com/mapbox/vector-tile-spec/tree/master/2.1) parsing
* [`term-mouse`](https://github.com/CoderPuppy/term-mouse) for mouse handling * [`term-mouse`](https://github.com/CoderPuppy/term-mouse) for mouse handling
* [`keypress`](https://github.com/TooTallNate/keypress) for input handling * [`keypress`](https://github.com/TooTallNate/keypress) for input handling
* [`node-drawille`](https://github.com/madbence/node-drawille/) for braille rendering (to be replaced) * [`node-drawille`](https://github.com/madbence/node-drawille/) for braille rendering (to be replaced)
## TODOs ## Wishlist
* node-gyp binding to [libdrawille](https://github.com/Huulivoide/libdrawille) for speed refactor possibilities + filled polygons
### TODOs
* [ ] mapping of view to tiles to show * [ ] mapping of view to tiles to show
* [ ] tile request system * [ ] tile request system
* [ ] from local mbtiles * [ ] from local mbtiles
@ -34,6 +38,3 @@ VectorTile based maps in your console.
* [ ] setZoom * [ ] setZoom
* [x] accurate mouse drag&drop * [x] accurate mouse drag&drop
* [x] handle console resize * [x] handle console resize
## Wishlist
* node-gyp binding to [libdrawille](https://github.com/Huulivoide/libdrawille) for speed refactor possibilities + filled polygons

View File

@ -8,7 +8,7 @@ TermMouse = require('term-mouse')
class Termap class Termap
config: config:
drawOrder: ["admin", "water", "landuse", "building", "road", "poi_label"] drawOrder: ["admin", "water", "landuse", "building", "road", "housenum_label"]
icons: icons:
car: "🚗" car: "🚗"
@ -22,7 +22,7 @@ class Termap
laundry: "👚" laundry: "👚"
bus: "🚌" bus: "🚌"
restaurant: "🍛" restaurant: "🍛"
lodging: "🛏" lodging: "🛏."
'fire-station': "🚒" 'fire-station': "🚒"
shop: "🛍" shop: "🛍"
pharmacy: "💊" pharmacy: "💊"
@ -30,18 +30,22 @@ class Termap
cinema: "🎦" cinema: "🎦"
layers: layers:
poi_label: housenum_label:
color: "red" minZoom: 4
color: 8
building:
minZoom: 12
color: 8
road: road:
color: "white" color: "white"
landuse: landuse:
color: "green" color: "green"
water: water:
color: "blue" color: "blue"
admin: admin:
color: "red" color: "red"
building:
color: 8
mouse: null mouse: null
width: null width: null
@ -117,8 +121,8 @@ class Termap
when "q" when "q"
process.exit 0 process.exit 0
when "a" then @zoomBy(.5) when "z" then @zoomBy(.5)
when "z" then @zoomBy(-.5) when "a" then @zoomBy(-.5)
when "left" then @view[0] += 5 when "left" then @view[0] += 5
when "right" then @view[0] -= 5 when "right" then @view[0] -= 5
when "up" then @view[1]+= 5 when "up" then @view[1]+= 5
@ -167,6 +171,10 @@ class Termap
for layer in @config.drawOrder for layer in @config.drawOrder
continue unless @features?[layer] continue unless @features?[layer]
if @config.layers[layer].minZoom and @scale > @config.layers[layer].minZoom
continue
@canvas.strokeStyle = @canvas.fillStyle = @config.layers[layer].color @canvas.strokeStyle = @canvas.fillStyle = @config.layers[layer].color
for feature in @features[layer] for feature in @features[layer]
@ -192,7 +200,8 @@ class Termap
@canvas.stroke() @canvas.stroke()
when "point" when "point"
@canvas.fillText (@config.icons[feature.properties.maki] or "X"), point... for point in points text = feature.properties.house_num or @config.icons[feature.properties.maki] or ""
@canvas.fillText text, point... for point in points
@canvas.restore() @canvas.restore()
@ -205,7 +214,7 @@ class Termap
process.stdout.write text process.stdout.write text
_getFooter: -> _getFooter: ->
"TerMap up and running!" "scale: #{Math.floor(@scale*1000)/1000}"
notify: -> notify: ->
return if @isDrawing return if @isDrawing