kepler.gl
Version:
kepler.gl is a webgl based application to visualize large scale location data in the browser
80 lines (67 loc) • 11.9 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getStyle = getStyle;
exports.getEditHandleShape = getEditHandleShape;
exports.DEFAULT_RADIUS = exports.DEFAULT_STATE_STYLE_OPACITY = exports.RENDER_TYPE_STYLES = exports.STATE_STYLES_FILL = exports.DEFAULT_STATE_STYLE_FILL = exports.STATE_STYLES_STROKE = exports.DEFAULT_STATE_STYLE_STROKE = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _reactMapGlDraw = require("react-map-gl-draw");
var _constants = require("./constants");
var _lodash = _interopRequireDefault(require("lodash.get"));
var _STATE_STYLES_STROKE, _STATE_STYLES_FILL, _RENDER_TYPE_STYLES;
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; }
var DEFAULT_EDIT_HANDLE_SHAPE = 'circle';
var rectStyle = {
x: -6,
y: -6,
height: 12,
width: 12
};
var DEFAULT_STATE_STYLE_STROKE = _constants.COLORS.PRIMARY;
exports.DEFAULT_STATE_STYLE_STROKE = DEFAULT_STATE_STYLE_STROKE;
var STATE_STYLES_STROKE = (_STATE_STYLES_STROKE = {}, (0, _defineProperty2["default"])(_STATE_STYLES_STROKE, _reactMapGlDraw.RenderStates.SELECTED, _constants.COLORS.PRIMARY), (0, _defineProperty2["default"])(_STATE_STYLES_STROKE, _reactMapGlDraw.RenderStates.HOVERED, _constants.COLORS.SECONDARY), _STATE_STYLES_STROKE);
exports.STATE_STYLES_STROKE = STATE_STYLES_STROKE;
var DEFAULT_STATE_STYLE_FILL = '#ffffff';
exports.DEFAULT_STATE_STYLE_FILL = DEFAULT_STATE_STYLE_FILL;
var STATE_STYLES_FILL = (_STATE_STYLES_FILL = {}, (0, _defineProperty2["default"])(_STATE_STYLES_FILL, _reactMapGlDraw.RenderStates.SELECTED, _constants.COLORS.SECONDARY), (0, _defineProperty2["default"])(_STATE_STYLES_FILL, _reactMapGlDraw.RenderStates.HOVERED, _constants.COLORS.SECONDARY), (0, _defineProperty2["default"])(_STATE_STYLES_FILL, _reactMapGlDraw.RenderStates.INACTIVE, _constants.COLORS.PRIMARY), (0, _defineProperty2["default"])(_STATE_STYLES_FILL, _reactMapGlDraw.RenderStates.UNCOMMITTED, _constants.COLORS.PRIMARY), _STATE_STYLES_FILL);
exports.STATE_STYLES_FILL = STATE_STYLES_FILL;
var STATE_STYLES_STROKE_WIDTH = 1;
var RENDER_TYPE_STYLES = (_RENDER_TYPE_STYLES = {}, (0, _defineProperty2["default"])(_RENDER_TYPE_STYLES, _reactMapGlDraw.RenderTypes.POINT, function (state) {
return {
fill: STATE_STYLES_FILL[state],
stroke: state === _reactMapGlDraw.RenderStates.SELECTED ? _constants.COLORS.PRIMARY : DEFAULT_STATE_STYLE_STROKE
};
}), (0, _defineProperty2["default"])(_RENDER_TYPE_STYLES, _reactMapGlDraw.RenderTypes.LINE_STRING, function () {
return rectStyle;
}), (0, _defineProperty2["default"])(_RENDER_TYPE_STYLES, _reactMapGlDraw.RenderTypes.RECTANGLE, function () {
return rectStyle;
}), (0, _defineProperty2["default"])(_RENDER_TYPE_STYLES, _reactMapGlDraw.RenderTypes.POLYGON, function () {
return rectStyle;
}), _RENDER_TYPE_STYLES);
exports.RENDER_TYPE_STYLES = RENDER_TYPE_STYLES;
var DEFAULT_STATE_STYLE_OPACITY = 0;
exports.DEFAULT_STATE_STYLE_OPACITY = DEFAULT_STATE_STYLE_OPACITY;
var DEFAULT_RADIUS = 5;
exports.DEFAULT_RADIUS = DEFAULT_RADIUS;
function noOp() {}
function getStyle(_ref) {
var feature = _ref.feature,
state = _ref.state;
var isVisible = (0, _lodash["default"])(feature, ['properties', 'isVisible'], true);
var style = {
stroke: STATE_STYLES_STROKE[state] || DEFAULT_STATE_STYLE_STROKE,
strokeWidth: isVisible ? STATE_STYLES_STROKE_WIDTH : 0,
fill: DEFAULT_STATE_STYLE_FILL,
fillOpacity: DEFAULT_STATE_STYLE_OPACITY,
r: DEFAULT_RADIUS
};
var renderType = feature.properties ? feature.properties.renderType : feature.renderType;
return _objectSpread({}, style, {}, (RENDER_TYPE_STYLES[renderType] || noOp)(state));
}
function getEditHandleShape() {
return DEFAULT_EDIT_HANDLE_SHAPE;
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jb21wb25lbnRzL2VkaXRvci9oYW5kbGUtc3R5bGUuanMiXSwibmFtZXMiOlsiREVGQVVMVF9FRElUX0hBTkRMRV9TSEFQRSIsInJlY3RTdHlsZSIsIngiLCJ5IiwiaGVpZ2h0Iiwid2lkdGgiLCJERUZBVUxUX1NUQVRFX1NUWUxFX1NUUk9LRSIsIkNPTE9SUyIsIlBSSU1BUlkiLCJTVEFURV9TVFlMRVNfU1RST0tFIiwiUmVuZGVyU3RhdGVzIiwiU0VMRUNURUQiLCJIT1ZFUkVEIiwiU0VDT05EQVJZIiwiREVGQVVMVF9TVEFURV9TVFlMRV9GSUxMIiwiU1RBVEVfU1RZTEVTX0ZJTEwiLCJJTkFDVElWRSIsIlVOQ09NTUlUVEVEIiwiU1RBVEVfU1RZTEVTX1NUUk9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