🎨 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
* [`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

View File

@ -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

View File

@ -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