🎨 adding $type to props to allow filters matching it

This commit is contained in:
Michael Straßburger 2016-09-21 05:41:47 +02:00
parent 1afd8ec9c2
commit 4ae431718b
3 changed files with 16 additions and 13 deletions

View File

@ -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 * [`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 * [`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 ### TODOs
* [ ] cli linking * [ ] cli linking
* [ ] mapping of view to tiles to show * [ ] mapping of view to tiles to show

View File

@ -33,9 +33,9 @@ module.exports = class Styler
false false
_passesFilter: (feature, filter) -> _passesFilter: (feature, filter) ->
switch filter.shift() switch filter[0]
when "all" when "all"
for subFilter in filter for subFilter in filter[1..]
return false unless @_passesFilter feature, subFilter return false unless @_passesFilter feature, subFilter
true true
@ -46,14 +46,14 @@ module.exports = class Styler
feature.properties[filter[0]] isnt filter[1] feature.properties[filter[0]] isnt filter[1]
when "in" when "in"
field = filter.shift() field = filter[1]
for value in filter for value in filter[2..]
return true if feature.properties[field] is value return true if feature.properties[field] is value
false false
when "!in" when "!in"
field = filter.shift() field = filter[1]
for value in filter for value in filter[2..]
return false if feature.properties[field] is value return false if feature.properties[field] is value
true true

View File

@ -21,6 +21,9 @@ utils =
angle / Math.PI * 180 angle / Math.PI * 180
hex2rgb: (color) -> hex2rgb: (color) ->
if not color.match
console.log color
process.exit()
return [255, 0, 0] unless color?.match return [255, 0, 0] unless color?.match
unless color.match /^#[a-fA-F0-9]{3,6}$/ unless color.match /^#[a-fA-F0-9]{3,6}$/
@ -207,10 +210,14 @@ class Termap
features[name] = for i in [0...layer.length] features[name] = for i in [0...layer.length]
feature = layer.feature i 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 id: feature.id
properties: feature.properties type: type
properties: properties
points: feature.loadGeometry() points: feature.loadGeometry()
features features
@ -276,7 +283,7 @@ class Termap
continue unless visible continue unless visible
toDraw.push projectedPoints 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'] color = style.paint['line-color'] or style.paint['fill-color']
# TODO: zoom calculation todo for perfect styling # TODO: zoom calculation todo for perfect styling