Refactor filtered field code
This commit is contained in:
parent
72f93abf16
commit
1016f6870c
@ -216,10 +216,19 @@ tree.Definition.prototype.toJS = function(env) {
|
||||
var zoom = "(" + this.zoom + " & (1 << ctx.zoom))";
|
||||
var frame_offset = this.frame_offset;
|
||||
var _if = this.filters.toJS(env);
|
||||
var filtered = _if !== '';
|
||||
var filters = [zoom];
|
||||
if(_if) filters.push(_if);
|
||||
if(frame_offset) filters.push('ctx["frame-offset"] === ' + frame_offset);
|
||||
|
||||
if(_if) {
|
||||
filters.push(_if);
|
||||
}
|
||||
|
||||
if(frame_offset){
|
||||
filters.push('ctx["frame-offset"] === ' + frame_offset);
|
||||
}
|
||||
|
||||
_if = filters.join(" && ");
|
||||
|
||||
_.each(this.rules, function(rule) {
|
||||
if(rule instanceof tree.Rule) {
|
||||
shaderAttrs[rule.name] = shaderAttrs[rule.name] || [];
|
||||
@ -230,30 +239,16 @@ tree.Definition.prototype.toJS = function(env) {
|
||||
};
|
||||
|
||||
if (_if) {
|
||||
r.js = "if(" + _if + "){" + rule.value.toJS(env) + "}"
|
||||
r.js = "if(" + _if + "){" + rule.value.toJS(env) + "}";
|
||||
} else {
|
||||
r.js = rule.value.toJS(env);
|
||||
}
|
||||
|
||||
r.constant = rule.value.ev(env).is !== 'field';
|
||||
var DEFAULT_FILTER = "(8388607 & (1 << ctx.zoom))";
|
||||
r.filtered = false;
|
||||
if (_if && _if !== DEFAULT_FILTER){
|
||||
r.filtered = true;
|
||||
}
|
||||
|
||||
r.filtered = filtered;
|
||||
shaderAttrs[rule.name].push(r);
|
||||
} else {
|
||||
throw new Error("Ruleset not supported");
|
||||
//if (rule instanceof tree.Ruleset) {
|
||||
//var sh = rule.toJS(env);
|
||||
//for(var v in sh) {
|
||||
//shaderAttrs[v] = shaderAttrs[v] || [];
|
||||
//for(var attr in sh[v]) {
|
||||
//shaderAttrs[v].push(sh[v][attr]);
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
}
|
||||
});
|
||||
return shaderAttrs;
|
||||
|
Loading…
Reference in New Issue
Block a user