Ignore zoom for the filtered field when the value is the default one.
This commit is contained in:
parent
daafa9fbf2
commit
d35e54859a
@ -209,12 +209,14 @@ tree.Definition.prototype.toXML = function(env, existing) {
|
||||
};
|
||||
|
||||
tree.Definition.prototype.toJS = function(env) {
|
||||
var DEFAULT_ZOOM_VALUE = 8388607;
|
||||
var shaderAttrs = {};
|
||||
var frame_offset = this.frame_offset;
|
||||
var zoomFilter = "(" + this.zoom + " & (1 << ctx.zoom))";
|
||||
var filters = [zoomFilter];
|
||||
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) {
|
||||
filters.push(originalFilters);
|
||||
@ -235,8 +237,7 @@ tree.Definition.prototype.toJS = function(env) {
|
||||
exportedRule.symbolizer = rule.symbolizer;
|
||||
exportedRule.js = "if(" + filters.join(" && ") + "){" + rule.value.toJS(env) + "}";
|
||||
exportedRule.constant = rule.value.ev(env).is !== 'field';
|
||||
exportedRule.filtered = originalFilters !== '';
|
||||
|
||||
exportedRule.filtered = zoomFiltered || (originalFilters !== '');
|
||||
shaderAttrs[rule.name] = shaderAttrs[rule.name] || [];
|
||||
shaderAttrs[rule.name].push(exportedRule);
|
||||
});
|
||||
|
@ -15,13 +15,15 @@
|
||||
* 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 Carto = require('../lib/carto/index.js');
|
||||
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 () {
|
||||
var style = [
|
||||
'#layer {',
|
||||
@ -85,4 +87,17 @@ describe('Field:filtered propery', function () {
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user