Support mapnik keywords in filters and error on bare keywords. Fixes
This commit is contained in:
parent
b7773c6452
commit
c1e8c3b8f3
@ -557,6 +557,7 @@ carto.Parser = function Parser(env) {
|
||||
if (key = $(/^[a-zA-Z0-9\-_]+/) ||
|
||||
$(this.entities.quoted) ||
|
||||
$(this.entities.variable) ||
|
||||
$(this.entities.keyword) ||
|
||||
$(this.entities.field)) {
|
||||
// TODO: remove at 1.0.0
|
||||
if (key instanceof tree.Quoted) {
|
||||
@ -566,6 +567,7 @@ carto.Parser = function Parser(env) {
|
||||
(val = $(this.entities.quoted) ||
|
||||
$(this.entities.variable) ||
|
||||
$(this.entities.dimension) ||
|
||||
$(this.entities.keyword) ||
|
||||
$(this.entities.field))) {
|
||||
if (! $(']')) return;
|
||||
if (!key.is) key = new tree.Field(key);
|
||||
|
@ -28,6 +28,22 @@ tree.Filter.prototype['eval'] = function(env) {
|
||||
};
|
||||
|
||||
tree.Filter.prototype.toXML = function(env) {
|
||||
if (tree.Reference.data.filter) {
|
||||
if (this.key.is === 'keyword' && -1 === tree.Reference.data.filter.value.indexOf(this.key.toString())) {
|
||||
env.error({
|
||||
message: this.key.toString() + ' is not a valid keyword in a filter expression',
|
||||
index: this.index,
|
||||
filename: this.filename
|
||||
});
|
||||
}
|
||||
if (this.val.is === 'keyword' && -1 === tree.Reference.data.filter.value.indexOf(this.val.toString())) {
|
||||
env.error({
|
||||
message: this.val.toString() + ' is not a valid keyword in a filter expression',
|
||||
index: this.index,
|
||||
filename: this.filename
|
||||
});
|
||||
}
|
||||
}
|
||||
var key = this.key.toString(false);
|
||||
var val = this.val.toString(this.val.is == 'string');
|
||||
|
||||
|
@ -36,7 +36,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"underscore": "~1.4.3",
|
||||
"mapnik-reference": "~5.0.0",
|
||||
"mapnik-reference": "~5.0.3",
|
||||
"xml2js": "~0.1.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
14
test/errorhandling/mapnik_keyword.mml
Normal file
14
test/errorhandling/mapnik_keyword.mml
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"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": [
|
||||
"mapnik_keyword.mss"
|
||||
],
|
||||
"Layer": [{
|
||||
"name": "world",
|
||||
"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"
|
||||
}
|
||||
}]
|
||||
}
|
3
test/errorhandling/mapnik_keyword.mss
Normal file
3
test/errorhandling/mapnik_keyword.mss
Normal file
@ -0,0 +1,3 @@
|
||||
#world[[FOO]=nul] {
|
||||
line-width:2;
|
||||
}
|
1
test/errorhandling/mapnik_keyword.result
Normal file
1
test/errorhandling/mapnik_keyword.result
Normal file
@ -0,0 +1 @@
|
||||
mapnik_keyword.mss:1:6 nul is not a valid keyword in a filter expression
|
14
test/rendering/mapnik_keyword.mml
Normal file
14
test/rendering/mapnik_keyword.mml
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"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": [
|
||||
"mapnik_keyword.mss"
|
||||
],
|
||||
"Layer": [{
|
||||
"name": "world",
|
||||
"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"
|
||||
}
|
||||
}]
|
||||
}
|
3
test/rendering/mapnik_keyword.mss
Normal file
3
test/rendering/mapnik_keyword.mss
Normal file
@ -0,0 +1,3 @@
|
||||
#world[[FOO]=null] {
|
||||
line-width:2;
|
||||
}
|
21
test/rendering/mapnik_keyword.result
Normal file
21
test/rendering/mapnik_keyword.result
Normal file
@ -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="world" filter-mode="first" >
|
||||
<Rule>
|
||||
<Filter>([FOO] = null)</Filter>
|
||||
<LineSymbolizer stroke-width="2" />
|
||||
</Rule>
|
||||
</Style>
|
||||
<Layer name="world"
|
||||
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>world</StyleName>
|
||||
<Datasource>
|
||||
<Parameter name="file"><![CDATA[[absolute path]]]></Parameter>
|
||||
<Parameter name="type"><![CDATA[shape]]></Parameter>
|
||||
</Datasource>
|
||||
</Layer>
|
||||
|
||||
</Map>
|
Loading…
Reference in New Issue
Block a user