Ignore zoom for the filtered field when the value is the default one.

This commit is contained in:
IagoLast 2017-08-21 16:32:54 +02:00
parent daafa9fbf2
commit d35e54859a
2 changed files with 20 additions and 4 deletions

View File

@ -209,12 +209,14 @@ tree.Definition.prototype.toXML = function(env, existing) {
}; };
tree.Definition.prototype.toJS = function(env) { tree.Definition.prototype.toJS = function(env) {
var DEFAULT_ZOOM_VALUE = 8388607;
var shaderAttrs = {}; var shaderAttrs = {};
var frame_offset = this.frame_offset; var frame_offset = this.frame_offset;
var zoomFilter = "(" + this.zoom + " & (1 << ctx.zoom))"; var zoomFilter = "(" + this.zoom + " & (1 << ctx.zoom))";
var filters = [zoomFilter]; var filters = [zoomFilter];
var originalFilters = this.filters.toJS(env); var originalFilters = this.filters.toJS(env);
// Ignore default zoom for filtering (https://github.com/CartoDB/carto/issues/40)
var zoomFiltered = this.zoom !== DEFAULT_ZOOM_VALUE;
if (originalFilters) { if (originalFilters) {
filters.push(originalFilters); filters.push(originalFilters);
@ -235,8 +237,7 @@ tree.Definition.prototype.toJS = function(env) {
exportedRule.symbolizer = rule.symbolizer; exportedRule.symbolizer = rule.symbolizer;
exportedRule.js = "if(" + filters.join(" && ") + "){" + rule.value.toJS(env) + "}"; exportedRule.js = "if(" + filters.join(" && ") + "){" + rule.value.toJS(env) + "}";
exportedRule.constant = rule.value.ev(env).is !== 'field'; exportedRule.constant = rule.value.ev(env).is !== 'field';
exportedRule.filtered = originalFilters !== ''; exportedRule.filtered = zoomFiltered || (originalFilters !== '');
shaderAttrs[rule.name] = shaderAttrs[rule.name] || []; shaderAttrs[rule.name] = shaderAttrs[rule.name] || [];
shaderAttrs[rule.name].push(exportedRule); shaderAttrs[rule.name].push(exportedRule);
}); });

View File

@ -15,13 +15,15 @@
* marker-color: red; // * marker-color: red; //
* } * }
* } * }
*
* "zoom" is a special case, and it only should be considered when it's value is not the default.
*/ */
var assert = require('assert'); var assert = require('assert');
var Carto = require('../lib/carto/index.js'); var Carto = require('../lib/carto/index.js');
var renderer = new Carto.RendererJS({ strict: true }); var renderer = new Carto.RendererJS({ strict: true });
describe('Field:filtered propery', function () { describe('property.filtered', function () {
it('should be false when the property is not filtered', function () { it('should be false when the property is not filtered', function () {
var style = [ var style = [
'#layer {', '#layer {',
@ -85,4 +87,17 @@ describe('Field:filtered propery', function () {
assert(layers['marker-fill'].filtered); assert(layers['marker-fill'].filtered);
}); });
it('should be true when filtering by zoom', function () {
var style = [
'#layer {',
' [zoom < 5]{',
' marker-fill: blue;',
' }',
'}`'
].join('\n');
var layers = renderer.render(style).layers[0].shader;
assert(layers['marker-fill'].filtered);
});
}); });