Boy scout rule

This commit is contained in:
IagoLast 2017-08-18 15:59:04 +02:00
parent 41133a65ad
commit 34799db0cc

View File

@ -210,47 +210,37 @@ tree.Definition.prototype.toXML = function(env, existing) {
tree.Definition.prototype.toJS = function(env) { tree.Definition.prototype.toJS = function(env) {
var shaderAttrs = {}; var shaderAttrs = {};
// merge conditions from filters with zoom condition of the
// definition
var zoom = "(" + this.zoom + " & (1 << ctx.zoom))";
var frame_offset = this.frame_offset; var frame_offset = this.frame_offset;
var _if = this.filters.toJS(env); var zoomFilter = "(" + this.zoom + " & (1 << ctx.zoom))";
var filtered = _if !== ''; var filters = [zoomFilter];
var filters = [zoom]; var originalFilters = this.filters.toJS(env);
if(_if) {
filters.push(_if); if (originalFilters) {
filters.push(originalFilters);
} }
if (frame_offset) { if (frame_offset) {
filters.push('ctx["frame-offset"] === ' + frame_offset); filters.push('ctx["frame-offset"] === ' + frame_offset);
} }
_if = filters.join(" && ");
_.each(this.rules, function (rule) { _.each(this.rules, function (rule) {
if(rule instanceof tree.Rule) { var exportedRule = {};
shaderAttrs[rule.name] = shaderAttrs[rule.name] || [];
var r = { if (!rule instanceof tree.Rule) {
index: rule.index,
symbolizer: rule.symbolizer
};
if (_if) {
r.js = "if(" + _if + "){" + rule.value.toJS(env) + "}";
} else {
r.js = rule.value.toJS(env);
}
r.constant = rule.value.ev(env).is !== 'field';
r.filtered = filtered;
shaderAttrs[rule.name].push(r);
} else {
throw new Error("Ruleset not supported"); throw new Error("Ruleset not supported");
} }
exportedRule.index = rule.index;
exportedRule.symbolizer = rule.symbolizer;
exportedRule.js = "if(" + filters.join(" && ") + "){" + rule.value.toJS(env) + "}";
exportedRule.constant = rule.value.ev(env).is !== 'field';
exportedRule.filtered = originalFilters !== '';
shaderAttrs[rule.name] = shaderAttrs[rule.name] || [];
shaderAttrs[rule.name].push(exportedRule);
}); });
return shaderAttrs; return shaderAttrs;
}; };