mirror of
https://github.com/rastapasta/mapscii.git
synced 2024-11-25 01:23:58 +01:00
🎨 respecting feature type set in style (line, fill or symbol)
This commit is contained in:
parent
e9d92a71fa
commit
2e7f9abfeb
@ -193,7 +193,7 @@ module.exports = class Renderer
|
|||||||
continue if feature.id and drawn[feature.id]
|
continue if feature.id and drawn[feature.id]
|
||||||
drawn[feature.id] = true
|
drawn[feature.id] = true
|
||||||
|
|
||||||
@_drawFeature layer, feature, tile.scale, tile.zoom
|
@_drawFeature tile, feature
|
||||||
|
|
||||||
@canvas.restore()
|
@canvas.restore()
|
||||||
|
|
||||||
@ -211,14 +211,15 @@ module.exports = class Renderer
|
|||||||
baseZoom = Math.min @config.maxZoom, Math.floor Math.max 0, zoom
|
baseZoom = Math.min @config.maxZoom, Math.floor Math.max 0, zoom
|
||||||
@config.tileSize / @config.projectSize / Math.pow(2, zoom-baseZoom)
|
@config.tileSize / @config.projectSize / Math.pow(2, zoom-baseZoom)
|
||||||
|
|
||||||
_drawFeature: (layer, feature, scale, zoom) ->
|
_drawFeature: (tile, feature) ->
|
||||||
style = feature.style
|
return false if feature.style.minzoom and tile.zoom < feature.style.minzoom
|
||||||
|
|
||||||
return false if style.minzoom and zoom < style.minzoom
|
toDraw = (@_scaleAndReduce points, tile.scale for points in feature.points)
|
||||||
|
|
||||||
toDraw = (@_scaleAndReduce points, scale for points in feature.points)
|
color =
|
||||||
|
feature.style.paint['line-color'] or
|
||||||
color = style.paint['line-color'] or style.paint['fill-color'] or style.paint['text-color']
|
feature.style.paint['fill-color'] or
|
||||||
|
feature.style.paint['text-color']
|
||||||
|
|
||||||
# TODO: zoom calculation todo for perfect styling
|
# TODO: zoom calculation todo for perfect styling
|
||||||
if color instanceof Object
|
if color instanceof Object
|
||||||
@ -226,15 +227,15 @@ module.exports = class Renderer
|
|||||||
|
|
||||||
colorCode = x256 utils.hex2rgb color
|
colorCode = x256 utils.hex2rgb color
|
||||||
|
|
||||||
switch feature.type
|
switch feature.style.type
|
||||||
when "LineString"
|
when "line"
|
||||||
width = style.paint['line-width']?.base*1.4 or 1
|
width = feature.style.paint['line-width']?.base*1.4 or 1
|
||||||
@canvas.polyline points, colorCode, width for points in toDraw
|
@canvas.polyline points, colorCode, width for points in toDraw
|
||||||
|
|
||||||
when "Polygon"
|
when "fill"
|
||||||
@canvas.polygon toDraw, colorCode
|
@canvas.polygon toDraw, colorCode
|
||||||
|
|
||||||
when "Point"
|
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
|
||||||
@ -246,11 +247,11 @@ module.exports = class Renderer
|
|||||||
for points in toDraw
|
for points in toDraw
|
||||||
for point in points
|
for point in points
|
||||||
x = point[0] - text.length
|
x = point[0] - text.length
|
||||||
margin = @config.layers[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], colorCode
|
||||||
else if @config.layers[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], colorCode
|
||||||
|
|
||||||
_scaleAndReduce: (points, scale) ->
|
_scaleAndReduce: (points, scale) ->
|
||||||
|
@ -46,9 +46,7 @@ class Tile
|
|||||||
#continue if @styler and not @styler.getStyleFor layer, feature
|
#continue if @styler and not @styler.getStyleFor layer, feature
|
||||||
|
|
||||||
feature = layer.feature i
|
feature = layer.feature i
|
||||||
|
feature.properties.$type = [undefined, "Point", "LineString", "Polygon"][feature.type]
|
||||||
feature.properties.$type = type =
|
|
||||||
[undefined, "Point", "LineString", "Polygon"][feature.type]
|
|
||||||
|
|
||||||
if @styler
|
if @styler
|
||||||
style = @styler.getStyleFor name, feature
|
style = @styler.getStyleFor name, feature
|
||||||
@ -62,7 +60,7 @@ class Tile
|
|||||||
points: points
|
points: points
|
||||||
properties: feature.properties
|
properties: feature.properties
|
||||||
id: feature.id
|
id: feature.id
|
||||||
type: type
|
layer: name
|
||||||
|
|
||||||
@_addToTree tree, data
|
@_addToTree tree, data
|
||||||
data
|
data
|
||||||
|
Loading…
Reference in New Issue
Block a user