mirror of
https://github.com/rastapasta/mapscii.git
synced 2024-11-24 17:13:57 +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 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%" />
|
||||
|
||||
|
@ -4,9 +4,9 @@
|
||||
|
||||
The Console Vector Tile renderer - bäm!
|
||||
###
|
||||
x256 = require 'x256'
|
||||
tilebelt = require 'tilebelt'
|
||||
Promise = require 'bluebird'
|
||||
x256 = require 'x256'
|
||||
|
||||
Canvas = require './Canvas'
|
||||
LabelBuffer = require './LabelBuffer'
|
||||
@ -17,12 +17,11 @@ utils = require './utils'
|
||||
module.exports = class Renderer
|
||||
cache: {}
|
||||
config:
|
||||
fillPolygons: true
|
||||
language: 'de'
|
||||
|
||||
labelMargin: 5
|
||||
|
||||
tileSize: 512
|
||||
tileSize: 4096
|
||||
projectSize: 256
|
||||
maxZoom: 14
|
||||
|
||||
@ -63,7 +62,7 @@ module.exports = class Renderer
|
||||
|
||||
layers:
|
||||
housenum_label:
|
||||
margin: 3
|
||||
margin: 4
|
||||
poi_label:
|
||||
margin: 5
|
||||
cluster: true
|
||||
@ -212,29 +211,21 @@ module.exports = class Renderer
|
||||
return false
|
||||
|
||||
points = @_scaleAndReduce tile, feature
|
||||
|
||||
unless points.length
|
||||
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
|
||||
when "line"
|
||||
width = feature.style.paint['line-width']?.base*1.4 or 1
|
||||
@canvas.polyline points, colorCode, width
|
||||
width = feature.style.paint['line-width']
|
||||
width = width.stops[0][1] if width instanceof Object
|
||||
|
||||
@canvas.polyline points, feature.color, width
|
||||
|
||||
when "fill"
|
||||
@canvas.polygon points, colorCode
|
||||
@canvas.polygon points, feature.color
|
||||
|
||||
when "symbola"
|
||||
when "symbol"
|
||||
text = feature.properties["name_"+@config.language] or
|
||||
feature.properties["name_en"] or
|
||||
feature.properties["name"] or
|
||||
@ -247,9 +238,9 @@ module.exports = class Renderer
|
||||
margin = @config.layers[feature.layer]?.margin or @config.labelMargin
|
||||
|
||||
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
|
||||
@canvas.text "◉", point[0], point[1], colorCode
|
||||
@canvas.text "◉", point[0], point[1], feature.color
|
||||
|
||||
_seen: {}
|
||||
_scaleAndReduce: (tile, feature) ->
|
||||
@ -259,25 +250,27 @@ module.exports = class Renderer
|
||||
scaled = []
|
||||
|
||||
for point in feature.points
|
||||
x = Math.floor tile.position.x+point.x/tile.scale
|
||||
y = Math.floor tile.position.y+point.y/tile.scale
|
||||
x = Math.floor tile.position.x+(point.x/tile.scale)
|
||||
y = Math.floor tile.position.y+(point.y/tile.scale)
|
||||
|
||||
if lastX is x and lastY is y
|
||||
continue
|
||||
|
||||
lastY = y
|
||||
lastX = x
|
||||
#
|
||||
# if x < -@tilePadding or
|
||||
# y < -@tilePadding or
|
||||
# x > @width+@tilePadding or
|
||||
# y > @height+@tilePadding
|
||||
# continue if outside
|
||||
# outside = true
|
||||
# else
|
||||
# if outside
|
||||
# outside = null
|
||||
# scaled.push [lastX, lastY]
|
||||
|
||||
if tile.xyz.z > 1 and (
|
||||
x < -@tilePadding or
|
||||
y < -@tilePadding or
|
||||
x > @width+@tilePadding or
|
||||
y > @height+@tilePadding
|
||||
)
|
||||
continue if outside
|
||||
outside = true
|
||||
else
|
||||
if outside
|
||||
outside = null
|
||||
scaled.push [lastX, lastY]
|
||||
|
||||
scaled.push [x, y]
|
||||
|
||||
@ -288,7 +281,7 @@ module.exports = class Renderer
|
||||
|
||||
@_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 []
|
||||
|
||||
scaled
|
||||
|
@ -23,8 +23,8 @@ module.exports = class Termap
|
||||
styleFile: __dirname+"/../styles/bright.json"
|
||||
|
||||
initialZoom: null
|
||||
maxZoom: 18
|
||||
zoomStep: 0.25
|
||||
maxZoom: 17
|
||||
zoomStep: 0.2
|
||||
headless: false
|
||||
|
||||
# size:
|
||||
@ -48,8 +48,7 @@ module.exports = class Termap
|
||||
# sf lat: 37.787946, lon: -122.407522
|
||||
# iceland lat: 64.124229, lon: -21.811552
|
||||
# rgbg
|
||||
lat: 49.0189
|
||||
lon: 12.0990
|
||||
lat: 49.019493, lon: 12.098341
|
||||
|
||||
minZoom: null
|
||||
|
||||
|
@ -10,6 +10,9 @@ Protobuf = require 'pbf'
|
||||
Promise = require 'bluebird'
|
||||
zlib = require 'zlib'
|
||||
rbush = require 'rbush'
|
||||
x256 = require 'x256'
|
||||
|
||||
utils = require "./utils"
|
||||
|
||||
class Tile
|
||||
layers: {}
|
||||
@ -39,6 +42,8 @@ class Tile
|
||||
|
||||
_loadLayers: (tile) ->
|
||||
layers = {}
|
||||
colorCache = {}
|
||||
|
||||
for name, layer of tile.layers
|
||||
tree = rbush()
|
||||
for i in [0...layer.length]
|
||||
@ -52,10 +57,22 @@ class Tile
|
||||
style = @styler.getStyleFor name, feature
|
||||
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
|
||||
# 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"
|
||||
@_addToTree tree,
|
||||
id: feature.id
|
||||
@ -63,6 +80,7 @@ class Tile
|
||||
style: style
|
||||
properties: feature.properties
|
||||
points: geometries[0]
|
||||
color: colorCode
|
||||
|
||||
else
|
||||
for points in geometries
|
||||
@ -72,6 +90,7 @@ class Tile
|
||||
style: style
|
||||
properties: feature.properties
|
||||
points: points
|
||||
color: colorCode
|
||||
|
||||
layers[name] = tree
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
"@water": "#5f87ff",
|
||||
|
||||
"@building": "#99b",
|
||||
"@housenum_label": "#88a",
|
||||
|
||||
"@country_label_1": "#ff0",
|
||||
"@country_label_2": "#ff0",
|
||||
@ -1677,7 +1678,7 @@
|
||||
"type": "symbol",
|
||||
"id": "housenum_label",
|
||||
"paint": {
|
||||
"text-color": "#444"
|
||||
"text-color": "@housenum_label"
|
||||
},
|
||||
"minzoom": 16.5,
|
||||
"source-layer": "housenum_label"
|
||||
|
Loading…
Reference in New Issue
Block a user