mirror of
https://github.com/rastapasta/mapscii.git
synced 2025-05-31 15:25:37 +02:00
👷 cleanup, testing tiles with an extent of 512, config params
This commit is contained in:
parent
a21d172a2c
commit
59b64e8dd2
@ -9,7 +9,7 @@ No web browser around? Don't worry - and discover the planet in your console!
|
|||||||
* Highly customizable styling (reuse your [mapbox-gl-styles](https://github.com/mapbox/mapbox-gl-styles))
|
* Highly customizable styling (reuse your [mapbox-gl-styles](https://github.com/mapbox/mapbox-gl-styles))
|
||||||
* Compatible with Linux and OSX terminals, Windows support via [PuTTY](http://www.putty.org/)
|
* Compatible with Linux and OSX terminals, Windows support via [PuTTY](http://www.putty.org/)
|
||||||
* Use the default or your own map server - or work offline with VectorTile/MBTiles
|
* Use the default or your own map server - or work offline with VectorTile/MBTiles
|
||||||
* 99% pure Coffee-/JavaScript! :sunglasses:
|
* 100% pure Coffee-/JavaScript! :sunglasses:
|
||||||
|
|
||||||
## How to install
|
## How to install
|
||||||
|
|
||||||
|
5
main.js
5
main.js
@ -7,12 +7,9 @@
|
|||||||
|
|
||||||
TODO: params parsing and so on
|
TODO: params parsing and so on
|
||||||
#*/
|
#*/
|
||||||
|
|
||||||
require('coffee-script/register');
|
require('coffee-script/register');
|
||||||
|
|
||||||
const fs = require('fs');
|
const Termap = require('./src/Termap');
|
||||||
const Termap = require(__dirname+'/src/Termap');
|
|
||||||
const Tile = require(__dirname+'/src/Tile')
|
|
||||||
|
|
||||||
termap = new Termap();
|
termap = new Termap();
|
||||||
termap.init();
|
termap.init();
|
||||||
|
@ -23,22 +23,19 @@ module.exports = class Renderer
|
|||||||
|
|
||||||
labelMargin: 5
|
labelMargin: 5
|
||||||
|
|
||||||
tileSize: 4096
|
tileSize: 512
|
||||||
projectSize: 256
|
projectSize: 256
|
||||||
maxZoom: 14
|
maxZoom: 14
|
||||||
|
|
||||||
#"poi_label", "water",
|
#"poi_label", "water",
|
||||||
drawOrder: [
|
drawOrder: [
|
||||||
"admin"
|
"admin"
|
||||||
|
|
||||||
"building"
|
|
||||||
"water"
|
"water"
|
||||||
|
"marine_label"
|
||||||
|
"building"
|
||||||
"road"
|
"road"
|
||||||
# "road:structure=bridge"
|
|
||||||
|
|
||||||
"country_label"
|
"country_label"
|
||||||
"state_label"
|
"state_label"
|
||||||
|
|
||||||
"water_label"
|
"water_label"
|
||||||
"place_label"
|
"place_label"
|
||||||
"rail_station_label"
|
"rail_station_label"
|
||||||
@ -75,16 +72,16 @@ module.exports = class Renderer
|
|||||||
place_label: cluster: true
|
place_label: cluster: true
|
||||||
state_label: cluster: true
|
state_label: cluster: true
|
||||||
|
|
||||||
|
terminal:
|
||||||
|
CLEAR: "\x1B[2J"
|
||||||
|
MOVE: "\x1B[?6h"
|
||||||
|
|
||||||
isDrawing: false
|
isDrawing: false
|
||||||
lastDrawAt: 0
|
lastDrawAt: 0
|
||||||
|
|
||||||
labelBuffer: null
|
labelBuffer: null
|
||||||
tileSource: null
|
tileSource: null
|
||||||
|
|
||||||
terminal:
|
|
||||||
CLEAR: "\x1B[2J"
|
|
||||||
MOVE: "\x1B[?6h"
|
|
||||||
|
|
||||||
constructor: (@output, @tileSource) ->
|
constructor: (@output, @tileSource) ->
|
||||||
@labelBuffer = new LabelBuffer()
|
@labelBuffer = new LabelBuffer()
|
||||||
|
|
||||||
@ -94,7 +91,7 @@ module.exports = class Renderer
|
|||||||
setSize: (@width, @height) ->
|
setSize: (@width, @height) ->
|
||||||
@canvas = new Canvas @width, @height
|
@canvas = new Canvas @width, @height
|
||||||
|
|
||||||
draw: (center, zoom, rotation = 0) ->
|
draw: (center, zoom) ->
|
||||||
return Promise.reject() if @isDrawing
|
return Promise.reject() if @isDrawing
|
||||||
@isDrawing = true
|
@isDrawing = true
|
||||||
|
|
||||||
@ -105,8 +102,6 @@ module.exports = class Renderer
|
|||||||
|
|
||||||
@canvas.clear()
|
@canvas.clear()
|
||||||
|
|
||||||
# TODO: tiles = @_tilesInBBox @_getBBox()
|
|
||||||
|
|
||||||
Promise
|
Promise
|
||||||
.resolve @_visibleTiles center, zoom
|
.resolve @_visibleTiles center, zoom
|
||||||
.map (tile) => @_getTile tile
|
.map (tile) => @_getTile tile
|
||||||
@ -177,16 +172,8 @@ module.exports = class Renderer
|
|||||||
|
|
||||||
features = {}
|
features = {}
|
||||||
for layer in @config.drawOrder
|
for layer in @config.drawOrder
|
||||||
idx = layer
|
|
||||||
if layer.indexOf(':') isnt -1
|
|
||||||
[layer, filter] = layer.split /:/
|
|
||||||
[filterField, filterValue] = filter.split /=/
|
|
||||||
else
|
|
||||||
filter = false
|
|
||||||
|
|
||||||
continue unless tile.data.layers?[layer]
|
continue unless tile.data.layers?[layer]
|
||||||
#if not filter or feature.data.properties[filterField] is filterValue
|
features[layer] = tile.data.layers[layer].tree.search box
|
||||||
features[idx] = tile.data.layers[layer].tree.search box
|
|
||||||
|
|
||||||
tile.features = features
|
tile.features = features
|
||||||
tile
|
tile
|
||||||
@ -221,12 +208,6 @@ module.exports = class Renderer
|
|||||||
featuresAt: (x, y) ->
|
featuresAt: (x, y) ->
|
||||||
@labelBuffer.featuresAt x, y
|
@labelBuffer.featuresAt x, y
|
||||||
|
|
||||||
_tilesInBBox: (bbox, zoom) ->
|
|
||||||
tiles = {}
|
|
||||||
[tiles.minX, tiles.minY] = utils.ll2tile bbox[0], bbox[1], Math.floor zoom
|
|
||||||
[tiles.maxX, tiles.maxY] = utils.ll2tile bbox[2], bbox[3], Math.floor zoom
|
|
||||||
tiles
|
|
||||||
|
|
||||||
_scaleAtZoom: (zoom) ->
|
_scaleAtZoom: (zoom) ->
|
||||||
baseZoom = Math.min @config.maxZoom, Math.floor Math.max 0, zoom
|
baseZoom = Math.min @config.maxZoom, Math.floor Math.max 0, zoom
|
||||||
(@config.tileSize/@config.projectSize)/Math.pow(2, zoom-baseZoom)
|
(@config.tileSize/@config.projectSize)/Math.pow(2, zoom-baseZoom)
|
||||||
|
@ -22,10 +22,14 @@ module.exports = class Termap
|
|||||||
#source: __dirname+"/../mbtiles/regensburg.mbtiles"
|
#source: __dirname+"/../mbtiles/regensburg.mbtiles"
|
||||||
styleFile: __dirname+"/../styles/bright.json"
|
styleFile: __dirname+"/../styles/bright.json"
|
||||||
|
|
||||||
zoomStep: 0.2
|
initialZoom: 14
|
||||||
maxZoom: 18
|
maxZoom: 18
|
||||||
|
zoomStep: 0.2
|
||||||
|
|
||||||
headless: false
|
headless: false
|
||||||
|
# size:
|
||||||
|
# width: 40*2
|
||||||
|
# height: 10*4
|
||||||
|
|
||||||
width: null
|
width: null
|
||||||
height: null
|
height: null
|
||||||
@ -40,7 +44,6 @@ module.exports = class Termap
|
|||||||
renderer: null
|
renderer: null
|
||||||
|
|
||||||
zoom: 0
|
zoom: 0
|
||||||
rotation: 0
|
|
||||||
center:
|
center:
|
||||||
# sf lat: 37.787946, lon: -122.407522
|
# sf lat: 37.787946, lon: -122.407522
|
||||||
# iceland lat: 64.124229, lon: -21.811552
|
# iceland lat: 64.124229, lon: -21.811552
|
||||||
@ -97,15 +100,15 @@ module.exports = class Termap
|
|||||||
@_draw()
|
@_draw()
|
||||||
|
|
||||||
@_resizeRenderer()
|
@_resizeRenderer()
|
||||||
@zoom = @minZoom
|
@zoom = if @config.initialZoom isnt null then @config.initialZoom else @minZoom
|
||||||
|
|
||||||
_resizeRenderer: (cb) ->
|
_resizeRenderer: (cb) ->
|
||||||
unless @config.headless
|
if @config.size
|
||||||
|
@width = @config.size.width
|
||||||
|
@height = @config.size.height
|
||||||
|
else
|
||||||
@width = @config.output.columns >> 1 << 2
|
@width = @config.output.columns >> 1 << 2
|
||||||
@height = @config.output.rows * 4 - 4
|
@height = @config.output.rows * 4 - 4
|
||||||
else
|
|
||||||
@width = 256
|
|
||||||
@height = 152
|
|
||||||
|
|
||||||
@minZoom = 4-Math.log(4096/@width)/Math.LN2
|
@minZoom = 4-Math.log(4096/@width)/Math.LN2
|
||||||
|
|
||||||
@ -155,9 +158,6 @@ module.exports = class Termap
|
|||||||
when "a" then @zoomBy @config.zoomStep
|
when "a" then @zoomBy @config.zoomStep
|
||||||
when "z" then @zoomBy -@config.zoomStep
|
when "z" then @zoomBy -@config.zoomStep
|
||||||
|
|
||||||
when "k" then @rotation += 15
|
|
||||||
when "l" then @rotation -= 15
|
|
||||||
|
|
||||||
when "left" then @moveBy 0, -8/Math.pow(2, @zoom)
|
when "left" then @moveBy 0, -8/Math.pow(2, @zoom)
|
||||||
when "right" then @moveBy 0, 8/Math.pow(2, @zoom)
|
when "right" then @moveBy 0, 8/Math.pow(2, @zoom)
|
||||||
when "up" then @moveBy 6/Math.pow(2, @zoom), 0
|
when "up" then @moveBy 6/Math.pow(2, @zoom), 0
|
||||||
@ -174,7 +174,7 @@ module.exports = class Termap
|
|||||||
|
|
||||||
_draw: ->
|
_draw: ->
|
||||||
@renderer
|
@renderer
|
||||||
.draw @center, @zoom, @rotation
|
.draw @center, @zoom
|
||||||
.then (frame) =>
|
.then (frame) =>
|
||||||
@_write frame
|
@_write frame
|
||||||
@notify @_getFooter()
|
@notify @_getFooter()
|
||||||
@ -201,7 +201,7 @@ module.exports = class Termap
|
|||||||
#features.map((f) -> JSON.stringify f.feature.properties).join(" - ")
|
#features.map((f) -> JSON.stringify f.feature.properties).join(" - ")
|
||||||
|
|
||||||
notify: (text) ->
|
notify: (text) ->
|
||||||
@_write "\r\x1B[K"+text
|
@_write "\r\x1B[K"+text unless @config.headless
|
||||||
|
|
||||||
_write: (output) ->
|
_write: (output) ->
|
||||||
@config.output.write output
|
@config.output.write output
|
||||||
|
@ -48,8 +48,23 @@ class Tile
|
|||||||
type = feature.properties.$type =
|
type = feature.properties.$type =
|
||||||
[undefined, "Point", "LineString", "Polygon"][feature.type]
|
[undefined, "Point", "LineString", "Polygon"][feature.type]
|
||||||
|
|
||||||
|
# TODO: monkey patching test case for tiles with a reduced extent
|
||||||
|
geo = for sub, i in feature.loadGeometry()
|
||||||
|
points = []
|
||||||
|
last = null
|
||||||
|
for point, j in sub
|
||||||
|
p =
|
||||||
|
x: Math.floor point.x/8
|
||||||
|
y: Math.floor point.y/8
|
||||||
|
|
||||||
|
if last and last.x is p.x and last.y is p.y
|
||||||
|
continue
|
||||||
|
points.push p
|
||||||
|
last = p
|
||||||
|
points
|
||||||
|
|
||||||
data =
|
data =
|
||||||
points: feature.loadGeometry()
|
points: geo
|
||||||
properties: feature.properties
|
properties: feature.properties
|
||||||
id: feature.id
|
id: feature.id
|
||||||
type: type
|
type: type
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "Bright",
|
"name": "Bright",
|
||||||
"constants": {
|
"constants": {
|
||||||
"@water": "#55c",
|
"@background": "#000",
|
||||||
|
"@water": "#5f87ff",
|
||||||
|
|
||||||
|
"@building": "#606060",
|
||||||
|
|
||||||
"@country_label_1": "#ff0",
|
"@country_label_1": "#ff0",
|
||||||
"@country_label_2": "#ff0",
|
"@country_label_2": "#ff0",
|
||||||
"@country_label_3": "#ff0",
|
"@country_label_3": "#ff0",
|
||||||
@ -20,7 +24,7 @@
|
|||||||
"type": "background",
|
"type": "background",
|
||||||
"id": "background",
|
"id": "background",
|
||||||
"paint": {
|
"paint": {
|
||||||
"background-color": "#000"
|
"background-color": "@background"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -290,19 +294,7 @@
|
|||||||
"type": "line",
|
"type": "line",
|
||||||
"id": "building",
|
"id": "building",
|
||||||
"paint": {
|
"paint": {
|
||||||
"fill-color": {
|
"line-color": "@building"
|
||||||
"base": 1,
|
|
||||||
"stops": [
|
|
||||||
[
|
|
||||||
14.5,
|
|
||||||
"#525652"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
16,
|
|
||||||
"#5f5b57"
|
|
||||||
]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"source-layer": "building",
|
"source-layer": "building",
|
||||||
"minzoom": 14.5
|
"minzoom": 14.5
|
||||||
|
Loading…
x
Reference in New Issue
Block a user