mirror of
https://github.com/rastapasta/mapscii.git
synced 2025-02-16 17:30:47 +01:00
📖 switching to refactored text renderer
This commit is contained in:
parent
cfe063cf2e
commit
f56b37d3b0
@ -73,7 +73,7 @@ module.exports = class BrailleBuffer
|
|||||||
output.join ''
|
output.join ''
|
||||||
|
|
||||||
setChar: (char, x, y, color) ->
|
setChar: (char, x, y, color) ->
|
||||||
return unless 0 <= x < @width/2 and 0 <= y < @height/4
|
return unless 0 <= x < @width and 0 <= y < @height
|
||||||
idx = @_project x, y
|
idx = @_project x, y
|
||||||
@charBuffer[idx] = char
|
@charBuffer[idx] = char
|
||||||
@colorBuffer[idx] = @termColor color
|
@colorBuffer[idx] = @termColor color
|
||||||
|
@ -40,7 +40,8 @@ module.exports = class Canvas
|
|||||||
@buffer.clear()
|
@buffer.clear()
|
||||||
|
|
||||||
text: (text, x, y, color, center = true) ->
|
text: (text, x, y, color, center = true) ->
|
||||||
@buffer.writeText text, x, y, color, center
|
position = @_project x, y
|
||||||
|
@buffer.writeText text, position[0], position[1], color, center
|
||||||
|
|
||||||
polyline: (points, color) ->
|
polyline: (points, color) ->
|
||||||
projected = (@_project point[0], point[1] for point in points)
|
projected = (@_project point[0], point[1] for point in points)
|
||||||
|
@ -17,7 +17,7 @@ module.exports = class Renderer
|
|||||||
language: 'de'
|
language: 'de'
|
||||||
|
|
||||||
#"poi_label", "housenum_label", "water",
|
#"poi_label", "housenum_label", "water",
|
||||||
drawOrder: ["admin", "building", "road", "place_label"]
|
drawOrder: ["admin", "building", "road", "poi_label"]
|
||||||
|
|
||||||
icons:
|
icons:
|
||||||
car: "🚗"
|
car: "🚗"
|
||||||
@ -76,7 +76,6 @@ module.exports = class Renderer
|
|||||||
|
|
||||||
@canvas.translate @view[0], @view[1]
|
@canvas.translate @view[0], @view[1]
|
||||||
@_drawLayers()
|
@_drawLayers()
|
||||||
|
|
||||||
@canvas.print()
|
@canvas.print()
|
||||||
|
|
||||||
@isDrawing = false
|
@isDrawing = false
|
||||||
@ -88,7 +87,6 @@ module.exports = class Renderer
|
|||||||
for layer in @config.drawOrder
|
for layer in @config.drawOrder
|
||||||
continue unless @features?[layer]
|
continue unless @features?[layer]
|
||||||
|
|
||||||
@notify "rendering #{layer}..."
|
|
||||||
scale = Math.pow 2, @zoom
|
scale = Math.pow 2, @zoom
|
||||||
|
|
||||||
if @config.layers[layer]?.minZoom and @zoom > @config.layers[layer].minZoom
|
if @config.layers[layer]?.minZoom and @zoom > @config.layers[layer].minZoom
|
||||||
@ -100,8 +98,9 @@ module.exports = class Renderer
|
|||||||
maxX: (@width-@view[0])*scale
|
maxX: (@width-@view[0])*scale
|
||||||
maxY: (@height-@view[1])*scale
|
maxY: (@height-@view[1])*scale
|
||||||
|
|
||||||
for feature in @features[layer].tree.search box
|
features = @features[layer].tree.search box
|
||||||
#@notify "rendering #{feature.data.id}"
|
@notify "rendering #{features.length} #{layer} features.."
|
||||||
|
for feature in features
|
||||||
@_drawFeature layer, feature.data, scale
|
@_drawFeature layer, feature.data, scale
|
||||||
|
|
||||||
_drawFeature: (layer, feature, scale) ->
|
_drawFeature: (layer, feature, scale) ->
|
||||||
@ -127,11 +126,9 @@ module.exports = class Renderer
|
|||||||
switch feature.type
|
switch feature.type
|
||||||
when "LineString"
|
when "LineString"
|
||||||
@canvas.polyline points, colorCode for points in toDraw
|
@canvas.polyline points, colorCode for points in toDraw
|
||||||
true
|
|
||||||
|
|
||||||
when "Polygon"
|
when "Polygon"
|
||||||
@canvas.polygon toDraw[0], colorCode
|
@canvas.polygon toDraw[0], colorCode
|
||||||
true
|
|
||||||
|
|
||||||
when "Point"
|
when "Point"
|
||||||
text = feature.properties["name_"+@config.language] or
|
text = feature.properties["name_"+@config.language] or
|
||||||
@ -140,23 +137,12 @@ module.exports = class Renderer
|
|||||||
#@config.icons[feature.properties.maki] or
|
#@config.icons[feature.properties.maki] or
|
||||||
"◉"
|
"◉"
|
||||||
|
|
||||||
wasDrawn = false
|
|
||||||
# TODO: check in definition if points can actually own multiple geometries
|
# TODO: check in definition if points can actually own multiple geometries
|
||||||
for points in toDraw
|
for points in toDraw
|
||||||
for point in points
|
for point in points
|
||||||
x = point.x - text.length
|
x = point[0] - text.length
|
||||||
#continue if x-@view[0] < 0
|
if @labelBuffer.writeIfPossible text, x, point[1]
|
||||||
if @labelBuffer.writeIfPossible text, x, point.y
|
@canvas.text text, x, point[1], colorCode, false
|
||||||
@canvas.text text, x, point.y, colorCode
|
|
||||||
wasDrawn = true
|
|
||||||
|
|
||||||
wasDrawn
|
|
||||||
|
|
||||||
_isOnScreen: (point) ->
|
|
||||||
point.x+@view[0]>=4 and
|
|
||||||
point.x+@view[0]<@width-4 and
|
|
||||||
point.y+@view[1]>=0 and
|
|
||||||
point.y+@view[1]<@height
|
|
||||||
|
|
||||||
notify: (text) ->
|
notify: (text) ->
|
||||||
@_write "\r\x1B[K"+text
|
@_write "\r\x1B[K"+text
|
||||||
|
@ -31,7 +31,7 @@ module.exports = class Termap
|
|||||||
lng: 12.096956
|
lng: 12.096956
|
||||||
|
|
||||||
zoom: 2
|
zoom: 2
|
||||||
view: [0, 100]
|
view: [0, 0]
|
||||||
|
|
||||||
scale: 4
|
scale: 4
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ module.exports = class Termap
|
|||||||
|
|
||||||
_resizeRenderer: (cb) ->
|
_resizeRenderer: (cb) ->
|
||||||
@width = (process.stdout.columns-1) >> 1 << 2
|
@width = (process.stdout.columns-1) >> 1 << 2
|
||||||
@height = Math.ceil(process.stdout.rows/2) << 4
|
@height = process.stdout.rows >> 2 << 4
|
||||||
|
|
||||||
@renderer.setSize @width, @height
|
@renderer.setSize @width, @height
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user