diff --git a/README.md b/README.md index 4c9b579..dad31e1 100644 --- a/README.md +++ b/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 diff --git a/src/LabelBuffer.coffee b/src/LabelBuffer.coffee index 2c46f29..0aef7db 100644 --- a/src/LabelBuffer.coffee +++ b/src/LabelBuffer.coffee @@ -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 diff --git a/termap.coffee b/termap.coffee index 786e608..6b8c102 100644 --- a/termap.coffee +++ b/termap.coffee @@ -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()