Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Simplify filter system, support numeric variables in filters

  • Loading branch information...
commit 9eee9074678f60f62ff1af1bf433bc9213d079d1 1 parent 8603799
@tmcw tmcw authored
View
4 Makefile
@@ -3,7 +3,6 @@
#
expresso = ./node_modules/.bin/mocha
-docco = ./node_modules/.bin/docco
lint:
./node_modules/.bin/jshint lib/carto/*.js lib/carto/tree/*.js
@@ -18,7 +17,4 @@ endif
check: test
-doc:
- $(docco) lib/carto/*.js lib/carto/tree/*.js
-
.PHONY: test
View
5 lib/carto/parser.js
@@ -662,10 +662,11 @@ carto.Parser = function Parser(env) {
save();
var key, op, val;
if (! $('[')) return;
- if (key = $(/^[a-zA-Z0-9\-_]+/) || $(this.entities.quoted) || $(this.entities.variable)) {
+ if (key = $(/^[a-zA-Z0-9\-_]+/) || $(this.entities.quoted) || $(this.entities.variable) || $(this.entities.field)) {
if ((op = $(this.entities.comparison)) &&
- (val = $(this.entities.quoted) || $(this.entities.variable) || $(/^[\w\-\.]+/))) {
+ (val = $(this.entities.quoted) || $(this.entities.variable) || $(this.entities.dimension))) {
if (! $(']')) return;
+ if (!key.is) key = new tree.Field(key);
return new tree.Filter(key, op, val, memo, env.filename);
}
}
View
35 lib/carto/tree/filter.js
@@ -1,28 +1,12 @@
(function(tree) {
tree.Filter = function Filter(key, op, val, index, filename) {
- if (key.is) {
- this.key = key.value;
- this._key = key;
- } else {
- this.key = key;
- }
-
+ this.key = key;
this.op = op;
+ this.val = val;
this.index = index;
this.filename = filename;
- if (val.is) {
- this.val = val.value;
- this._val = val;
- } else {
- this.val = val;
- }
-
- if (ops[this.op][1] == 'numeric') {
- this.val = 1 * this.val;
- }
-
this.id = this.key + this.op + this.val;
};
@@ -39,15 +23,14 @@ var ops = {
};
tree.Filter.prototype.toXML = function(env) {
- var val, key;
- if (this.val['eval']) this._val = this.val['eval'](env);
- if (this.key['eval']) this._key = this.key['eval'](env);
- if (this._key) key = this._key.toString(false);
- if (this._val) val = this._val.toString(this._val.is == 'string');
+ var key = this.key['eval'](env);
+ var val = this.val['eval'](env);
+ key = key.toString(false);
+ val = val.toString(val.is == 'string');
if (
- (ops[this.op][1] == 'numeric' && isNaN(this.val)) ||
- (ops[this.op][1] == 'string' && (val || this.val)[0] != "'")
+ (ops[this.op][1] == 'numeric' && isNaN(val)) ||
+ (ops[this.op][1] == 'string' && (val)[0] != "'")
) {
env.error({
message: 'Cannot use operator "' + this.op + '" with value ' + this.val,
@@ -56,7 +39,7 @@ tree.Filter.prototype.toXML = function(env) {
});
}
- return '[' + (key || this.key) + ']' + ops[this.op][0] + '' + (val || this.val) + (ops[this.op][2] || '');
+ return key + ops[this.op][0] + '' + val + (ops[this.op][2] || '');
};
tree.Filter.prototype.toString = function() {
View
4 lib/carto/tree/variable.js
@@ -7,6 +7,10 @@ tree.Variable = function Variable(name, index, filename) {
};
tree.Variable.prototype = {
+ is: 'variable',
+ toString: function() {
+ return this.name;
+ },
eval: function(env) {
var variable,
v,
View
1  package.json
@@ -42,7 +42,6 @@
},
"devDependencies": {
"mocha": "1.3.x",
- "docco": "0.3.x",
"jshint": "0.2.x",
"sax": "0.1.x"
},
View
15 test/rendering/support4504.mml
@@ -0,0 +1,15 @@
+{
+ "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",
+ "Stylesheet": [
+ "support4504.mss"
+ ],
+ "Layer": [{
+ "class": "new",
+ "name": "countries",
+ "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",
+ "Datasource": {
+ "file": "http://tilemill-data.s3.amazonaws.com/test_data/shape_demo.zip",
+ "type": "shape"
+ }
+ }]
+}
View
7 test/rendering/support4504.mss
@@ -0,0 +1,7 @@
+@z13: 19;
+@num_pixels: 50;
+@z13area: @z13 * @z13 * @num_pixels;
+
+#countries[way_area > @z13area] {
+ polygon-opacity:0.2;
+}
View
21 test/rendering/support4504.result
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE Map[]>
+<Map srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over" maximum-extent="-20037508.34,-20037508.34,20037508.34,20037508.34">
+
+
+<Style name="countries" filter-mode="first" >
+ <Rule>
+ <Filter>([way_area] &gt; 18050)</Filter>
+ <PolygonSymbolizer fill-opacity="0.2" />
+ </Rule>
+</Style>
+<Layer name="countries"
+ srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
+ <StyleName>countries</StyleName>
+ <Datasource>
+ <Parameter name="file"><![CDATA[[absolute path]]]></Parameter>
+ <Parameter name="type"><![CDATA[shape]]></Parameter>
+ </Datasource>
+ </Layer>
+
+</Map>
Please sign in to comment.
Something went wrong with that request. Please try again.