UNPKG

kepler.gl

Version:

kepler.gl is a webgl based application to visualize large scale location data in the browser

72 lines (58 loc) 11.5 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.noOp = noOp; exports.getStyle = getStyle; exports.RENDER_TYPE_STYLES = exports.DEFAULT_STROKE_DASH_ARRAY = exports.STATE_STYLES_STROKE_WIDTH = exports.DEFAULT_STATE_STYLE_OPACITY = exports.STATE_STYLES_FILL = exports.DEFAULT_STATE_STYLE_FILL = exports.STATE_STYLES_STROKE = exports.DEFAULT_STATE_STYLE_STROKE = exports.DEFAULT_RADIUS = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _reactMapGlDraw = require("react-map-gl-draw"); var _lodash = _interopRequireDefault(require("lodash.get")); var _constants = require("./constants"); 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_RADIUS = 5; exports.DEFAULT_RADIUS = DEFAULT_RADIUS; 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.INACTIVE, '#26B5F2'), (0, _defineProperty2["default"])(_STATE_STYLES_STROKE, _reactMapGlDraw.RenderStates.UNCOMMITTED, '#a9a9a9'), (0, _defineProperty2["default"])(_STATE_STYLES_STROKE, _reactMapGlDraw.RenderStates.CLOSING, '#a9a9a9'), (0, _defineProperty2["default"])(_STATE_STYLES_STROKE, _reactMapGlDraw.RenderStates.SELECTED, '#26B5F2'), (0, _defineProperty2["default"])(_STATE_STYLES_STROKE, _reactMapGlDraw.RenderStates.HOVERED, '#26B5F2'), _STATE_STYLES_STROKE); exports.STATE_STYLES_STROKE = STATE_STYLES_STROKE; var DEFAULT_STATE_STYLE_FILL = '#000'; exports.DEFAULT_STATE_STYLE_FILL = DEFAULT_STATE_STYLE_FILL; var STATE_STYLES_FILL = (_STATE_STYLES_FILL = {}, (0, _defineProperty2["default"])(_STATE_STYLES_FILL, _reactMapGlDraw.RenderStates.INACTIVE, '#333333'), (0, _defineProperty2["default"])(_STATE_STYLES_FILL, _reactMapGlDraw.RenderStates.HOVERED, '#7ac943'), (0, _defineProperty2["default"])(_STATE_STYLES_FILL, _reactMapGlDraw.RenderStates.SELECTED, '#ffff00'), (0, _defineProperty2["default"])(_STATE_STYLES_FILL, _reactMapGlDraw.RenderStates.UNCOMMITTED, '#a9a9a9'), (0, _defineProperty2["default"])(_STATE_STYLES_FILL, _reactMapGlDraw.RenderStates.CLOSING, '#a9a9a9'), _STATE_STYLES_FILL); exports.STATE_STYLES_FILL = STATE_STYLES_FILL; var DEFAULT_STATE_STYLE_OPACITY = 0.1; exports.DEFAULT_STATE_STYLE_OPACITY = DEFAULT_STATE_STYLE_OPACITY; var STATE_STYLES_STROKE_WIDTH = 2; exports.STATE_STYLES_STROKE_WIDTH = STATE_STYLES_STROKE_WIDTH; var DEFAULT_STROKE_DASH_ARRAY = '4,2'; exports.DEFAULT_STROKE_DASH_ARRAY = DEFAULT_STROKE_DASH_ARRAY; var RENDER_TYPE_STYLES = (_RENDER_TYPE_STYLES = {}, (0, _defineProperty2["default"])(_RENDER_TYPE_STYLES, _reactMapGlDraw.RenderTypes.POINT, function () { return { r: DEFAULT_RADIUS }; }), (0, _defineProperty2["default"])(_RENDER_TYPE_STYLES, _reactMapGlDraw.RenderTypes.LINE_STRING, function () { return { fill: 'none' }; }), _RENDER_TYPE_STYLES); exports.RENDER_TYPE_STYLES = RENDER_TYPE_STYLES; function noOp() {} function getStyle(_ref) { var feature = _ref.feature, state = _ref.state; var isVisible = (0, _lodash["default"])(feature, ['properties', 'isVisible'], true); var style = _objectSpread({ stroke: STATE_STYLES_STROKE[state] || DEFAULT_STATE_STYLE_STROKE, strokeWidth: isVisible ? STATE_STYLES_STROKE_WIDTH : 0, fill: STATE_STYLES_FILL[state] || DEFAULT_STATE_STYLE_FILL, fillOpacity: DEFAULT_STATE_STYLE_OPACITY }, state !== _reactMapGlDraw.RenderStates.SELECTED ? { strokeDasharray: DEFAULT_STROKE_DASH_ARRAY } : null); var renderType = feature.properties ? feature.properties.renderType : feature.renderType; return _objectSpread({}, style, {}, (RENDER_TYPE_STYLES[renderType] || noOp)(state)); } //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jb21wb25lbnRzL2VkaXRvci9mZWF0dXJlLXN0eWxlcy5qcyJdLCJuYW1lcyI6WyJERUZBVUxUX1JBRElVUyIsIkRFRkFVTFRfU1RBVEVfU1RZTEVfU1RST0tFIiwiQ09MT1JTIiwiUFJJTUFSWSIsIlNUQVRFX1NUWUxFU19TVFJPS0UiLCJSZW5kZXJTdGF0ZXMiLCJJTkFDVElWRSIsIlVOQ09NTUlUVEVEIiwiQ0xPU0lORyIsIlNFTEVDVEVEIiwiSE9WRVJFRCIsIkRFRkFVTFRfU1RBVEVfU1RZTEVfRklMTCIsIlNUQVRFX1NUWUxFU19GSUxMIiwi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