mirror of
https://github.com/rastapasta/mapscii.git
synced 2024-11-25 01:23:58 +01:00
🏃 moving label selection logic to tile loader
This commit is contained in:
parent
3dffcde3b5
commit
ca6a4e27ae
@ -140,10 +140,7 @@ module.exports = class Renderer
|
||||
@_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
|
||||
a.feature.sorty-b.feature.sort
|
||||
|
||||
for label in labels
|
||||
@_drawFeature label.tile, label.feature, label.scale
|
||||
@ -178,10 +175,8 @@ module.exports = class Renderer
|
||||
@canvas.polygon points, feature.color
|
||||
|
||||
when "symbol"
|
||||
text = feature.properties["name_"+config.language] or
|
||||
feature.properties["name_en"] or
|
||||
feature.properties["name"] or
|
||||
feature.properties.house_num or
|
||||
genericSymbol = null
|
||||
text = feature.label or
|
||||
genericSymbol = "◉"
|
||||
|
||||
return false if @_seen[text] and not genericSymbol
|
||||
|
@ -13,6 +13,7 @@ rbush = require 'rbush'
|
||||
x256 = require 'x256'
|
||||
earcut = require 'earcut'
|
||||
|
||||
config = require "./config"
|
||||
utils = require "./utils"
|
||||
|
||||
class Tile
|
||||
@ -74,22 +75,34 @@ class Tile
|
||||
# use feature.loadGeometry() again as soon as we got a 512 extent tileset
|
||||
geometries = feature.loadGeometry() #@_reduceGeometry feature, 8
|
||||
|
||||
sort = feature.properties.localrank or feature.properties.scalerank
|
||||
label = if style.type is "symbol"
|
||||
feature.properties["name_"+config.language] or
|
||||
feature.properties.name_en or
|
||||
feature.properties.name or
|
||||
feature.properties.house_num
|
||||
else
|
||||
undefined
|
||||
|
||||
if style.type is "fill"
|
||||
nodes.push @_addBoundaries true,
|
||||
id: feature.id
|
||||
# id: feature.id
|
||||
layer: name
|
||||
style: style
|
||||
properties: feature.properties
|
||||
label: label
|
||||
sort: sort
|
||||
points: geometries
|
||||
color: colorCode
|
||||
|
||||
else
|
||||
|
||||
for points in geometries
|
||||
nodes.push @_addBoundaries false,
|
||||
id: feature.id
|
||||
# id: feature.id
|
||||
layer: name
|
||||
style: style
|
||||
properties: feature.properties
|
||||
label: label
|
||||
sort: sort
|
||||
points: points
|
||||
color: colorCode
|
||||
|
||||
|
@ -55,5 +55,13 @@ utils =
|
||||
digits: (number, digits) ->
|
||||
Math.floor(number*Math.pow(10, digits))/Math.pow(10, digits)
|
||||
|
||||
normalize: (ll) ->
|
||||
ll.lon += 360 if ll.lon < -180
|
||||
ll.lon -= 360 if ll.lon > 180
|
||||
|
||||
ll.lat = 85.0511 if ll.lat > 85.0511
|
||||
ll.lat = -85.0511 if ll.lat < -85.0511
|
||||
|
||||
ll
|
||||
|
||||
module.exports = utils
|
||||
|
Loading…
Reference in New Issue
Block a user