From d3e296118440c2381f270e25308366452821cdfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Stra=C3=9Fburger?= Date: Wed, 21 Sep 2016 15:41:44 +0200 Subject: [PATCH] :book: centering of label texts, better text selection --- README.md | 5 ++++- src/Canvas.coffee | 2 ++ src/utils.coffee | 11 +++++++++-- termap.coffee | 12 ++++++++++-- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 24b1271..ff9d2f4 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,10 @@ No web browser around? No worries - discover the planet in your console! * [ ] label drawing * [x] support for point labels * [x] dynamic decluttering of labels - * [ ] centering text labels + * [x] centering text labels + * [ ] multi line label + * [ ] label margin to avoid POI overlap? + * [ ] translatable raster fonts * [x] filled polygons * [x] convert polygons to triangles * [x] implement fillTriangle into drawille-canvas-blessed-contrib diff --git a/src/Canvas.coffee b/src/Canvas.coffee index 23f36b2..60781f5 100644 --- a/src/Canvas.coffee +++ b/src/Canvas.coffee @@ -9,3 +9,5 @@ BlessedCanvas = require 'drawille-canvas-blessed-contrib' module.exports = class Canvas extends BlessedCanvas + fillText: (text, x, y, size=1) -> + super text, x-text.length, y diff --git a/src/utils.coffee b/src/utils.coffee index f0ea4c6..3729b79 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -1,3 +1,10 @@ +### + termap - Terminal Map Viewer + by Michael Strassburger + + methods used all around +### + utils = deg2rad: (angle) -> # (angle / 180) * Math.PI @@ -6,9 +13,9 @@ utils = angle / Math.PI * 180 hex2rgb: (color) -> - if not color.match + if not color?.match console.log color - process.exit() + return [255, 0, 0] unless color?.match unless color.match /^#[a-fA-F0-9]{3,6}$/ diff --git a/termap.coffee b/termap.coffee index e8105f2..fb8fe27 100644 --- a/termap.coffee +++ b/termap.coffee @@ -21,12 +21,13 @@ utils = require __dirname+'/src/utils' class Termap config: + language: 'de' styleFile: __dirname+"/styles/bright.json" fillPolygons: true zoomStep: 0.4 - drawOrder: ["admin", "water", "building", "road", "poi_label", "city_label", "housenum_label"] + drawOrder: ["admin", "water", "building", "road", "poi_label", "place_label", "housenum_label"] icons: car: "🚗" @@ -55,6 +56,9 @@ class Termap minZoom: 3.8 color: 8 + place_label: + color: "yellow" + poi_label: minZoom: 3 color: "yellow" @@ -282,7 +286,11 @@ class Termap true when "Point" - text = feature.properties.house_num or @config.icons[feature.properties.maki] or "◉" + text = feature.properties["name_"+@config.language] or + feature.properties["name"] or + feature.properties.house_num or + @config.icons[feature.properties.maki] or + "◉" wasDrawn = false # TODO: check in definition if points can actually own multiple geometries