🏃 moving label selection logic to tile loader

This commit is contained in:
Michael Straßburger 2017-05-10 14:24:11 +02:00
parent 3dffcde3b5
commit ca6a4e27ae
3 changed files with 28 additions and 12 deletions

View File

@ -140,10 +140,7 @@ module.exports = class Renderer
@_drawFeature tile, feature, layer.scale @_drawFeature tile, feature, layer.scale
labels.sort (a, b) -> labels.sort (a, b) ->
if a.feature.properties.localrank a.feature.sorty-b.feature.sort
a.feature.properties.localrank-b.feature.properties.localrank
else
a.feature.properties.scalerank-b.feature.properties.scalerank
for label in labels for label in labels
@_drawFeature label.tile, label.feature, label.scale @_drawFeature label.tile, label.feature, label.scale
@ -178,10 +175,8 @@ module.exports = class Renderer
@canvas.polygon points, feature.color @canvas.polygon points, feature.color
when "symbol" when "symbol"
text = feature.properties["name_"+config.language] or genericSymbol = null
feature.properties["name_en"] or text = feature.label or
feature.properties["name"] or
feature.properties.house_num or
genericSymbol = "" genericSymbol = ""
return false if @_seen[text] and not genericSymbol return false if @_seen[text] and not genericSymbol

View File

@ -13,6 +13,7 @@ rbush = require 'rbush'
x256 = require 'x256' x256 = require 'x256'
earcut = require 'earcut' earcut = require 'earcut'
config = require "./config"
utils = require "./utils" utils = require "./utils"
class Tile class Tile
@ -74,22 +75,34 @@ class Tile
# use feature.loadGeometry() again as soon as we got a 512 extent tileset # use feature.loadGeometry() again as soon as we got a 512 extent tileset
geometries = feature.loadGeometry() #@_reduceGeometry feature, 8 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" if style.type is "fill"
nodes.push @_addBoundaries true, nodes.push @_addBoundaries true,
id: feature.id # id: feature.id
layer: name layer: name
style: style style: style
properties: feature.properties label: label
sort: sort
points: geometries points: geometries
color: colorCode color: colorCode
else else
for points in geometries for points in geometries
nodes.push @_addBoundaries false, nodes.push @_addBoundaries false,
id: feature.id # id: feature.id
layer: name layer: name
style: style style: style
properties: feature.properties label: label
sort: sort
points: points points: points
color: colorCode color: colorCode

View File

@ -55,5 +55,13 @@ utils =
digits: (number, digits) -> digits: (number, digits) ->
Math.floor(number*Math.pow(10, digits))/Math.pow(10, 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 module.exports = utils