UNPKG

@deck.gl/layers

Version:
243 lines (218 loc) 8.5 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _core = require("@deck.gl/core"); var _core2 = require("@luma.gl/core"); var _scatterplotLayerVertex = _interopRequireDefault(require("./scatterplot-layer-vertex.glsl")); var _scatterplotLayerFragment = _interopRequireDefault(require("./scatterplot-layer-fragment.glsl")); function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } var DEFAULT_COLOR = [0, 0, 0, 255]; var defaultProps = { radiusUnits: 'meters', radiusScale: { type: 'number', min: 0, value: 1 }, radiusMinPixels: { type: 'number', min: 0, value: 0 }, radiusMaxPixels: { type: 'number', min: 0, value: Number.MAX_SAFE_INTEGER }, lineWidthUnits: 'meters', lineWidthScale: { type: 'number', min: 0, value: 1 }, lineWidthMinPixels: { type: 'number', min: 0, value: 0 }, lineWidthMaxPixels: { type: 'number', min: 0, value: Number.MAX_SAFE_INTEGER }, stroked: false, filled: true, billboard: false, antialiasing: true, getPosition: { type: 'accessor', value: function value(x) { return x.position; } }, getRadius: { type: 'accessor', value: 1 }, getFillColor: { type: 'accessor', value: DEFAULT_COLOR }, getLineColor: { type: 'accessor', value: DEFAULT_COLOR }, getLineWidth: { type: 'accessor', value: 1 }, strokeWidth: { deprecatedFor: 'getLineWidth' }, outline: { deprecatedFor: 'stroked' }, getColor: { deprecatedFor: ['getFillColor', 'getLineColor'] } }; var ScatterplotLayer = function (_Layer) { (0, _inherits2.default)(ScatterplotLayer, _Layer); var _super = _createSuper(ScatterplotLayer); function ScatterplotLayer() { (0, _classCallCheck2.default)(this, ScatterplotLayer); return _super.apply(this, arguments); } (0, _createClass2.default)(ScatterplotLayer, [{ key: "getShaders", value: function getShaders() { return (0, _get2.default)((0, _getPrototypeOf2.default)(ScatterplotLayer.prototype), "getShaders", this).call(this, { vs: _scatterplotLayerVertex.default, fs: _scatterplotLayerFragment.default, modules: [_core.project32, _core.picking] }); } }, { key: "initializeState", value: function initializeState() { this.getAttributeManager().addInstanced({ instancePositions: { size: 3, type: 5130, fp64: this.use64bitPositions(), transition: true, accessor: 'getPosition' }, instanceRadius: { size: 1, transition: true, accessor: 'getRadius', defaultValue: 1 }, instanceFillColors: { size: this.props.colorFormat.length, transition: true, normalized: true, type: 5121, accessor: 'getFillColor', defaultValue: [0, 0, 0, 255] }, instanceLineColors: { size: this.props.colorFormat.length, transition: true, normalized: true, type: 5121, accessor: 'getLineColor', defaultValue: [0, 0, 0, 255] }, instanceLineWidths: { size: 1, transition: true, accessor: 'getLineWidth', defaultValue: 1 } }); } }, { key: "updateState", value: function updateState(params) { (0, _get2.default)((0, _getPrototypeOf2.default)(ScatterplotLayer.prototype), "updateState", this).call(this, params); if (params.changeFlags.extensionsChanged) { var _this$state$model; var gl = this.context.gl; (_this$state$model = this.state.model) === null || _this$state$model === void 0 ? void 0 : _this$state$model.delete(); this.state.model = this._getModel(gl); this.getAttributeManager().invalidateAll(); } } }, { key: "draw", value: function draw(_ref) { var uniforms = _ref.uniforms; var _this$props = this.props, radiusUnits = _this$props.radiusUnits, radiusScale = _this$props.radiusScale, radiusMinPixels = _this$props.radiusMinPixels, radiusMaxPixels = _this$props.radiusMaxPixels, stroked = _this$props.stroked, filled = _this$props.filled, billboard = _this$props.billboard, antialiasing = _this$props.antialiasing, lineWidthUnits = _this$props.lineWidthUnits, lineWidthScale = _this$props.lineWidthScale, lineWidthMinPixels = _this$props.lineWidthMinPixels, lineWidthMaxPixels = _this$props.lineWidthMaxPixels; this.state.model.setUniforms(uniforms).setUniforms({ stroked: stroked ? 1 : 0, filled: filled, billboard: billboard, antialiasing: antialiasing, radiusUnits: _core.UNIT[radiusUnits], radiusScale: radiusScale, radiusMinPixels: radiusMinPixels, radiusMaxPixels: radiusMaxPixels, lineWidthUnits: _core.UNIT[lineWidthUnits], lineWidthScale: lineWidthScale, lineWidthMinPixels: lineWidthMinPixels, lineWidthMaxPixels: lineWidthMaxPixels }).draw(); } }, { key: "_getModel", value: function _getModel(gl) { var positions = [-1, -1, 0, 1, -1, 0, 1, 1, 0, -1, 1, 0]; return new _core2.Model(gl, _objectSpread(_objectSpread({}, this.getShaders()), {}, { id: this.props.id, geometry: new _core2.Geometry({ drawMode: 6, vertexCount: 4, attributes: { positions: { size: 3, value: new Float32Array(positions) } } }), isInstanced: true })); } }]); return ScatterplotLayer; }(_core.Layer); exports.default = ScatterplotLayer; (0, _defineProperty2.default)(ScatterplotLayer, "defaultProps", defaultProps); (0, _defineProperty2.default)(ScatterplotLayer, "layerName", 'ScatterplotLayer'); //# sourceMappingURL=scatterplot-layer.js.map