mirror of
https://github.com/rastapasta/mapscii.git
synced 2025-04-02 17:46:13 +02:00
🎊 multi tile support! endless left/right scroll, promise refactor
This commit is contained in:
parent
c5ae3a4963
commit
6c2819a89c
@ -8,6 +8,7 @@ x256 = require 'x256'
|
|||||||
mercator = new (require('sphericalmercator'))()
|
mercator = new (require('sphericalmercator'))()
|
||||||
tilebelt = require 'tilebelt'
|
tilebelt = require 'tilebelt'
|
||||||
MBTiles = require 'mbtiles'
|
MBTiles = require 'mbtiles'
|
||||||
|
Promise = require 'bluebird'
|
||||||
|
|
||||||
Canvas = require './Canvas'
|
Canvas = require './Canvas'
|
||||||
LabelBuffer = require './LabelBuffer'
|
LabelBuffer = require './LabelBuffer'
|
||||||
@ -99,40 +100,52 @@ module.exports = class Renderer
|
|||||||
|
|
||||||
# TODO: tiles = @_tilesInBBox @_getBBox()
|
# TODO: tiles = @_tilesInBBox @_getBBox()
|
||||||
|
|
||||||
z = Math.max 0, Math.floor zoom
|
Promise
|
||||||
xyz = tilebelt.pointToTileFraction center.lon, center.lat, z
|
.resolve @_visibleTiles center, zoom
|
||||||
tile =
|
.map (tile) => @_getTile tile.xyz, tile
|
||||||
size: tileSize
|
.then (tiles) =>
|
||||||
x: Math.floor xyz[0]
|
for tile in tiles
|
||||||
y: Math.floor xyz[1]
|
@_renderTile tile.data, zoom, tile.meta.position
|
||||||
z: z
|
|
||||||
|
|
||||||
tileSize = @config.tileSize / @_scaleAtZoom(zoom)
|
|
||||||
position = [
|
|
||||||
@width/2-(xyz[0]-tile.x)*tileSize
|
|
||||||
@height/2-(xyz[1]-tile.y)*tileSize
|
|
||||||
]
|
|
||||||
|
|
||||||
@_getTile tile
|
|
||||||
.then (data) =>
|
|
||||||
@_renderTile data, zoom, position
|
|
||||||
@_writeFrame()
|
@_writeFrame()
|
||||||
|
|
||||||
@isDrawing = false
|
@isDrawing = false
|
||||||
@lastDrawAt = Date.now()
|
@lastDrawAt = Date.now()
|
||||||
|
|
||||||
_getTile: (tile) ->
|
_visibleTiles: (center, zoom) ->
|
||||||
cacheKey = [tile.z, tile.x, tile.y].join "-"
|
z = Math.max 0, Math.floor zoom
|
||||||
|
xyz = tilebelt.pointToTileFraction center.lon, center.lat, z
|
||||||
|
|
||||||
# if data = @cache[cacheKey]
|
tiles = []
|
||||||
# console.log cacheKey
|
tileSize = @config.tileSize / @_scaleAtZoom(zoom)
|
||||||
# console.log data
|
for y in [Math.floor(xyz[1])-1..Math.floor(xyz[1])+1]
|
||||||
# return Promise.resolve data
|
for x in [Math.floor(xyz[0])-1..Math.floor(xyz[0])+1]
|
||||||
|
tile = x: x, y: y, z: z
|
||||||
|
|
||||||
|
position = [
|
||||||
|
@width/2-(xyz[0]-tile.x)*tileSize
|
||||||
|
@height/2-(xyz[1]-tile.y)*tileSize
|
||||||
|
]
|
||||||
|
|
||||||
|
tile.x %= Math.pow 2, z
|
||||||
|
tile.y %= Math.pow 2, z
|
||||||
|
|
||||||
|
if position[0]+tileSize < 0 or
|
||||||
|
position[1]+tileSize < 0 or
|
||||||
|
position[0]>@width or
|
||||||
|
position[1]>@height
|
||||||
|
continue
|
||||||
|
|
||||||
|
tiles.push xyz: tile, position: position
|
||||||
|
|
||||||
|
tiles
|
||||||
|
|
||||||
|
_getTile: (tile, meta = {}) ->
|
||||||
@tileSource
|
@tileSource
|
||||||
.getTile tile.z, tile.x, tile.y
|
.getTile tile.z, tile.x, tile.y
|
||||||
.then (data) =>
|
.then (data) =>
|
||||||
@cache[cacheKey] = data
|
data: data
|
||||||
|
meta: meta
|
||||||
|
|
||||||
_renderTile: (tile, zoom, position) ->
|
_renderTile: (tile, zoom, position) ->
|
||||||
@canvas.reset()
|
@canvas.reset()
|
||||||
@ -160,6 +173,7 @@ module.exports = class Renderer
|
|||||||
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 = tile.layers[layer].tree.search box
|
#features = tile.layers[layer].tree.search box
|
||||||
|
|
||||||
#@notify "rendering #{features.length} #{layer} features.."
|
#@notify "rendering #{features.length} #{layer} features.."
|
||||||
|
@ -174,6 +174,8 @@ module.exports = class Termap
|
|||||||
.draw @center, @zoom, @rotation
|
.draw @center, @zoom, @rotation
|
||||||
.then =>
|
.then =>
|
||||||
@renderer.notify @_getFooter()
|
@renderer.notify @_getFooter()
|
||||||
|
.catch =>
|
||||||
|
@renderer.notify "renderer is busy"
|
||||||
|
|
||||||
_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)
|
||||||
|
Loading…
Reference in New Issue
Block a user