diff --git a/README.md b/README.md index 95247f5..2b60d8e 100644 --- a/README.md +++ b/README.md @@ -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 ### TODOs +* [ ] mouse hover of POIs (maybe even polygons?) +* [ ] termap-server - telnet and ssh access * [ ] cli linking * [ ] mapping of view to tiles to show * [x] abstracted MapBox style JSON support diff --git a/src/LabelBuffer.coffee b/src/LabelBuffer.coffee index 84f355d..2f78cda 100644 --- a/src/LabelBuffer.coffee +++ b/src/LabelBuffer.coffee @@ -9,7 +9,9 @@ rbush = require 'rbush' module.exports = class LabelBuffer + treeWithMargin: null tree: null + margin: 5 constructor: (@width, @height) -> @@ -18,22 +20,28 @@ module.exports = class LabelBuffer clear: -> @tree.clear() + project: (x, y) -> [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 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 false - _hasSpace: (text, x, y) -> - not @tree.collides @_calculateArea text, x, y, 0 + featuresAt: (x, y) -> + @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 - minY: y-margin + minY: y-margin/4 maxX: x+margin+text.length - maxY: y+margin + maxY: y+margin/4 diff --git a/src/Renderer.coffee b/src/Renderer.coffee index 79ee5c5..d0e73d8 100644 --- a/src/Renderer.coffee +++ b/src/Renderer.coffee @@ -100,6 +100,10 @@ module.exports = class Renderer @isDrawing = false + featuresAt: (x, y) -> + @labelBuffer.featuresAt x, y + + _write: (output) -> process.stdout.write output @@ -165,9 +169,9 @@ module.exports = class Renderer x = point[0] - text.length 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 - 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 _scaleAndReduce: (points, scale) -> diff --git a/src/Termap.coffee b/src/Termap.coffee index 029ae78..d9dfee1 100644 --- a/src/Termap.coffee +++ b/src/Termap.coffee @@ -97,8 +97,10 @@ module.exports = class Termap else @mouseDragging = x: event.x, y: event.y - # update internal mouse tracker - @mousePosition = x: event.x, y: event.y + # update internal mouse tracker + @mousePosition = x: event.x, y: event.y + @renderer.notify @_getFooter() + _onKey: (key) -> # 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]) _getFooter: -> - #{}"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(', ')}]" - #{}"#{@mouseDragging.x} #{@mouseDragging.y} #{@mousePosition.x} #{@mousePosition.y}" + features = @renderer.featuresAt @mousePosition.x-1-(@view[0]>>1), @mousePosition.y-1-(@view[1]>>2) + "features: ["+features.map((f) -> f.feature.id).join(", ")+"] "+ + "#{@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) -> return @zoom = 0 if @zoom+step < 0 diff --git a/tiles/berlin.z12.pbf.gz b/tiles/berlin.z12.pbf.gz new file mode 100644 index 0000000..b279ef3 Binary files /dev/null and b/tiles/berlin.z12.pbf.gz differ