mirror of
https://github.com/rastapasta/mapscii.git
synced 2024-11-22 08:03:07 +01:00
🏃 adding tile feature padding to improve edge clipping
This commit is contained in:
parent
329f6fc26b
commit
cfd8e24342
@ -23,7 +23,7 @@ module.exports = class Renderer
|
|||||||
|
|
||||||
labelMargin: 5
|
labelMargin: 5
|
||||||
|
|
||||||
tileSize: 4096 #512
|
tileSize: 512
|
||||||
projectSize: 256
|
projectSize: 256
|
||||||
maxZoom: 14
|
maxZoom: 14
|
||||||
|
|
||||||
@ -81,6 +81,7 @@ module.exports = class Renderer
|
|||||||
|
|
||||||
labelBuffer: null
|
labelBuffer: null
|
||||||
tileSource: null
|
tileSource: null
|
||||||
|
tilePadding: 64
|
||||||
|
|
||||||
constructor: (@output, @tileSource) ->
|
constructor: (@output, @tileSource) ->
|
||||||
@labelBuffer = new LabelBuffer()
|
@labelBuffer = new LabelBuffer()
|
||||||
@ -187,8 +188,8 @@ module.exports = class Renderer
|
|||||||
continue unless tile.features[layer]?.length
|
continue unless tile.features[layer]?.length
|
||||||
|
|
||||||
for feature in tile.features[layer]
|
for feature in tile.features[layer]
|
||||||
continue if feature.id and drawn[feature.id]
|
# continue if feature.id and drawn[feature.id]
|
||||||
drawn[feature.id] = true
|
# drawn[feature.id] = true
|
||||||
|
|
||||||
@_drawFeature tile, feature
|
@_drawFeature tile, feature
|
||||||
|
|
||||||
@ -252,13 +253,12 @@ module.exports = class Renderer
|
|||||||
|
|
||||||
_scaleAndReduce: (tile, feature) ->
|
_scaleAndReduce: (tile, feature) ->
|
||||||
reduced = []
|
reduced = []
|
||||||
seen = {}
|
|
||||||
for points in feature.points
|
for points in feature.points
|
||||||
|
seen = {}
|
||||||
lastX = null
|
lastX = null
|
||||||
lastY = null
|
lastY = null
|
||||||
|
|
||||||
firstOutside = null
|
outside = null
|
||||||
scaled = []
|
scaled = []
|
||||||
|
|
||||||
for point in points
|
for point in points
|
||||||
@ -271,7 +271,10 @@ module.exports = class Renderer
|
|||||||
lastY = y
|
lastY = y
|
||||||
lastX = x
|
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
|
continue if outside
|
||||||
outside = true
|
outside = true
|
||||||
else
|
else
|
||||||
@ -282,9 +285,8 @@ module.exports = class Renderer
|
|||||||
scaled.push [x, y]
|
scaled.push [x, y]
|
||||||
|
|
||||||
if scaled.length is 2
|
if scaled.length is 2
|
||||||
ka = scaled[0].concat(scaled[1]).join '-'
|
if seen[ka = scaled[0].concat(scaled[1]).join '-'] or
|
||||||
kb = scaled[1].concat(scaled[0]).join '-'
|
seen[kb = scaled[1].concat(scaled[0]).join '-']
|
||||||
if seen[ka] or seen[kb]
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
seen[ka] = seen[kb] = true
|
seen[ka] = seen[kb] = true
|
||||||
|
@ -22,9 +22,9 @@ module.exports = class Termap
|
|||||||
#source: __dirname+"/../mbtiles/regensburg.mbtiles"
|
#source: __dirname+"/../mbtiles/regensburg.mbtiles"
|
||||||
styleFile: __dirname+"/../styles/bright.json"
|
styleFile: __dirname+"/../styles/bright.json"
|
||||||
|
|
||||||
initialZoom: 14
|
initialZoom: null
|
||||||
maxZoom: 18
|
maxZoom: 18
|
||||||
zoomStep: 0.2
|
zoomStep: 0.1
|
||||||
|
|
||||||
headless: false
|
headless: false
|
||||||
# size:
|
# size:
|
||||||
@ -155,6 +155,7 @@ module.exports = class Termap
|
|||||||
when "q"
|
when "q"
|
||||||
process.exit 0
|
process.exit 0
|
||||||
|
|
||||||
|
when "w" then @zoomy = true
|
||||||
when "a" then @zoomBy @config.zoomStep
|
when "a" then @zoomBy @config.zoomStep
|
||||||
when "z" then @zoomBy -@config.zoomStep
|
when "z" then @zoomBy -@config.zoomStep
|
||||||
|
|
||||||
@ -172,7 +173,6 @@ module.exports = class Termap
|
|||||||
# display debug info for unhandled keys
|
# display debug info for unhandled keys
|
||||||
@notify JSON.stringify key
|
@notify JSON.stringify key
|
||||||
|
|
||||||
drawn: 0
|
|
||||||
_draw: ->
|
_draw: ->
|
||||||
@renderer
|
@renderer
|
||||||
.draw @center, @zoom
|
.draw @center, @zoom
|
||||||
@ -181,8 +181,12 @@ module.exports = class Termap
|
|||||||
@notify @_getFooter()
|
@notify @_getFooter()
|
||||||
.catch =>
|
.catch =>
|
||||||
@notify "renderer is busy"
|
@notify "renderer is busy"
|
||||||
# .then =>
|
.then =>
|
||||||
# @_draw() if @drawn++ < 20
|
if @zoomy and @zoom < @config.maxZoom
|
||||||
|
@zoom += @config.zoomStep
|
||||||
|
@_draw()
|
||||||
|
else
|
||||||
|
@zoomy = false
|
||||||
|
|
||||||
_getFooter: ->
|
_getFooter: ->
|
||||||
# features = @renderer.featuresAt @mousePosition.x-1-(@view[0]>>1), @mousePosition.y-1-(@view[1]>>2)
|
# features = @renderer.featuresAt @mousePosition.x-1-(@view[0]>>1), @mousePosition.y-1-(@view[1]>>2)
|
||||||
|
@ -53,7 +53,7 @@ class Tile
|
|||||||
continue unless style
|
continue unless style
|
||||||
|
|
||||||
# TODO: monkey patching test case for tiles with a reduced extent
|
# TODO: monkey patching test case for tiles with a reduced extent
|
||||||
points = feature.loadGeometry() #@_reduceGeometry feature, 8
|
points = @_reduceGeometry feature, 8
|
||||||
|
|
||||||
data =
|
data =
|
||||||
style: style
|
style: style
|
||||||
|
@ -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",
|
"type": "symbol",
|
||||||
"id": "water_label",
|
"id": "water_label",
|
||||||
|
Loading…
Reference in New Issue
Block a user