👷 cleanup, testing tiles with an extent of 512, config params

This commit is contained in:
Michael Straßburger 2016-11-06 14:15:30 +01:00
parent a21d172a2c
commit 59b64e8dd2
6 changed files with 46 additions and 61 deletions

View File

@ -9,7 +9,7 @@ No web browser around? Don't worry - and discover the planet in your console!
* Highly customizable styling (reuse your [mapbox-gl-styles](https://github.com/mapbox/mapbox-gl-styles))
* Compatible with Linux and OSX terminals, Windows support via [PuTTY](http://www.putty.org/)
* Use the default or your own map server - or work offline with VectorTile/MBTiles
* 99% pure Coffee-/JavaScript! :sunglasses:
* 100% pure Coffee-/JavaScript! :sunglasses:
## How to install

View File

@ -7,12 +7,9 @@
TODO: params parsing and so on
#*/
require('coffee-script/register');
const fs = require('fs');
const Termap = require(__dirname+'/src/Termap');
const Tile = require(__dirname+'/src/Tile')
const Termap = require('./src/Termap');
termap = new Termap();
termap.init();

View File

@ -23,22 +23,19 @@ module.exports = class Renderer
labelMargin: 5
tileSize: 4096
tileSize: 512
projectSize: 256
maxZoom: 14
#"poi_label", "water",
drawOrder: [
"admin"
"building"
"water"
"marine_label"
"building"
"road"
# "road:structure=bridge"
"country_label"
"state_label"
"water_label"
"place_label"
"rail_station_label"
@ -75,16 +72,16 @@ module.exports = class Renderer
place_label: cluster: true
state_label: cluster: true
terminal:
CLEAR: "\x1B[2J"
MOVE: "\x1B[?6h"
isDrawing: false
lastDrawAt: 0
labelBuffer: null
tileSource: null
terminal:
CLEAR: "\x1B[2J"
MOVE: "\x1B[?6h"
constructor: (@output, @tileSource) ->
@labelBuffer = new LabelBuffer()
@ -94,7 +91,7 @@ module.exports = class Renderer
setSize: (@width, @height) ->
@canvas = new Canvas @width, @height
draw: (center, zoom, rotation = 0) ->
draw: (center, zoom) ->
return Promise.reject() if @isDrawing
@isDrawing = true
@ -105,8 +102,6 @@ module.exports = class Renderer
@canvas.clear()
# TODO: tiles = @_tilesInBBox @_getBBox()
Promise
.resolve @_visibleTiles center, zoom
.map (tile) => @_getTile tile
@ -177,16 +172,8 @@ module.exports = class Renderer
features = {}
for layer in @config.drawOrder
idx = layer
if layer.indexOf(':') isnt -1
[layer, filter] = layer.split /:/
[filterField, filterValue] = filter.split /=/
else
filter = false
continue unless tile.data.layers?[layer]
#if not filter or feature.data.properties[filterField] is filterValue
features[idx] = tile.data.layers[layer].tree.search box
features[layer] = tile.data.layers[layer].tree.search box
tile.features = features
tile
@ -221,12 +208,6 @@ module.exports = class Renderer
featuresAt: (x, y) ->
@labelBuffer.featuresAt x, y
_tilesInBBox: (bbox, zoom) ->
tiles = {}
[tiles.minX, tiles.minY] = utils.ll2tile bbox[0], bbox[1], Math.floor zoom
[tiles.maxX, tiles.maxY] = utils.ll2tile bbox[2], bbox[3], Math.floor zoom
tiles
_scaleAtZoom: (zoom) ->
baseZoom = Math.min @config.maxZoom, Math.floor Math.max 0, zoom
(@config.tileSize/@config.projectSize)/Math.pow(2, zoom-baseZoom)

View File

@ -22,10 +22,14 @@ module.exports = class Termap
#source: __dirname+"/../mbtiles/regensburg.mbtiles"
styleFile: __dirname+"/../styles/bright.json"
zoomStep: 0.2
initialZoom: 14
maxZoom: 18
zoomStep: 0.2
headless: false
# size:
# width: 40*2
# height: 10*4
width: null
height: null
@ -40,7 +44,6 @@ module.exports = class Termap
renderer: null
zoom: 0
rotation: 0
center:
# sf lat: 37.787946, lon: -122.407522
# iceland lat: 64.124229, lon: -21.811552
@ -97,15 +100,15 @@ module.exports = class Termap
@_draw()
@_resizeRenderer()
@zoom = @minZoom
@zoom = if @config.initialZoom isnt null then @config.initialZoom else @minZoom
_resizeRenderer: (cb) ->
unless @config.headless
if @config.size
@width = @config.size.width
@height = @config.size.height
else
@width = @config.output.columns >> 1 << 2
@height = @config.output.rows * 4 - 4
else
@width = 256
@height = 152
@minZoom = 4-Math.log(4096/@width)/Math.LN2
@ -155,9 +158,6 @@ module.exports = class Termap
when "a" then @zoomBy @config.zoomStep
when "z" then @zoomBy -@config.zoomStep
when "k" then @rotation += 15
when "l" then @rotation -= 15
when "left" then @moveBy 0, -8/Math.pow(2, @zoom)
when "right" then @moveBy 0, 8/Math.pow(2, @zoom)
when "up" then @moveBy 6/Math.pow(2, @zoom), 0
@ -174,7 +174,7 @@ module.exports = class Termap
_draw: ->
@renderer
.draw @center, @zoom, @rotation
.draw @center, @zoom
.then (frame) =>
@_write frame
@notify @_getFooter()
@ -201,7 +201,7 @@ module.exports = class Termap
#features.map((f) -> JSON.stringify f.feature.properties).join(" - ")
notify: (text) ->
@_write "\r\x1B[K"+text
@_write "\r\x1B[K"+text unless @config.headless
_write: (output) ->
@config.output.write output

View File

@ -48,8 +48,23 @@ class Tile
type = feature.properties.$type =
[undefined, "Point", "LineString", "Polygon"][feature.type]
# TODO: monkey patching test case for tiles with a reduced extent
geo = for sub, i in feature.loadGeometry()
points = []
last = null
for point, j in sub
p =
x: Math.floor point.x/8
y: Math.floor point.y/8
if last and last.x is p.x and last.y is p.y
continue
points.push p
last = p
points
data =
points: feature.loadGeometry()
points: geo
properties: feature.properties
id: feature.id
type: type

View File

@ -1,7 +1,11 @@
{
"name": "Bright",
"constants": {
"@water": "#55c",
"@background": "#000",
"@water": "#5f87ff",
"@building": "#606060",
"@country_label_1": "#ff0",
"@country_label_2": "#ff0",
"@country_label_3": "#ff0",
@ -20,7 +24,7 @@
"type": "background",
"id": "background",
"paint": {
"background-color": "#000"
"background-color": "@background"
}
},
{
@ -290,19 +294,7 @@
"type": "line",
"id": "building",
"paint": {
"fill-color": {
"base": 1,
"stops": [
[
14.5,
"#525652"
],
[
16,
"#5f5b57"
]
]
}
"line-color": "@building"
},
"source-layer": "building",
"minzoom": 14.5