@carto/airship-bridge
Version:
Airship bridge to other libs (CARTO VL, CARTO.js)
72 lines (71 loc) • 2.73 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { select } from '../../util/Utils';
import { BaseFilter } from '../base/BaseFilter';
/**
* Class that binds a CARTO VL between filter to an Airship range slider widget
*
* @export
* @class GlobalRangeFilter
* @extends {BaseFilter}
*/
var GlobalRangeFilter = /** @class */ (function (_super) {
__extends(GlobalRangeFilter, _super);
function GlobalRangeFilter(carto, layer, widget, columnName, source) {
var _this = _super.call(this, "global_range", carto, columnName, layer, source, false) || this;
_this._value = null;
_this._widget = select(widget);
_this._carto = carto;
_this._widget.addEventListener('change', function (event) {
_this._value = event.detail;
_this._filterChanged();
});
return _this;
}
GlobalRangeFilter.prototype.setDataLayer = function (layer) {
var _this = this;
this._dataLayer = layer;
this._dataLayer.on('updated', function () {
var data = _this._dataLayer.viz.variables[_this.name];
if (data && !_this._populated) {
_this._widget.minValue = data.value[0];
_this._widget.maxValue = data.value[1];
_this._widget.range = data.value;
_this._populated = true;
}
});
};
Object.defineProperty(GlobalRangeFilter.prototype, "filter", {
get: function () {
if (this._value === null) {
return null;
}
else {
return "@" + this.columnPropName + " > " + this._value[0] + " and @" + this.columnPropName + " < " + this._value[1];
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(GlobalRangeFilter.prototype, "expression", {
get: function () {
var s = this._carto.expressions;
return s.list([s.globalMin(s.prop(this._column)), s.globalMax(s.prop(this._column))]);
},
enumerable: true,
configurable: true
});
return GlobalRangeFilter;
}(BaseFilter));
export { GlobalRangeFilter };