From 4ae431718b27a57074419246e39101c16ed55409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Stra=C3=9Fburger?= Date: Wed, 21 Sep 2016 05:41:47 +0200 Subject: [PATCH] :art: adding $type to props to allow filters matching it --- README.md | 4 ---- src/Styler.coffee | 12 ++++++------ termap.coffee | 13 ++++++++++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 9d4365b..34b59c2 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,6 @@ No web browser around? No worries - discover the planet in your console! * [`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](http://spatialreference.org/ref/sr-org/6864/) <> [WGS84](http://spatialreference.org/ref/epsg/wgs-84/) conversions -## Wishlist - -* node port of [libdrawille](https://github.com/Huulivoide/libdrawille) - well optimized library, supporting filled polygons - ### TODOs * [ ] cli linking * [ ] mapping of view to tiles to show diff --git a/src/Styler.coffee b/src/Styler.coffee index 214c8a8..166fcf5 100644 --- a/src/Styler.coffee +++ b/src/Styler.coffee @@ -33,9 +33,9 @@ module.exports = class Styler false _passesFilter: (feature, filter) -> - switch filter.shift() + switch filter[0] when "all" - for subFilter in filter + for subFilter in filter[1..] return false unless @_passesFilter feature, subFilter true @@ -46,14 +46,14 @@ module.exports = class Styler feature.properties[filter[0]] isnt filter[1] when "in" - field = filter.shift() - for value in filter + field = filter[1] + for value in filter[2..] return true if feature.properties[field] is value false when "!in" - field = filter.shift() - for value in filter + field = filter[1] + for value in filter[2..] return false if feature.properties[field] is value true diff --git a/termap.coffee b/termap.coffee index 1a4e5d7..9bb40f0 100644 --- a/termap.coffee +++ b/termap.coffee @@ -21,6 +21,9 @@ utils = angle / Math.PI * 180 hex2rgb: (color) -> + if not color.match + console.log color + process.exit() return [255, 0, 0] unless color?.match unless color.match /^#[a-fA-F0-9]{3,6}$/ @@ -207,10 +210,14 @@ class Termap features[name] = for i in [0...layer.length] feature = layer.feature i + type = [undefined, "Point", "LineString", "Polygon"][feature.type] + + properties = feature.properties + properties.$type = type - type: [undefined, "Point", "LineString", "Polygon"][feature.type] id: feature.id - properties: feature.properties + type: type + properties: properties points: feature.loadGeometry() features @@ -276,7 +283,7 @@ class Termap continue unless visible toDraw.push projectedPoints - if style = @styler.getStyleFor layer, feature, 8 + if style = @styler.getStyleFor layer, feature, 14 color = style.paint['line-color'] or style.paint['fill-color'] # TODO: zoom calculation todo for perfect styling