diff --git a/src/BrailleBuffer.coffee b/src/BrailleBuffer.coffee index 64ecc3b..b15757e 100644 --- a/src/BrailleBuffer.coffee +++ b/src/BrailleBuffer.coffee @@ -34,7 +34,9 @@ module.exports = class BrailleBuffer @foregroundBuffer = [] @backgroundBuffer = [] - setBackground: (idx, color) -> + setBackground: (x, y, color) -> + return unless 0 <= x < @width and 0 <= y < @height + idx = @_project x, y @backgroundBuffer[idx] = color setPixel: (x, y, color) -> diff --git a/src/Canvas.coffee b/src/Canvas.coffee index fc0724f..4b18e2f 100644 --- a/src/Canvas.coffee +++ b/src/Canvas.coffee @@ -49,6 +49,10 @@ module.exports = class Canvas bresenham projected[i-1]..., projected[i]..., (x, y) => @buffer.setPixel x, y, color + background: (x, y, color) -> + point = @_project x, y + @buffer.setBackground point[0], point[1], color + # TODO: support for polygon holes polygon: (points, color) -> vertices = [] diff --git a/src/Renderer.coffee b/src/Renderer.coffee index fa6a5d6..ded6a40 100644 --- a/src/Renderer.coffee +++ b/src/Renderer.coffee @@ -19,7 +19,7 @@ module.exports = class Renderer labelMargin: 5 #"poi_label", "water", - drawOrder: ["admin", "building", "road", "place_label", "poi_label", "housenum_label"] + drawOrder: ["water", "admin", "building", "road", "place_label", "poi_label", "housenum_label"] icons: car: "🚗" @@ -109,9 +109,11 @@ module.exports = class Renderer features = @features[layer].tree.search box @notify "rendering #{features.length} #{layer} features.." for feature in features - @_drawFeature layer, feature.data, scale + @_drawFeature layer, feature, scale + + _drawFeature: (layer, data, scale) -> + feature = data.data - _drawFeature: (layer, feature, scale) -> # TODO: this is ugly :) need to be fixed @style #return false if feature.properties.class is "ferry" feature.type = "LineString" if layer is "building" or layer is "road" @@ -137,6 +139,11 @@ module.exports = class Renderer when "Polygon" @canvas.polygon toDraw[0], colorCode + # points = toDraw[0] + # for y in [Math.max(0,Math.floor(data.minY/scale))..Math.min(@height, Math.floor(data.maxY/scale))] by 4 + # for x in [Math.max(0, Math.floor(data.minX/scale))..Math.min(@width, Math.floor(data.maxX/scale))] by 2 + # if utils.pointInPolygon points, [x, y] + # @canvas.background x, y, colorCode when "Point" text = feature.properties["name_"+@config.language] or diff --git a/src/utils.coffee b/src/utils.coffee index 31dcabe..b34c33b 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -16,6 +16,7 @@ utils = point[0] < (polygon[j][0]-polygon[i][0]) * (point[1]-polygon[i][1]) / (polygon[j][1]-polygon[i][1]) + polygon[i][0] inside = !inside j = i + inside deg2rad: (angle) -> # (angle / 180) * Math.PI