mirror of
https://github.com/rastapasta/mapscii.git
synced 2024-11-21 23:53:08 +01:00
🔎 ordering labels by scalerank before trying to place them
This commit is contained in:
parent
ef6ab82376
commit
8e0b976ae0
@ -126,6 +126,7 @@ module.exports = class Renderer
|
|||||||
|
|
||||||
_renderTiles: (tiles) ->
|
_renderTiles: (tiles) ->
|
||||||
drawn = {}
|
drawn = {}
|
||||||
|
labels = []
|
||||||
|
|
||||||
for layerId in @_generateDrawOrder tiles[0].xyz.z
|
for layerId in @_generateDrawOrder tiles[0].xyz.z
|
||||||
for tile in tiles
|
for tile in tiles
|
||||||
@ -133,8 +134,19 @@ module.exports = class Renderer
|
|||||||
for feature in layer.features
|
for feature in layer.features
|
||||||
# continue if feature.id and drawn[feature.id]
|
# continue if feature.id and drawn[feature.id]
|
||||||
# drawn[feature.id] = true
|
# drawn[feature.id] = true
|
||||||
|
if layerId.match /label/
|
||||||
|
labels.push tile: tile, feature: feature, scale: layer.scale
|
||||||
|
else
|
||||||
|
@_drawFeature tile, feature, layer.scale
|
||||||
|
|
||||||
@_drawFeature tile, feature, layer.scale
|
labels.sort (a, b) ->
|
||||||
|
if a.feature.properties.localrank
|
||||||
|
a.feature.properties.localrank-b.feature.properties.localrank
|
||||||
|
else
|
||||||
|
a.feature.properties.scalerank-b.feature.properties.scalerank
|
||||||
|
|
||||||
|
for label in labels
|
||||||
|
@_drawFeature label.tile, label.feature, label.scale
|
||||||
|
|
||||||
_getFrame: ->
|
_getFrame: ->
|
||||||
frame = ""
|
frame = ""
|
||||||
@ -155,6 +167,7 @@ module.exports = class Renderer
|
|||||||
switch feature.style.type
|
switch feature.style.type
|
||||||
when "line"
|
when "line"
|
||||||
width = feature.style.paint['line-width']
|
width = feature.style.paint['line-width']
|
||||||
|
# TODO: apply the correct zoom based value
|
||||||
width = width.stops[0][1] if width instanceof Object
|
width = width.stops[0][1] if width instanceof Object
|
||||||
|
|
||||||
points = @_scaleAndReduce tile, feature, feature.points, scale
|
points = @_scaleAndReduce tile, feature, feature.points, scale
|
||||||
@ -163,9 +176,6 @@ module.exports = class Renderer
|
|||||||
when "fill"
|
when "fill"
|
||||||
points = (@_scaleAndReduce tile, feature, p, scale, false for p in feature.points)
|
points = (@_scaleAndReduce tile, feature, p, scale, false for p in feature.points)
|
||||||
@canvas.polygon points, feature.color
|
@canvas.polygon points, feature.color
|
||||||
# if points.length is 3
|
|
||||||
# @canvas._filledTriangle points[0], points[1], points[2], feature.color
|
|
||||||
true
|
|
||||||
|
|
||||||
when "symbol"
|
when "symbol"
|
||||||
text = feature.properties["name_"+config.language] or
|
text = feature.properties["name_"+config.language] or
|
||||||
@ -228,7 +238,8 @@ module.exports = class Renderer
|
|||||||
if scaled.length < 2
|
if scaled.length < 2
|
||||||
return []
|
return []
|
||||||
|
|
||||||
simplify scaled, .5
|
#simplify scaled, .5, true
|
||||||
|
scaled
|
||||||
else
|
else
|
||||||
scaled
|
scaled
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ module.exports =
|
|||||||
#source: __dirname+"/../mbtiles/regensburg.mbtiles"
|
#source: __dirname+"/../mbtiles/regensburg.mbtiles"
|
||||||
styleFile: __dirname+"/../styles/dark.json"
|
styleFile: __dirname+"/../styles/dark.json"
|
||||||
|
|
||||||
initialZoom: false
|
initialZoom: null
|
||||||
maxZoom: 18
|
maxZoom: 18
|
||||||
zoomStep: 0.2
|
zoomStep: 0.2
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user