Skip to content

Commit

Permalink
🎨 optimizing label/marker rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
rastapasta committed Sep 28, 2016
1 parent f493a48 commit bd83950
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
bundle*
*.log
tmp
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Tile = require(__dirname+'/src/Tile')
termap = new Termap();

// TODO: abstracing this class, create loader class
data = fs.readFileSync(__dirname+"/tiles/world.pbf.gz");
data = fs.readFileSync(__dirname+"/tiles/regensburg.pbf.gz");
tile = new Tile(data);
termap.renderer.features = tile.layers
termap._draw();
2 changes: 1 addition & 1 deletion src/Canvas.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = class Canvas
clear: ->
@buffer.clear()

text: (text, x, y, color, center = true) ->
text: (text, x, y, color, center = false) ->
position = @_project x, y
@buffer.writeText text, position[0], position[1], color, center

Expand Down
11 changes: 4 additions & 7 deletions src/Renderer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module.exports = class Renderer
"building"
"road"

"water_label"
"place_label"
"poi_label"
"housenum_label"
Expand Down Expand Up @@ -147,7 +146,7 @@ module.exports = class Renderer

switch feature.type
when "LineString"
width = style.paint['line-width']?.base or 1
width = style.paint['line-width']?.base*1.4 or 1
@canvas.polyline points, colorCode, width for points in toDraw

when "Polygon"
Expand All @@ -166,12 +165,10 @@ module.exports = class Renderer
x = point[0] - text.length
margin = @config.layers[layer]?.margin or @config.labelMargin

write = (text) => @canvas.text text, x, point[1], colorCode, false

if @labelBuffer.writeIfPossible text, x, point[1], margin
write text
else if @config.layers[layer]?.cluster and @labelBuffer.writeIfPossible "X", x, point[1], 3
write ""
@canvas.text text, x, point[1], colorCode
else if @config.layers[layer]?.cluster and @labelBuffer.writeIfPossible "X", point[0], point[1], 3
@canvas.text "", point[0], point[1], colorCode

_scaleAndReduce: (points, scale) ->
lastX = null
Expand Down
2 changes: 1 addition & 1 deletion styles/bright.json
Original file line number Diff line number Diff line change
Expand Up @@ -1799,7 +1799,7 @@
"type": "symbol",
"id": "housenum_label",
"paint": {
"text-color": "#333"
"text-color": "#444"
},
"source-layer": "housenum_label"
},
Expand Down

0 comments on commit bd83950

Please sign in to comment.