mirror of
https://github.com/rastapasta/mapscii.git
synced 2024-11-07 16:54:22 +01:00
🔳 calculating visible tiles
This commit is contained in:
parent
e841d634f9
commit
eb88d231a9
2
main.js
2
main.js
@ -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/germany.pbf.gz");
|
||||
data = fs.readFileSync(__dirname+"/tiles/world.pbf.gz");
|
||||
tile = new Tile(data);
|
||||
termap.renderer.features = tile.layers
|
||||
termap._draw();
|
||||
|
@ -167,7 +167,7 @@ module.exports = class Renderer
|
||||
@canvas.polyline points, colorCode, width for points in toDraw
|
||||
|
||||
when "Polygon"
|
||||
@canvas.polygon toDraw[0], colorCode
|
||||
@canvas.polygon toDraw, colorCode
|
||||
|
||||
when "Point"
|
||||
text = feature.properties["name_"+@config.language] or
|
||||
|
@ -31,10 +31,10 @@ module.exports = class Termap
|
||||
|
||||
degree: 0
|
||||
center:
|
||||
#lat: 49.0189
|
||||
#lon: 12.0990
|
||||
lat: 0 #26.7
|
||||
lon: 0 #20.2
|
||||
lat: 49.0189
|
||||
lon: 12.0990
|
||||
#lat: 0 #26.7
|
||||
#lon: 0 #20.2
|
||||
|
||||
zoom: 0
|
||||
view: [0, 0]
|
||||
@ -150,15 +150,33 @@ module.exports = class Termap
|
||||
|
||||
_getTiles: ->
|
||||
|
||||
_getBBox: ->
|
||||
_getBBox: (zoom = @zoom) ->
|
||||
[x, y] = utils.ll2xy @center.lon, @center.lat
|
||||
meterPerPixel = utils.metersPerPixel @zoom, @center.lat
|
||||
meterPerPixel = utils.metersPerPixel zoom, @center.lat
|
||||
|
||||
width = @width * meterPerPixel * .5
|
||||
height = @height * meterPerPixel * .5
|
||||
width = @width * meterPerPixel
|
||||
height = @height * meterPerPixel
|
||||
|
||||
mercator.inverse([x - width, y + height]).concat mercator.inverse([x + width, y - height])
|
||||
west = x - width*.5
|
||||
east = x + width*.5
|
||||
south = y + height*.5
|
||||
north = y - height*.5
|
||||
|
||||
box = mercator
|
||||
.inverse([west+1, south])
|
||||
.concat mercator.inverse([east-1, north])
|
||||
|
||||
_tilesInBBox: (bbox, zoom = @zoom) ->
|
||||
tile = utils.ll2tile bbox[0], bbox[1], Math.floor zoom
|
||||
tiles =
|
||||
minX: Math.max 0, tile[0]
|
||||
minY: Math.max 0, tile[1]
|
||||
|
||||
tile = utils.ll2tile bbox[2], bbox[3], Math.floor zoom
|
||||
tiles.maxX = Math.max 0, tile[0]
|
||||
tiles.maxY = Math.max 0, tile[1]
|
||||
|
||||
tiles
|
||||
|
||||
_getFooter: ->
|
||||
# features = @renderer.featuresAt @mousePosition.x-1-(@view[0]>>1), @mousePosition.y-1-(@view[1]>>2)
|
||||
@ -170,8 +188,12 @@ module.exports = class Termap
|
||||
# ).join(", ")+"] "+
|
||||
# "#{@mousePosition.x} #{@mousePosition.y}"
|
||||
#"center: [#{utils.digits @center.lat, 2}, #{utils.digits @center.lng, 2}]}"
|
||||
bbox = @_getBBox()
|
||||
|
||||
"zoom: #{utils.digits @zoom, 2} "+
|
||||
"bbox: [#{@_getBBox().map((z) -> utils.digits(z, 2)).join(', ')}]"
|
||||
#{}"bbox: [#{bbox.map((z) -> utils.digits(z, 2)).join(', ')}]"+
|
||||
"tiles: "+(v for k,v of @_tilesInBBox(bbox) when typeof v is "number").join(",")
|
||||
|
||||
|
||||
#features.map((f) -> JSON.stringify f.feature.properties).join(" - ")
|
||||
|
||||
|
@ -31,8 +31,10 @@ utils =
|
||||
]
|
||||
|
||||
ll2tile: (lon, lat, zoom) ->
|
||||
x: Math.floor (lon+180)/360*Math.pow(2, zoom)
|
||||
y: Math.floor (1-Math.log(Math.tan(lat*Math.PI/180)+1/Math.cos(lat*Math.PI/180))/Math.PI)/2*Math.pow(2, zoom)
|
||||
[
|
||||
Math.floor (lon+180)/360*Math.pow(2, zoom)
|
||||
Math.floor (1-Math.log(Math.tan(lat*Math.PI/180)+1/Math.cos(lat*Math.PI/180))/Math.PI)/2*Math.pow(2, zoom)
|
||||
]
|
||||
|
||||
tile2ll: (x, y, zoom) ->
|
||||
n = Math.PI - 2*Math.PI*y/Math.pow(2, zoom)
|
||||
|
Loading…
Reference in New Issue
Block a user