From 7ed86ceed499c45615c82333bf7173ee3ee19e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Stra=C3=9Fburger?= Date: Mon, 7 Nov 2016 02:49:07 +0100 Subject: [PATCH] :runner: converting colors on Tile load, not on every feature draw --- README.md | 2 +- src/Renderer.coffee | 63 ++++++++++++++++++++------------------------- src/Termap.coffee | 7 +++-- src/Tile.coffee | 21 ++++++++++++++- styles/bright.json | 3 ++- 5 files changed, 54 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index a1a097f..c51ac28 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/Renderer.coffee b/src/Renderer.coffee index e85f9c0..e70536b 100644 --- a/src/Renderer.coffee +++ b/src/Renderer.coffee @@ -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 diff --git a/src/Termap.coffee b/src/Termap.coffee index b0cdade..649510e 100644 --- a/src/Termap.coffee +++ b/src/Termap.coffee @@ -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 diff --git a/src/Tile.coffee b/src/Tile.coffee index de52ec2..399c804 100644 --- a/src/Tile.coffee +++ b/src/Tile.coffee @@ -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 diff --git a/styles/bright.json b/styles/bright.json index 7b34752..ca5df48 100644 --- a/styles/bright.json +++ b/styles/bright.json @@ -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"