🏃 adding tile feature padding to improve edge clipping

This commit is contained in:
Michael Straßburger 2016-11-06 18:56:57 +01:00
parent 329f6fc26b
commit cfd8e24342
4 changed files with 22 additions and 92 deletions

View File

@ -23,7 +23,7 @@ module.exports = class Renderer
labelMargin: 5
tileSize: 4096 #512
tileSize: 512
projectSize: 256
maxZoom: 14
@ -81,6 +81,7 @@ module.exports = class Renderer
labelBuffer: null
tileSource: null
tilePadding: 64
constructor: (@output, @tileSource) ->
@labelBuffer = new LabelBuffer()
@ -187,8 +188,8 @@ module.exports = class Renderer
continue unless tile.features[layer]?.length
for feature in tile.features[layer]
continue if feature.id and drawn[feature.id]
drawn[feature.id] = true
# continue if feature.id and drawn[feature.id]
# drawn[feature.id] = true
@_drawFeature tile, feature
@ -252,13 +253,12 @@ module.exports = class Renderer
_scaleAndReduce: (tile, feature) ->
reduced = []
seen = {}
for points in feature.points
seen = {}
lastX = null
lastY = null
firstOutside = null
outside = null
scaled = []
for point in points
@ -271,7 +271,10 @@ module.exports = class Renderer
lastY = y
lastX = x
if x < 0 or y < 0 or x > @width or y > @width
if x < -@tilePadding or
y < -@tilePadding or
x > @width+@tilePadding or
y > @height+@tilePadding
continue if outside
outside = true
else
@ -282,9 +285,8 @@ module.exports = class Renderer
scaled.push [x, y]
if scaled.length is 2
ka = scaled[0].concat(scaled[1]).join '-'
kb = scaled[1].concat(scaled[0]).join '-'
if seen[ka] or seen[kb]
if seen[ka = scaled[0].concat(scaled[1]).join '-'] or
seen[kb = scaled[1].concat(scaled[0]).join '-']
continue
seen[ka] = seen[kb] = true

View File

@ -22,9 +22,9 @@ module.exports = class Termap
#source: __dirname+"/../mbtiles/regensburg.mbtiles"
styleFile: __dirname+"/../styles/bright.json"
initialZoom: 14
initialZoom: null
maxZoom: 18
zoomStep: 0.2
zoomStep: 0.1
headless: false
# size:
@ -155,6 +155,7 @@ module.exports = class Termap
when "q"
process.exit 0
when "w" then @zoomy = true
when "a" then @zoomBy @config.zoomStep
when "z" then @zoomBy -@config.zoomStep
@ -172,7 +173,6 @@ module.exports = class Termap
# display debug info for unhandled keys
@notify JSON.stringify key
drawn: 0
_draw: ->
@renderer
.draw @center, @zoom
@ -181,8 +181,12 @@ module.exports = class Termap
@notify @_getFooter()
.catch =>
@notify "renderer is busy"
# .then =>
# @_draw() if @drawn++ < 20
.then =>
if @zoomy and @zoom < @config.maxZoom
@zoom += @config.zoomStep
@_draw()
else
@zoomy = false
_getFooter: ->
# features = @renderer.featuresAt @mousePosition.x-1-(@view[0]>>1), @mousePosition.y-1-(@view[1]>>2)

View File

@ -53,7 +53,7 @@ class Tile
continue unless style
# TODO: monkey patching test case for tiles with a reduced extent
points = feature.loadGeometry() #@_reduceGeometry feature, 8
points = @_reduceGeometry feature, 8
data =
style: style

View File

@ -1557,82 +1557,6 @@
]
]
},
{
"type": "line",
"id": "admin_level_3_maritime",
"paint": {
"line-color": "#a0c8f0",
"line-width": {
"base": 1,
"stops": [
[
4,
0.4
],
[
5,
1
],
[
12,
3
]
]
}
},
"source-layer": "admin",
"filter": [
"all",
[
">=",
"admin_level",
3
],
[
"==",
"maritime",
1
]
]
},
{
"type": "line",
"id": "admin_level_2_maritime",
"paint": {
"line-color": "#a0c8f0",
"line-width": {
"base": 1,
"stops": [
[
4,
1.4
],
[
5,
2
],
[
12,
8
]
]
}
},
"source-layer": "admin",
"filter": [
"all",
[
"==",
"admin_level",
2
],
[
"==",
"maritime",
1
]
]
},
{
"type": "symbol",
"id": "water_label",