mirror of
https://github.com/rastapasta/mapscii.git
synced 2025-03-19 08:18:13 +01:00
🐁 adding Renderer.featuresAt to return features for mouse positions
This commit is contained in:
parent
80edcc3f04
commit
0e481bf5c9
@ -48,6 +48,8 @@ No web browser around? No worries - discover the planet in your console!
|
|||||||
* [`sphericalmercator`](https://github.com/mapbox/node-sphericalmercator) for [EPSG:3857](http://spatialreference.org/ref/sr-org/6864/) <> [WGS84](http://spatialreference.org/ref/epsg/wgs-84/) conversions
|
* [`sphericalmercator`](https://github.com/mapbox/node-sphericalmercator) for [EPSG:3857](http://spatialreference.org/ref/sr-org/6864/) <> [WGS84](http://spatialreference.org/ref/epsg/wgs-84/) conversions
|
||||||
|
|
||||||
### TODOs
|
### TODOs
|
||||||
|
* [ ] mouse hover of POIs (maybe even polygons?)
|
||||||
|
* [ ] termap-server - telnet and ssh access
|
||||||
* [ ] cli linking
|
* [ ] cli linking
|
||||||
* [ ] mapping of view to tiles to show
|
* [ ] mapping of view to tiles to show
|
||||||
* [x] abstracted MapBox style JSON support
|
* [x] abstracted MapBox style JSON support
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
rbush = require 'rbush'
|
rbush = require 'rbush'
|
||||||
|
|
||||||
module.exports = class LabelBuffer
|
module.exports = class LabelBuffer
|
||||||
|
treeWithMargin: null
|
||||||
tree: null
|
tree: null
|
||||||
|
|
||||||
margin: 5
|
margin: 5
|
||||||
|
|
||||||
constructor: (@width, @height) ->
|
constructor: (@width, @height) ->
|
||||||
@ -18,22 +20,28 @@ module.exports = class LabelBuffer
|
|||||||
clear: ->
|
clear: ->
|
||||||
@tree.clear()
|
@tree.clear()
|
||||||
|
|
||||||
|
|
||||||
project: (x, y) ->
|
project: (x, y) ->
|
||||||
[Math.floor(x/2), Math.floor(y/4)]
|
[Math.floor(x/2), Math.floor(y/4)]
|
||||||
|
|
||||||
writeIfPossible: (text, x, y, margin = @margin) ->
|
writeIfPossible: (text, x, y, feature, margin = @margin) ->
|
||||||
point = @project x, y
|
point = @project x, y
|
||||||
|
|
||||||
if @_hasSpace text, point[0], point[1]
|
if @_hasSpace text, point[0], point[1]
|
||||||
@tree.insert @_calculateArea text, point[0], point[1], margin
|
data = @_calculateArea text, point[0], point[1], margin
|
||||||
|
data.feature = feature
|
||||||
|
@tree.insert data
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
|
|
||||||
_hasSpace: (text, x, y) ->
|
featuresAt: (x, y) ->
|
||||||
not @tree.collides @_calculateArea text, x, y, 0
|
@tree.search minX: x, maxX: x, minY: y, maxY: y
|
||||||
|
|
||||||
_calculateArea: (text, x, y, margin) ->
|
_hasSpace: (text, x, y) ->
|
||||||
|
not @tree.collides @_calculateArea text, x, y
|
||||||
|
|
||||||
|
_calculateArea: (text, x, y, margin = 0) ->
|
||||||
minX: x-margin
|
minX: x-margin
|
||||||
minY: y-margin
|
minY: y-margin/4
|
||||||
maxX: x+margin+text.length
|
maxX: x+margin+text.length
|
||||||
maxY: y+margin
|
maxY: y+margin/4
|
||||||
|
@ -100,6 +100,10 @@ module.exports = class Renderer
|
|||||||
|
|
||||||
@isDrawing = false
|
@isDrawing = false
|
||||||
|
|
||||||
|
featuresAt: (x, y) ->
|
||||||
|
@labelBuffer.featuresAt x, y
|
||||||
|
|
||||||
|
|
||||||
_write: (output) ->
|
_write: (output) ->
|
||||||
process.stdout.write output
|
process.stdout.write output
|
||||||
|
|
||||||
@ -165,9 +169,9 @@ module.exports = class Renderer
|
|||||||
x = point[0] - text.length
|
x = point[0] - text.length
|
||||||
margin = @config.layers[layer]?.margin or @config.labelMargin
|
margin = @config.layers[layer]?.margin or @config.labelMargin
|
||||||
|
|
||||||
if @labelBuffer.writeIfPossible text, x, point[1], margin
|
if @labelBuffer.writeIfPossible text, x, point[1], feature, margin
|
||||||
@canvas.text text, x, point[1], colorCode
|
@canvas.text text, x, point[1], colorCode
|
||||||
else if @config.layers[layer]?.cluster and @labelBuffer.writeIfPossible "X", point[0], point[1], 3
|
else if @config.layers[layer]?.cluster and @labelBuffer.writeIfPossible "X", point[0], point[1], feature, 3
|
||||||
@canvas.text "◉", point[0], point[1], colorCode
|
@canvas.text "◉", point[0], point[1], colorCode
|
||||||
|
|
||||||
_scaleAndReduce: (points, scale) ->
|
_scaleAndReduce: (points, scale) ->
|
||||||
|
@ -97,8 +97,10 @@ module.exports = class Termap
|
|||||||
else
|
else
|
||||||
@mouseDragging = x: event.x, y: event.y
|
@mouseDragging = x: event.x, y: event.y
|
||||||
|
|
||||||
# update internal mouse tracker
|
# update internal mouse tracker
|
||||||
@mousePosition = x: event.x, y: event.y
|
@mousePosition = x: event.x, y: event.y
|
||||||
|
@renderer.notify @_getFooter()
|
||||||
|
|
||||||
|
|
||||||
_onKey: (key) ->
|
_onKey: (key) ->
|
||||||
# check if the pressed key is configured
|
# check if the pressed key is configured
|
||||||
@ -138,9 +140,13 @@ module.exports = class Termap
|
|||||||
#mercator.inverse([x - width/2, y + width/2]).concat mercator.inverse([x + width/2, y - width/2])
|
#mercator.inverse([x - width/2, y + width/2]).concat mercator.inverse([x + width/2, y - width/2])
|
||||||
|
|
||||||
_getFooter: ->
|
_getFooter: ->
|
||||||
#{}"center: [#{utils.digits @center.lat, 2}, #{utils.digits @center.lng, 2}] zoom: #{utils.digits @zoom, 2}"
|
features = @renderer.featuresAt @mousePosition.x-1-(@view[0]>>1), @mousePosition.y-1-(@view[1]>>2)
|
||||||
"bbox: [#{@_getBBox().map((z) -> utils.digits(z, 2)).join(', ')}]"
|
"features: ["+features.map((f) -> f.feature.id).join(", ")+"] "+
|
||||||
#{}"#{@mouseDragging.x} #{@mouseDragging.y} #{@mousePosition.x} #{@mousePosition.y}"
|
"#{@mousePosition.x} #{@mousePosition.y}"
|
||||||
|
#"center: [#{utils.digits @center.lat, 2}, #{utils.digits @center.lng, 2}] zoom: #{utils.digits @zoom, 2}"
|
||||||
|
#"bbox: [#{@_getBBox().map((z) -> utils.digits(z, 2)).join(', ')}]"
|
||||||
|
|
||||||
|
#features.map((f) -> JSON.stringify f.feature.properties).join(" - ")
|
||||||
|
|
||||||
zoomBy: (step) ->
|
zoomBy: (step) ->
|
||||||
return @zoom = 0 if @zoom+step < 0
|
return @zoom = 0 if @zoom+step < 0
|
||||||
|
BIN
tiles/berlin.z12.pbf.gz
Normal file
BIN
tiles/berlin.z12.pbf.gz
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user