mirror of
https://github.com/rastapasta/mapscii.git
synced 2024-11-08 01:04:01 +01:00
🎨 starting refactor, config hash, more todos
This commit is contained in:
parent
3b03122807
commit
29d6a084fb
@ -8,7 +8,8 @@ Discover the world in your console - render vector tile maps from any source!
|
|||||||
* [ ] from local mbtiles
|
* [ ] from local mbtiles
|
||||||
* [ ] from remote url
|
* [ ] from remote url
|
||||||
* [ ] label drawing
|
* [ ] label drawing
|
||||||
* [ ] center+zoom based viewport
|
* [ ] lat/lng-center + zoom based viewport
|
||||||
|
* [ ] TileSource class (abstracting URL, mbtiles, single vector tile source)
|
||||||
* [ ] zoom while keeping center
|
* [ ] zoom while keeping center
|
||||||
* [ ] API
|
* [ ] API
|
||||||
* [ ] setCenter
|
* [ ] setCenter
|
||||||
|
@ -15,13 +15,20 @@ mouse.start()
|
|||||||
width = null
|
width = null
|
||||||
height = null
|
height = null
|
||||||
|
|
||||||
drawOrder = ["admin", "water", "landuse", "building", "road"]
|
config =
|
||||||
layers =
|
drawOrder: ["admin", "water", "landuse", "building", "road"]
|
||||||
road: "white"
|
|
||||||
landuse: "green"
|
layers:
|
||||||
water: "blue"
|
road:
|
||||||
admin: "red"
|
color: "white"
|
||||||
building: 8
|
landuse:
|
||||||
|
color: "green"
|
||||||
|
water:
|
||||||
|
color: "blue"
|
||||||
|
admin:
|
||||||
|
color: "red"
|
||||||
|
building:
|
||||||
|
color: 8
|
||||||
|
|
||||||
canvas = null
|
canvas = null
|
||||||
|
|
||||||
@ -37,11 +44,19 @@ zlib.gunzip data, (err, buffer) ->
|
|||||||
throw new Error err if err
|
throw new Error err if err
|
||||||
|
|
||||||
tile = new VectorTile new Protobuf buffer
|
tile = new VectorTile new Protobuf buffer
|
||||||
|
|
||||||
|
# Load all layers and preparse the included geometries
|
||||||
for name,layer of tile.layers
|
for name,layer of tile.layers
|
||||||
if layers[name]
|
if config.layers[name]
|
||||||
features[name] = []
|
features[name] = []
|
||||||
|
|
||||||
for i in [0...layer.length]
|
for i in [0...layer.length]
|
||||||
features[name].push layer.feature(i).loadGeometry()
|
feature = layer.feature i
|
||||||
|
features[name].push
|
||||||
|
type: feature.type
|
||||||
|
id: feature.id
|
||||||
|
properties: feature.properties
|
||||||
|
points: feature.loadGeometry()
|
||||||
|
|
||||||
draw()
|
draw()
|
||||||
|
|
||||||
@ -62,12 +77,12 @@ draw = ->
|
|||||||
canvas.save()
|
canvas.save()
|
||||||
|
|
||||||
canvas.translate view[0], view[1]
|
canvas.translate view[0], view[1]
|
||||||
for layer in drawOrder
|
for layer in config.drawOrder
|
||||||
continue unless features[layer]
|
continue unless features[layer]
|
||||||
|
|
||||||
canvas.strokeStyle = layers[layer]
|
canvas.strokeStyle = config.layers[layer].color
|
||||||
for feature in features[layer]
|
for feature in features[layer]
|
||||||
for line in feature
|
for line in feature.points
|
||||||
found = false
|
found = false
|
||||||
points = for point in line
|
points = for point in line
|
||||||
p = [point.x/scale, point.y/scale]
|
p = [point.x/scale, point.y/scale]
|
||||||
@ -81,7 +96,11 @@ draw = ->
|
|||||||
canvas.lineTo point... for point in points
|
canvas.lineTo point... for point in points
|
||||||
canvas.stroke()
|
canvas.stroke()
|
||||||
|
|
||||||
|
canvas.fillStyle = "white"
|
||||||
|
canvas.fillText "test", 0, 0
|
||||||
|
canvas.stroke()
|
||||||
canvas.restore()
|
canvas.restore()
|
||||||
|
|
||||||
flush()
|
flush()
|
||||||
process.stdout.write getStatus()
|
process.stdout.write getStatus()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user