Update results for temporary image-transform renaming, update

reference to mapnik-reference to point to the transforms branch,
prep a changelog message
This commit is contained in:
Tom MacWright 2012-06-22 18:06:15 -04:00
parent a941bda795
commit 265554813b
6 changed files with 57 additions and 15 deletions

View File

@ -1,5 +1,9 @@
## Changelog
### 0.8.0
* Supports function syntax for transforms, optionally with variables and arguments.
### 0.7.0
* Support an `opacity` property on any style that is a style-level property

View File

@ -1,8 +1,5 @@
(function(tree) {
//
// A function call node.
//
tree.Call = function Call(name, args, index) {
this.is = 'call';
@ -53,26 +50,49 @@ tree.Call.prototype = {
};
}
} else {
return this;
// return new tree.Anonymous(this.name +
// '(' + args.map(function(a) { return a.toString(); }).join(', ') + ')');
var fn = tree.Reference.mapnikFunction(this.name);
if (!fn) {
env.error({
message: 'unknown function ' + this.name,
index: this.index,
type: 'runtime',
filename: this.filename
});
return {
is: 'undefined',
value: 'undefined'
};
}
if (fn[1] !== args.length) {
env.error({
message: 'function ' + this.name + ' takes ' +
fn[1] + ' arguments and was given ' + args.length,
index: this.index,
type: 'runtime',
filename: this.filename
});
return {
is: 'undefined',
value: 'undefined'
};
} else {
// Save the evaluated versions of arguments
this.args = args;
return this;
}
}
},
toString: function(env, format) {
if (format === 'image-filter') {
if (this.args.length) {
return this.name + ':' + this.args.map(function(a) {
return a.eval(env);
}).join(',');
return this.name + ':' + this.args.join(',');
} else {
return this.name;
}
} else {
if (this.args.length) {
return this.name + '(' + this.args.map(function(a) {
return a.eval(env);
}).join(',') + ')';
return this.name + '(' + this.args.join(',') + ')';
} else {
return this.name;
}

View File

@ -65,6 +65,24 @@ tree.Reference.symbolizer = function(selector) {
}
};
/*
* For transform properties and image-filters,
* mapnik has its own functions.
*/
tree.Reference.mapnikFunction = function(name) {
var functions = [];
for (var i in tree.Reference.data.symbolizers) {
for (var j in tree.Reference.data.symbolizers[i]) {
if (tree.Reference.data.symbolizers[i][j].type === 'functions') {
functions = functions.concat(tree.Reference.data.symbolizers[i][j].functions);
}
}
}
return _.find(functions, function(f) {
return f[0] === name;
});
};
tree.Reference.requiredPropertyList = function(symbolizer_name) {
if (this.required_prop_list_cache[symbolizer_name]) {
return this.required_prop_list_cache[symbolizer_name];

View File

@ -36,7 +36,7 @@
},
"dependencies": {
"underscore": "~1.3.3",
"mapnik-reference": "~2.1.0",
"mapnik-reference": "https://github.com/mapnik/mapnik-reference/zipball/transform-functions",
"xml2js": "~0.1.13"
},
"devDependencies": {

View File

@ -5,7 +5,7 @@
<Style name="world" filter-mode="first" >
<Rule>
<PointSymbolizer file="foo.png" transform="translate(4,2)" />
<PointSymbolizer file="foo.png" image-transform="translate(4,2)" />
</Rule>
</Style>
<Layer name="world"

View File

@ -5,7 +5,7 @@
<Style name="world" filter-mode="first" >
<Rule>
<PointSymbolizer file="foo.png" transform="translate(2, 2)" />
<PointSymbolizer file="foo.png" image-transform="translate(2, 2)" />
</Rule>
</Style>
<Layer name="world"