🚦 uniting layer rendering + label buffering across tiles

This commit is contained in:
Michael Straßburger 2016-11-03 05:39:44 +01:00
parent 6c2819a89c
commit ae9507d4e3
2 changed files with 43 additions and 21 deletions

View File

@ -103,12 +103,15 @@ module.exports = class Renderer
Promise Promise
.resolve @_visibleTiles center, zoom .resolve @_visibleTiles center, zoom
.map (tile) => @_getTile tile.xyz, tile .map (tile) => @_getTile tile.xyz, tile
.then (tiles) => .map (tile) => @_getTileFeatures tile
for tile in tiles .then (tiles) => @_renderTiles tiles
@_renderTile tile.data, zoom, tile.meta.position .then =>
@_writeFrame() @_writeFrame()
.catch (e) ->
console.log e
.finally =>
@isDrawing = false @isDrawing = false
@lastDrawAt = Date.now() @lastDrawAt = Date.now()
@ -117,7 +120,9 @@ module.exports = class Renderer
xyz = tilebelt.pointToTileFraction center.lon, center.lat, z xyz = tilebelt.pointToTileFraction center.lon, center.lat, z
tiles = [] tiles = []
tileSize = @config.tileSize / @_scaleAtZoom(zoom) scale = @_scaleAtZoom zoom
tileSize = @config.tileSize / scale
for y in [Math.floor(xyz[1])-1..Math.floor(xyz[1])+1] for y in [Math.floor(xyz[1])-1..Math.floor(xyz[1])+1]
for x in [Math.floor(xyz[0])-1..Math.floor(xyz[0])+1] for x in [Math.floor(xyz[0])-1..Math.floor(xyz[0])+1]
tile = x: x, y: y, z: z tile = x: x, y: y, z: z
@ -136,7 +141,7 @@ module.exports = class Renderer
position[1]>@height position[1]>@height
continue continue
tiles.push xyz: tile, position: position tiles.push xyz: tile, position: position, scale: scale
tiles tiles
@ -147,40 +152,56 @@ module.exports = class Renderer
data: data data: data
meta: meta meta: meta
_renderTile: (tile, zoom, position) -> _getTileFeatures: (tile) ->
@canvas.reset() zoom = tile.meta.xyz.z
@canvas.translate position[0], position[1] position = tile.meta.position
scale = tile.meta.zoom
scale = @_scaleAtZoom zoom #TODO: if not filter or feature.data.properties[filterField] is filterValue
box = box =
minX: -position[0]*scale minX: -position[0]*scale
minY: -position[1]*scale minY: -position[1]*scale
maxX: (@width-position[0])*scale maxX: (@width-position[0])*scale
maxY: (@height-position[1])*scale maxY: (@height-position[1])*scale
# console.log box
# process.exit 0
features = {}
for layer in @config.drawOrder for layer in @config.drawOrder
idx = layer
if layer.indexOf(':') isnt -1 if layer.indexOf(':') isnt -1
[layer, filter] = layer.split /:/ [layer, filter] = layer.split /:/
[filterField, filterValue] = filter.split /=/ [filterField, filterValue] = filter.split /=/
else else
filter = false filter = false
continue unless tile.layers?[layer] continue unless tile.data.layers?[layer]
if @config.layers[layer]?.minZoom and zoom > @config.layers[layer].minZoom if @config.layers[layer]?.minZoom and zoom > @config.layers[layer].minZoom
continue continue
# TODO: reimplement tree based lookup features[idx] = tile.data.layers[layer].tree.all() #search box
#features = tile.layers[layer].tree.search box
#@notify "rendering #{features.length} #{layer} features.." tile.features = features
for feature in tile.layers[layer].features tile
feature = data: feature
if not filter or feature.data.properties[filterField] is filterValue _renderTiles: (tiles) ->
@_drawFeature layer, feature, scale, zoom drawn = {}
for layer in @config.drawOrder
short = layer.split(":")[0]
@notify "rendering #{layer}.."
for tile in tiles
continue unless tile.features[layer]?.length
@canvas.reset()
@canvas.translate tile.meta.position[0], tile.meta.position[1]
for feature in tile.features[layer]
continue if feature.data.id and drawn[feature.data.id]
drawn[feature.data.id] = true
@_drawFeature short, feature, tile.meta.scale, tile.meta.xyz.z
_writeFrame: -> _writeFrame: ->
unless @lastDrawAt unless @lastDrawAt

View File

@ -48,6 +48,7 @@ module.exports = class Termap
minZoom: null minZoom: null
maxZoom: 14.9
constructor: (options) -> constructor: (options) ->
@config[key] = val for key, val of options @config[key] = val for key, val of options
@ -198,6 +199,6 @@ module.exports = class Termap
zoomBy: (step) -> zoomBy: (step) ->
return @zoom = @minZoom if @zoom+step < @minZoom return @zoom = @minZoom if @zoom+step < @minZoom
return @zoom = @maxZoom if @zoom+step > @maxZoom
before = @zoom
@zoom += step @zoom += step