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 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 _if = this.filters.toJS(env);
|
||||||
|
var filtered = _if !== '';
|
||||||
var filters = [zoom];
|
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(" && ");
|
_if = filters.join(" && ");
|
||||||
|
|
||||||
_.each(this.rules, function(rule) {
|
_.each(this.rules, function(rule) {
|
||||||
if(rule instanceof tree.Rule) {
|
if(rule instanceof tree.Rule) {
|
||||||
shaderAttrs[rule.name] = shaderAttrs[rule.name] || [];
|
shaderAttrs[rule.name] = shaderAttrs[rule.name] || [];
|
||||||
@ -230,30 +239,16 @@ tree.Definition.prototype.toJS = function(env) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (_if) {
|
if (_if) {
|
||||||
r.js = "if(" + _if + "){" + rule.value.toJS(env) + "}"
|
r.js = "if(" + _if + "){" + rule.value.toJS(env) + "}";
|
||||||
} else {
|
} else {
|
||||||
r.js = rule.value.toJS(env);
|
r.js = rule.value.toJS(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
r.constant = rule.value.ev(env).is !== 'field';
|
r.constant = rule.value.ev(env).is !== 'field';
|
||||||
var DEFAULT_FILTER = "(8388607 & (1 << ctx.zoom))";
|
r.filtered = filtered;
|
||||||
r.filtered = false;
|
|
||||||
if (_if && _if !== DEFAULT_FILTER){
|
|
||||||
r.filtered = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
shaderAttrs[rule.name].push(r);
|
shaderAttrs[rule.name].push(r);
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Ruleset not supported");
|
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;
|
return shaderAttrs;
|
||||||
|
Loading…
Reference in New Issue
Block a user