kepler.gl
Version:
kepler.gl is a webgl based application to visualize large scale location data in the browser
77 lines (75 loc) • 12.6 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _itemSelector = _interopRequireDefault(require("../common/item-selector/item-selector"));
var _constants = require("@kepler.gl/constants");
var _components = require("./components");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
var layerFilter = function layerFilter(layer) {
return layer.type === _constants.LAYER_TYPES.point;
};
var isAlreadySelected = function isAlreadySelected(selectedLayers, layerId) {
return selectedLayers.findIndex(function (l) {
return l.id === layerId;
}) === -1;
};
function PolygonFilterFactory() {
var PolygonFilter = /*#__PURE__*/_react["default"].memo(function (_ref) {
var filter = _ref.filter,
layers = _ref.layers,
setLayers = _ref.setLayers;
var setNewLayers = (0, _react.useCallback)(function (newLayers) {
return setLayers(newLayers.map(function (l) {
return l.id;
}));
}, [setLayers]);
var selectedLayers = (0, _react.useMemo)(function () {
return layers.filter(function (l) {
var _filter$layerId;
return (_filter$layerId = filter.layerId) === null || _filter$layerId === void 0 ? void 0 : _filter$layerId.includes(l.id);
});
}, [filter, layers]);
var availableLayers = (0, _react.useMemo)(function () {
// remove already added layers and filter out non point layers
return layers.filter(function (layer) {
return layerFilter(layer) && isAlreadySelected(selectedLayers, layer.id);
});
}, [layers, selectedLayers]);
var searchOptions = (0, _react.useCallback)(function (value, options) {
var searchStr = value === null || value === void 0 ? void 0 : value.toLowerCase();
return options.filter(function (l) {
var _l$config;
return ((_l$config = l.config) === null || _l$config === void 0 || (_l$config = _l$config.label) === null || _l$config === void 0 ? void 0 : _l$config.toLowerCase().indexOf(searchStr)) >= 0;
});
}, []);
return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_components.StyledFilterPanel, {
htmlFor: "filter-".concat(filter.id)
}, "Layers:"), /*#__PURE__*/_react["default"].createElement(_itemSelector["default"], {
options: availableLayers,
selectedItems: selectedLayers,
onChange: setNewLayers,
searchable: true,
searchOptions: searchOptions,
multiSelect: true,
getOptionValue: function getOptionValue(l) {
return l.id;
},
displayOption: function displayOption(l) {
return l.config.label;
},
placeholder: 'placeholder.selectLayer'
}));
});
PolygonFilter.displayName = 'PolygonFilter';
return PolygonFilter;
}
var _default = exports["default"] = PolygonFilterFactory;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfcmVhY3QiLCJfaW50ZXJvcFJlcXVpcmVXaWxkY2FyZCIsInJlcXVpcmUiLCJfaXRlbVNlbGVjdG9yIiwiX2ludGVyb3BSZXF1aXJlRGVmYXVsdCIsIl9jb25zdGFudHMiLCJfY29tcG9uZW50cyIsIl9nZXRSZXF1aXJlV2lsZGNhcmRDYWNoZSIsImUiLCJXZWFrTWFwIiwiciIsInQiLCJfX2VzTW9kdWxlIiwiX3R5cGVvZiIsImhhcyIsImdldCIsIm4iLCJfX3Byb3RvX18iLCJhIiwiT2JqZWN0IiwiZGVmaW5lUHJvcGVydHkiLCJnZXRPd25Qcm9wZXJ0eURlc2NyaXB0b3IiLCJ1IiwiaGFz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