UNPKG

kepler.gl

Version:

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

93 lines (81 loc) 10.1 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); 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 _components = require("./components"); var _constants = require("../../constants"); // Copyright (c) 2020 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. 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 = _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; })); }, [layers, setLayers]); var selectedLayers = (0, _react.useMemo)(function () { return layers.filter(function (l) { return 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]); return _react["default"].createElement("div", null, _react["default"].createElement(_components.StyledFilterPanel, { htmlFor: "filter-".concat(filter.id) }, "Layers:"), _react["default"].createElement(_itemSelector["default"], { options: availableLayers, selectedItems: selectedLayers, onChange: setNewLayers, searchable: false, multiSelect: true, getOptionValue: function getOptionValue(l) { return l.id; }, displayOption: function displayOption(l) { return l.config.label; } })); }); PolygonFilter.displayName = 'PolygonFilter'; return PolygonFilter; } var _default = PolygonFilterFactory; exports["default"] = _default; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jb21wb25lbnRzL2ZpbHRlcnMvcG9seWdvbi1maWx0ZXIuanMiXSwibmFtZXMiOlsibGF5ZXJGaWx0ZXIiLCJsYXllciIsInR5cGUiLCJMQVlFUl9UWVBFUyIsInBvaW50IiwiaXNBbHJlYWR5U2VsZWN0ZWQiLCJzZWxlY3RlZExheWVycyIsImxheWVySWQiLCJmaW5kSW5kZXgiLCJsIiwiaWQiLCJQb2x5Z29uRmlsdGVyRmFjdG9yeSIsIlBvbHlnb25GaWx0ZXIiLCJSZWFjdCIsIm1lbW8iLCJmaWx0ZXIiLCJsYXllcnMiLCJzZXRMYXllcnMiLCJzZXROZXdMYXllcnMiLCJuZXdMYXllcnMiLCJtYXAiLCJpbmNsdWRlcyIsImF2YWlsYWJsZUxheWVycyIsImNvbmZpZyIsImxhYmVsIiwiZGlzcGxheU5hbWUiXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7O0FBb0JBOztBQUNBOztBQUNBOztBQUNBOztBQXZCQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO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