@deck.gl/experimental-layers
Version:
Experimental layers for deck.gl
235 lines (209 loc) • 9.87 kB
JavaScript
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import '@deck.gl/core';
import { CompositeLayer, _GPUGridAggregator as GPUGridAggregator, _pointToDensityGridData as pointToDensityGridData } from '@deck.gl/core';
import GPUGridCellLayer from './gpu-grid-cell-layer';
var MINCOLOR = [0, 0, 0, 255];
var MAXCOLOR = [0, 255, 0, 255];
var defaultProps = {
// elevation
elevationScale: {
type: 'number',
min: 0,
value: 1
},
// grid
cellSize: {
type: 'number',
min: 0,
max: 1000,
value: 1000
},
coverage: {
type: 'number',
min: 0,
max: 1,
value: 1
},
getPosition: {
type: 'accessor',
value: function value(x) {
return x.position;
}
},
extruded: false,
fp64: false,
pickable: false,
// TODO: Enable picking with GPU Aggregation
// Optional settings for 'lighting' shader module
lightSettings: {},
// GPU Aggregation
gpuAggregation: true
};
var GPUGridLayer =
/*#__PURE__*/
function (_CompositeLayer) {
_inherits(GPUGridLayer, _CompositeLayer);
function GPUGridLayer() {
_classCallCheck(this, GPUGridLayer);
return _possibleConstructorReturn(this, _getPrototypeOf(GPUGridLayer).apply(this, arguments));
}
_createClass(GPUGridLayer, [{
key: "initializeState",
value: function initializeState() {
var gl = this.context.gl;
var options = {
id: "".concat(this.id, "-gpu-aggregator"),
shaderCache: this.context.shaderCache
};
this.state = {
gpuGridAggregator: new GPUGridAggregator(gl, options)
};
}
}, {
key: "updateState",
value: function updateState(opts) {
var aggregationFlags = this.getAggregationFlags(opts);
if (aggregationFlags) {
// project data into grid cells
this.getLayerData(aggregationFlags);
}
}
}, {
key: "getAggregationFlags",
value: function getAggregationFlags(_ref) {
var oldProps = _ref.oldProps,
props = _ref.props,
changeFlags = _ref.changeFlags;
var aggregationFlags = null;
if (changeFlags.dataChanged || oldProps.gpuAggregation !== props.gpuAggregation || changeFlags.updateTriggersChanged && (changeFlags.updateTriggersChanged.all || changeFlags.updateTriggersChanged.getPosition)) {
aggregationFlags = Object.assign({}, aggregationFlags, {
dataChanged: true
});
}
if (oldProps.cellSize !== props.cellSize) {
aggregationFlags = Object.assign({}, aggregationFlags, {
cellSizeChanged: true
});
}
return aggregationFlags;
}
}, {
key: "getLayerData",
value: function getLayerData(aggregationFlags) {
var _this$props = this.props,
data = _this$props.data,
cellSizeMeters = _this$props.cellSize,
getPosition = _this$props.getPosition,
gpuAggregation = _this$props.gpuAggregation;
var _pointToDensityGridDa = pointToDensityGridData({
data: data,
cellSizeMeters: cellSizeMeters,
getPosition: getPosition,
gpuAggregation: gpuAggregation,
gpuGridAggregator: this.state.gpuGridAggregator,
boundingBox: this.state.boundingBox,
// avoid parsing data when it is not changed.
aggregationFlags: aggregationFlags
}),
countsBuffer = _pointToDensityGridDa.countsBuffer,
maxCountBuffer = _pointToDensityGridDa.maxCountBuffer,
gridSize = _pointToDensityGridDa.gridSize,
gridOrigin = _pointToDensityGridDa.gridOrigin,
cellSize = _pointToDensityGridDa.cellSize,
boundingBox = _pointToDensityGridDa.boundingBox;
this.setState({
countsBuffer: countsBuffer,
maxCountBuffer: maxCountBuffer,
gridSize: gridSize,
gridOrigin: gridOrigin,
cellSize: cellSize,
boundingBox: boundingBox
});
} // for subclassing, override this method to return
// customized sub layer props
}, {
key: "getSubLayerProps",
value: function getSubLayerProps() {
var _this$props2 = this.props,
elevationScale = _this$props2.elevationScale,
fp64 = _this$props2.fp64,
extruded = _this$props2.extruded,
cellSizeMeters = _this$props2.cellSize,
coverage = _this$props2.coverage,
lightSettings = _this$props2.lightSettings;
var _this$state = this.state,
countsBuffer = _this$state.countsBuffer,
maxCountBuffer = _this$state.maxCountBuffer,
gridSize = _this$state.gridSize,
gridOrigin = _this$state.gridOrigin,
cellSize = _this$state.cellSize;
var minColor = MINCOLOR;
var maxColor = MAXCOLOR; // return props to the sublayer constructor
return _get(_getPrototypeOf(GPUGridLayer.prototype), "getSubLayerProps", this).call(this, {
id: 'grid-cell',
data: this.state.layerData,
countsBuffer: countsBuffer,
maxCountBuffer: maxCountBuffer,
gridSize: gridSize,
gridOrigin: gridOrigin,
gridOffset: cellSize,
numInstances: gridSize[0] * gridSize[1],
minColor: minColor,
maxColor: maxColor,
fp64: fp64,
cellSize: cellSizeMeters,
coverage: coverage,
lightSettings: lightSettings,
elevationScale: elevationScale,
extruded: extruded,
pickable: false
});
} // for subclassing, override this method to return
// customized sub layer class
}, {
key: "getSubLayerClass",
value: function getSubLayerClass() {
return GPUGridCellLayer;
}
}, {
key: "renderLayers",
value: function renderLayers() {
var SubLayerClass = this.getSubLayerClass();
return new SubLayerClass(this.getSubLayerProps());
}
}]);
return GPUGridLayer;
}(CompositeLayer);
export { GPUGridLayer as default };
GPUGridLayer.layerName = 'GridLayer';
GPUGridLayer.defaultProps = defaultProps;
//# sourceMappingURL=gpu-grid-layer.js.map