mirror of
https://github.com/rastapasta/mapscii.git
synced 2024-11-21 23:53:08 +01:00
🔍 improving label collision detection
This commit is contained in:
parent
c717b7504f
commit
8ccca7f3e0
18
README.md
18
README.md
@ -21,18 +21,22 @@ Discover the world in your console!
|
||||
` termap`
|
||||
|
||||
## Behind the scenes
|
||||
|
||||
### Libraries
|
||||
#### Mastering the console
|
||||
* [`drawille-canvas-blessed-contrib`](https://github.com/yaronn/drawille-canvas-blessed-contrib/) for braille rendering
|
||||
* [`term-mouse`](https://github.com/CoderPuppy/term-mouse) for mouse handling
|
||||
* [`keypress`](https://github.com/TooTallNate/keypress) for input handling
|
||||
|
||||
* [`drawille-canvas-blessed-contrib`](https://github.com/yaronn/drawille-canvas-blessed-contrib/) for braille rendering
|
||||
* [`term-mouse`](https://github.com/CoderPuppy/term-mouse) for mouse handling
|
||||
* [`keypress`](https://github.com/TooTallNate/keypress) for input handling
|
||||
* [`node-mbtiles`](https://github.com/mapbox/node-mbtiles) for MBTiles parsing
|
||||
* [`pbf`](https://github.com/mapbox/pbf) for Protobuf decoding
|
||||
#### Discovering the map data
|
||||
* [`node-mbtiles`](https://github.com/mapbox/node-mbtiles) for [MBTiles](https://github.com/mapbox/mbtiles-spec/blob/master/1.2/spec.md) parsing
|
||||
* [`pbf`](https://github.com/mapbox/pbf) for [Protobuf](https://developers.google.com/protocol-buffers/) decoding
|
||||
* [`vector-tile-js`](https://github.com/mapbox/vector-tile-js) for [VectorTile](https://github.com/mapbox/vector-tile-spec/tree/master/2.1) parsing
|
||||
* [`rbush`](https://github.com/mourner/rbush) for 2D spatial indexing
|
||||
|
||||
#### Juggling the vectors and numbers
|
||||
* [`rbush`](https://github.com/mourner/rbush) for 2D spatial indexing based label and mouse collision detection
|
||||
* [`sphericalmercator`](https://github.com/mapbox/node-sphericalmercator) for EPSG:3857 <> WGS84 conversions
|
||||
|
||||
|
||||
## Wishlist
|
||||
|
||||
* node port of [libdrawille](https://github.com/Huulivoide/libdrawille) - well optimized library, supporting filled polygons
|
||||
|
@ -13,15 +13,16 @@ module.exports = class LabelBuffer
|
||||
writeIfPossible: (text, x, y) ->
|
||||
point = @project x, y
|
||||
|
||||
return false unless @_hasSpace text, point[0], point[1]
|
||||
@tree.insert @_calculateArea text, point[0], point[1]
|
||||
true
|
||||
if @_hasSpace text, point[0], point[1]
|
||||
@tree.insert @_calculateArea text, point[0], point[1]
|
||||
else
|
||||
false
|
||||
|
||||
_hasSpace: (text, x, y) ->
|
||||
not @tree.collides @_calculateArea text, x, y
|
||||
not @tree.collides @_calculateArea text, x, y, 0
|
||||
|
||||
_calculateArea: (text, x, y) ->
|
||||
minX: x-@margin
|
||||
minY: y-@margin
|
||||
maxX: x+@margin+text.length
|
||||
maxY: y+@margin
|
||||
_calculateArea: (text, x, y, margin = @margin) ->
|
||||
minX: x-margin
|
||||
minY: y-margin
|
||||
maxX: x+margin+text.length
|
||||
maxY: y+margin
|
||||
|
@ -285,6 +285,6 @@ class Termap
|
||||
termap = new Termap()
|
||||
|
||||
# TODO: abstracing this class, create loader class
|
||||
data = fs.readFileSync __dirname+"/tiles/world.pbf.gz"
|
||||
data = fs.readFileSync __dirname+"/tiles/regensburg.pbf.gz"
|
||||
termap.features = termap._getFeatures termap._parseTile data
|
||||
termap._draw()
|
||||
|
Loading…
Reference in New Issue
Block a user