🔍 adapting label decluttering to centered labels

pull/7/head
Michael Straßburger 2016-09-21 17:35:16 +02:00
rodzic d3e2961184
commit 1effed33d9
4 zmienionych plików z 38 dodań i 5 usunięć

Wyświetl plik

@ -38,8 +38,9 @@ No web browser around? No worries - discover the planet in your console!
* [`vector-tile-js`](https://github.com/mapbox/vector-tile-js) for [VectorTile](https://github.com/mapbox/vector-tile-spec/tree/master/2.1) parsing
#### Juggling the vectors and numbers
* [`pnltri`](https://github.com/jahting/pnltri.js) for polygon triangulation to draw them filled
* [`pnltri`](https://github.com/jahting/pnltri.js) for polygon triangulation to draw 'em filled
* [`rbush`](https://github.com/mourner/rbush) for 2D spatial indexing based label and mouse collision detection
* [`gl-matrix`](https://github.com/toji/gl-matrix) for vector and matrix operations
* [`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
@ -51,12 +52,14 @@ No web browser around? No worries - discover the planet in your console!
* [x] support for point labels
* [x] dynamic decluttering of labels
* [x] centering text labels
* [ ] clipping fix when x<0 after repositioning
* [ ] multi line label
* [ ] label margin to avoid POI overlap?
* [ ] translatable raster fonts
* [x] filled polygons
* [x] convert polygons to triangles
* [x] implement fillTriangle into drawille-canvas-blessed-contrib
* [ ] respect fill/line style file based setting
* [ ] lat/lng-center + zoom based viewport
* [ ] bbox awareness
* [ ] zoom -> scale calculation

Wyświetl plik

@ -22,6 +22,7 @@
"dependencies": {
"coffee-script": "^1.10.0",
"drawille-canvas-blessed-contrib": "git+https://github.com/rastapasta/drawille-canvas-blessed-contrib.git",
"gl-matrix": "^2.3.2",
"keypress": "^0.2.1",
"pbf": "^3.0.0",
"pnltri": "^2.1.1",

Wyświetl plik

@ -7,7 +7,35 @@
###
BlessedCanvas = require 'drawille-canvas-blessed-contrib'
vec2 = require('gl-matrix').vec2
module.exports = class Canvas extends BlessedCanvas
fillText: (text, x, y, size=1) ->
super text, x-text.length, y
# bresenham: (from, to) ->
# points = []
# adx = Math.abs dx = to.x - from.x
# ady = Math.abs dy = to.y - from.y
# eps = 0
# sx = if dx > 0 then 1 else -1
# sy = if dy > 0 then 1 else -1
#
# [x, y] = from
# if adx > ady
# while if sx < 0 then x >= x1 else x <= x1
# points.add x:, y: y
# eps += ady
# if eps<<1 >= adx
# y += sy
# eps -= adx
#
# x += sx
# else
# while if sy < 0 then y >= y1 else y <= y1
# fn(x, y);
# eps += adx;
# if eps<<1 >= ady
# x += sx;
# eps -= ady;
#
# y += sy
# arr

Wyświetl plik

@ -296,8 +296,9 @@ class Termap
# TODO: check in definition if points can actually own multiple geometries
for points in toDraw
for point in points
if @labelBuffer.writeIfPossible text, point.x, point.y
@canvas.fillText text, point.x, point.y
x = point.x - text.length
if @labelBuffer.writeIfPossible text, x, point.y
@canvas.fillText text, x, point.y
wasDrawn = true
wasDrawn