mirror of
https://github.com/rastapasta/mapscii.git
synced 2025-02-16 09:29:13 +01:00
🏃 converting colors on Tile load, not on every feature draw
This commit is contained in:
parent
e69321dfb6
commit
7ed86ceed4
@ -1,6 +1,6 @@
|
|||||||
# MapSCII - The Whole World In Your Console.
|
# MapSCII - The Whole World In Your Console.
|
||||||
|
|
||||||
MapSCII is node.js based [Vector Tile](https://github.com/mapbox/vector-tile-spec) to [Braille](http://www.fileformat.info/info/unicode/block/braille_patterns/utf8test.htm) renderer for [xterm](https://en.wikipedia.org/wiki/Xterm)-compatible terminals.
|
MapSCII is a node.js based [Vector Tile](https://github.com/mapbox/vector-tile-spec) to [Braille](http://www.fileformat.info/info/unicode/block/braille_patterns/utf8test.htm) renderer for [xterm](https://en.wikipedia.org/wiki/Xterm)-compatible terminals.
|
||||||
|
|
||||||
<img src="http://i.imgur.com/yYVt7No.png" width="100%" />
|
<img src="http://i.imgur.com/yYVt7No.png" width="100%" />
|
||||||
|
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
|
|
||||||
The Console Vector Tile renderer - bäm!
|
The Console Vector Tile renderer - bäm!
|
||||||
###
|
###
|
||||||
x256 = require 'x256'
|
|
||||||
tilebelt = require 'tilebelt'
|
tilebelt = require 'tilebelt'
|
||||||
Promise = require 'bluebird'
|
Promise = require 'bluebird'
|
||||||
|
x256 = require 'x256'
|
||||||
|
|
||||||
Canvas = require './Canvas'
|
Canvas = require './Canvas'
|
||||||
LabelBuffer = require './LabelBuffer'
|
LabelBuffer = require './LabelBuffer'
|
||||||
@ -17,12 +17,11 @@ utils = require './utils'
|
|||||||
module.exports = class Renderer
|
module.exports = class Renderer
|
||||||
cache: {}
|
cache: {}
|
||||||
config:
|
config:
|
||||||
fillPolygons: true
|
|
||||||
language: 'de'
|
language: 'de'
|
||||||
|
|
||||||
labelMargin: 5
|
labelMargin: 5
|
||||||
|
|
||||||
tileSize: 512
|
tileSize: 4096
|
||||||
projectSize: 256
|
projectSize: 256
|
||||||
maxZoom: 14
|
maxZoom: 14
|
||||||
|
|
||||||
@ -63,7 +62,7 @@ module.exports = class Renderer
|
|||||||
|
|
||||||
layers:
|
layers:
|
||||||
housenum_label:
|
housenum_label:
|
||||||
margin: 3
|
margin: 4
|
||||||
poi_label:
|
poi_label:
|
||||||
margin: 5
|
margin: 5
|
||||||
cluster: true
|
cluster: true
|
||||||
@ -212,29 +211,21 @@ module.exports = class Renderer
|
|||||||
return false
|
return false
|
||||||
|
|
||||||
points = @_scaleAndReduce tile, feature
|
points = @_scaleAndReduce tile, feature
|
||||||
|
|
||||||
unless points.length
|
unless points.length
|
||||||
return false
|
return false
|
||||||
|
|
||||||
color =
|
|
||||||
feature.style.paint['line-color'] or
|
|
||||||
feature.style.paint['fill-color'] or
|
|
||||||
feature.style.paint['text-color']
|
|
||||||
|
|
||||||
# TODO: zoom calculation todo for perfect styling
|
|
||||||
if color instanceof Object
|
|
||||||
color = color.stops[0][1]
|
|
||||||
|
|
||||||
colorCode = x256 utils.hex2rgb color
|
|
||||||
|
|
||||||
switch feature.style.type
|
switch feature.style.type
|
||||||
when "line"
|
when "line"
|
||||||
width = feature.style.paint['line-width']?.base*1.4 or 1
|
width = feature.style.paint['line-width']
|
||||||
@canvas.polyline points, colorCode, width
|
width = width.stops[0][1] if width instanceof Object
|
||||||
|
|
||||||
|
@canvas.polyline points, feature.color, width
|
||||||
|
|
||||||
when "fill"
|
when "fill"
|
||||||
@canvas.polygon points, colorCode
|
@canvas.polygon points, feature.color
|
||||||
|
|
||||||
when "symbola"
|
when "symbol"
|
||||||
text = feature.properties["name_"+@config.language] or
|
text = feature.properties["name_"+@config.language] or
|
||||||
feature.properties["name_en"] or
|
feature.properties["name_en"] or
|
||||||
feature.properties["name"] or
|
feature.properties["name"] or
|
||||||
@ -247,9 +238,9 @@ module.exports = class Renderer
|
|||||||
margin = @config.layers[feature.layer]?.margin or @config.labelMargin
|
margin = @config.layers[feature.layer]?.margin or @config.labelMargin
|
||||||
|
|
||||||
if @labelBuffer.writeIfPossible text, x, point[1], feature, margin
|
if @labelBuffer.writeIfPossible text, x, point[1], feature, margin
|
||||||
@canvas.text text, x, point[1], colorCode
|
@canvas.text text, x, point[1], feature.color
|
||||||
else if @config.layers[feature.layer]?.cluster and @labelBuffer.writeIfPossible "X", point[0], point[1], feature, 3
|
else if @config.layers[feature.layer]?.cluster and @labelBuffer.writeIfPossible "X", point[0], point[1], feature, 3
|
||||||
@canvas.text "◉", point[0], point[1], colorCode
|
@canvas.text "◉", point[0], point[1], feature.color
|
||||||
|
|
||||||
_seen: {}
|
_seen: {}
|
||||||
_scaleAndReduce: (tile, feature) ->
|
_scaleAndReduce: (tile, feature) ->
|
||||||
@ -259,25 +250,27 @@ module.exports = class Renderer
|
|||||||
scaled = []
|
scaled = []
|
||||||
|
|
||||||
for point in feature.points
|
for point in feature.points
|
||||||
x = Math.floor tile.position.x+point.x/tile.scale
|
x = Math.floor tile.position.x+(point.x/tile.scale)
|
||||||
y = Math.floor tile.position.y+point.y/tile.scale
|
y = Math.floor tile.position.y+(point.y/tile.scale)
|
||||||
|
|
||||||
if lastX is x and lastY is y
|
if lastX is x and lastY is y
|
||||||
continue
|
continue
|
||||||
|
|
||||||
lastY = y
|
lastY = y
|
||||||
lastX = x
|
lastX = x
|
||||||
#
|
|
||||||
# if x < -@tilePadding or
|
if tile.xyz.z > 1 and (
|
||||||
# y < -@tilePadding or
|
x < -@tilePadding or
|
||||||
# x > @width+@tilePadding or
|
y < -@tilePadding or
|
||||||
# y > @height+@tilePadding
|
x > @width+@tilePadding or
|
||||||
# continue if outside
|
y > @height+@tilePadding
|
||||||
# outside = true
|
)
|
||||||
# else
|
continue if outside
|
||||||
# if outside
|
outside = true
|
||||||
# outside = null
|
else
|
||||||
# scaled.push [lastX, lastY]
|
if outside
|
||||||
|
outside = null
|
||||||
|
scaled.push [lastX, lastY]
|
||||||
|
|
||||||
scaled.push [x, y]
|
scaled.push [x, y]
|
||||||
|
|
||||||
@ -288,7 +281,7 @@ module.exports = class Renderer
|
|||||||
|
|
||||||
@_seen[ka] = @_seen[kb] = true
|
@_seen[ka] = @_seen[kb] = true
|
||||||
|
|
||||||
unless scaled.length > 1 or feature.type is "symbol"
|
if scaled.length < 2 and feature.style.type isnt "symbol"
|
||||||
return []
|
return []
|
||||||
|
|
||||||
scaled
|
scaled
|
||||||
|
@ -23,8 +23,8 @@ module.exports = class Termap
|
|||||||
styleFile: __dirname+"/../styles/bright.json"
|
styleFile: __dirname+"/../styles/bright.json"
|
||||||
|
|
||||||
initialZoom: null
|
initialZoom: null
|
||||||
maxZoom: 18
|
maxZoom: 17
|
||||||
zoomStep: 0.25
|
zoomStep: 0.2
|
||||||
headless: false
|
headless: false
|
||||||
|
|
||||||
# size:
|
# size:
|
||||||
@ -48,8 +48,7 @@ module.exports = class Termap
|
|||||||
# sf lat: 37.787946, lon: -122.407522
|
# sf lat: 37.787946, lon: -122.407522
|
||||||
# iceland lat: 64.124229, lon: -21.811552
|
# iceland lat: 64.124229, lon: -21.811552
|
||||||
# rgbg
|
# rgbg
|
||||||
lat: 49.0189
|
lat: 49.019493, lon: 12.098341
|
||||||
lon: 12.0990
|
|
||||||
|
|
||||||
minZoom: null
|
minZoom: null
|
||||||
|
|
||||||
|
@ -10,6 +10,9 @@ Protobuf = require 'pbf'
|
|||||||
Promise = require 'bluebird'
|
Promise = require 'bluebird'
|
||||||
zlib = require 'zlib'
|
zlib = require 'zlib'
|
||||||
rbush = require 'rbush'
|
rbush = require 'rbush'
|
||||||
|
x256 = require 'x256'
|
||||||
|
|
||||||
|
utils = require "./utils"
|
||||||
|
|
||||||
class Tile
|
class Tile
|
||||||
layers: {}
|
layers: {}
|
||||||
@ -39,6 +42,8 @@ class Tile
|
|||||||
|
|
||||||
_loadLayers: (tile) ->
|
_loadLayers: (tile) ->
|
||||||
layers = {}
|
layers = {}
|
||||||
|
colorCache = {}
|
||||||
|
|
||||||
for name, layer of tile.layers
|
for name, layer of tile.layers
|
||||||
tree = rbush()
|
tree = rbush()
|
||||||
for i in [0...layer.length]
|
for i in [0...layer.length]
|
||||||
@ -52,10 +57,22 @@ class Tile
|
|||||||
style = @styler.getStyleFor name, feature
|
style = @styler.getStyleFor name, feature
|
||||||
continue unless style
|
continue unless style
|
||||||
|
|
||||||
|
color =
|
||||||
|
style.paint['line-color'] or
|
||||||
|
style.paint['fill-color'] or
|
||||||
|
style.paint['text-color']
|
||||||
|
|
||||||
|
# TODO: zoom calculation todo for perfect styling
|
||||||
|
if color instanceof Object
|
||||||
|
color = color.stops[0][1]
|
||||||
|
|
||||||
|
colorCode = colorCache[color] or colorCache[color] = x256 utils.hex2rgb color
|
||||||
|
|
||||||
# TODO: monkey patching test case for tiles with a reduced extent 4096 / 8 -> 512
|
# TODO: monkey patching test case for tiles with a reduced extent 4096 / 8 -> 512
|
||||||
# use feature.loadGeometry() again as soon as we got a 512 extent tileset
|
# use feature.loadGeometry() again as soon as we got a 512 extent tileset
|
||||||
geometries = @_reduceGeometry feature, 8
|
geometries = feature.loadGeometry() #@_reduceGeometry feature, 8
|
||||||
|
|
||||||
|
# TODO: handling polygon holes, only handling outer area for now
|
||||||
if style.type is "fill"
|
if style.type is "fill"
|
||||||
@_addToTree tree,
|
@_addToTree tree,
|
||||||
id: feature.id
|
id: feature.id
|
||||||
@ -63,6 +80,7 @@ class Tile
|
|||||||
style: style
|
style: style
|
||||||
properties: feature.properties
|
properties: feature.properties
|
||||||
points: geometries[0]
|
points: geometries[0]
|
||||||
|
color: colorCode
|
||||||
|
|
||||||
else
|
else
|
||||||
for points in geometries
|
for points in geometries
|
||||||
@ -72,6 +90,7 @@ class Tile
|
|||||||
style: style
|
style: style
|
||||||
properties: feature.properties
|
properties: feature.properties
|
||||||
points: points
|
points: points
|
||||||
|
color: colorCode
|
||||||
|
|
||||||
layers[name] = tree
|
layers[name] = tree
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
"@water": "#5f87ff",
|
"@water": "#5f87ff",
|
||||||
|
|
||||||
"@building": "#99b",
|
"@building": "#99b",
|
||||||
|
"@housenum_label": "#88a",
|
||||||
|
|
||||||
"@country_label_1": "#ff0",
|
"@country_label_1": "#ff0",
|
||||||
"@country_label_2": "#ff0",
|
"@country_label_2": "#ff0",
|
||||||
@ -1677,7 +1678,7 @@
|
|||||||
"type": "symbol",
|
"type": "symbol",
|
||||||
"id": "housenum_label",
|
"id": "housenum_label",
|
||||||
"paint": {
|
"paint": {
|
||||||
"text-color": "#444"
|
"text-color": "@housenum_label"
|
||||||
},
|
},
|
||||||
"minzoom": 16.5,
|
"minzoom": 16.5,
|
||||||
"source-layer": "housenum_label"
|
"source-layer": "housenum_label"
|
||||||
|
Loading…
Reference in New Issue
Block a user