UNPKG

kepler.gl

Version:

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

80 lines (78 loc) 10.8 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); var _react = require("react"); var _reactRedux = require("react-redux"); var _actions = require("@kepler.gl/actions"); var _constants = require("@kepler.gl/constants"); var _reducers = require("@kepler.gl/reducers"); // SPDX-License-Identifier: MIT // Copyright contributors to the kepler.gl project var useDndLayers = function useDndLayers(layers, layerOrder) { var dispatch = (0, _reactRedux.useDispatch)(); var _useState = (0, _react.useState)(), _useState2 = (0, _slicedToArray2["default"])(_useState, 2), activeLayer = _useState2[0], setActiveLayer = _useState2[1]; var onDragStart = (0, _react.useCallback)(function (event) { var active = event.active; var newActiveLayer = layers.find(function (layer) { return layer.id === active.id; }); if (newActiveLayer) { setActiveLayer(newActiveLayer); if (newActiveLayer !== null && newActiveLayer !== void 0 && newActiveLayer.config.isConfigActive) { dispatch((0, _actions.layerConfigChange)(newActiveLayer, { isConfigActive: false })); } } }, [dispatch, layers]); var onDragEnd = (0, _react.useCallback)(function (event) { var _over$data; var active = event.active, over = event.over; var activeLayerId = active.id; var overType = over === null || over === void 0 || (_over$data = over.data) === null || _over$data === void 0 || (_over$data = _over$data.current) === null || _over$data === void 0 ? void 0 : _over$data.type; if (!overType) { setActiveLayer(undefined); return; } switch (overType) { // moving layers into maps case _constants.DROPPABLE_MAP_CONTAINER_TYPE: { var _over$data$current$in, _over$data$current; var mapIndex = (_over$data$current$in = (_over$data$current = over.data.current) === null || _over$data$current === void 0 ? void 0 : _over$data$current.index) !== null && _over$data$current$in !== void 0 ? _over$data$current$in : 0; dispatch((0, _actions.toggleLayerForMap)(mapIndex, activeLayerId)); break; } // swaping layers case _constants.SORTABLE_LAYER_TYPE: { var newLayerOrder = (0, _reducers.reorderLayerOrder)(layerOrder, activeLayerId, over.id); dispatch((0, _actions.reorderLayer)(newLayerOrder)); break; } // moving layers within side panel case _constants.SORTABLE_SIDE_PANEL_TYPE: // move layer to the end of the list dispatch((0, _actions.reorderLayer)((0, _reducers.reorderLayerOrder)(layerOrder, activeLayerId, layerOrder[layerOrder.length - 1]))); break; default: break; } setActiveLayer(undefined); }, [dispatch, layerOrder]); return { activeLayer: activeLayer, onDragStart: onDragStart, onDragEnd: onDragEnd }; }; var _default = exports["default"] = useDndLayers; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfcmVhY3QiLCJyZXF1aXJlIiwiX3JlYWN0UmVkdXgiLCJfYWN0aW9ucyIsIl9jb25zdGFudHMiLCJfcmVkdWNlcnMiLCJ1c2VEbmRMYXllcnMiLCJsYXllcnMiLCJsYXllck9yZGVyIiwiZGlzcGF0Y2giLCJ1c2VEaXNwYXRjaCIsIl91c2VTdGF0ZSIsInVzZVN0YXRlIiwiX3VzZVN0YXRlMiIsIl9zbGljZWRUb0FycmF5MiIsImFjdGl2ZUxheWVyIiwic2V0QWN0aXZlTGF5ZXIiLCJvbkRyYWdTdGFydCIsInVzZUNhbGxiYWNrIiwiZXZlbnQiLCJhY3RpdmUiLCJuZXdBY3RpdmVMYXllciIsImZpbmQiLCJsYXllciIsImlkIiwiY29uZmlnIiwiaXNDb25maWdBY3RpdmUiLCJsYXllckNvbmZpZ0NoYW5nZSIsIm9uRHJhZ0VuZCIsIl9vdmVyJGRhdGEiLCJvdmVyIiwiYWN0aXZlTGF5ZXJJZCIsIm92ZXJUeXBlIiwiZGF0YSIsImN1cnJlbnQiLCJ0eXBlIiwidW5kZWZpbmVkIiwiRFJPUFBBQkxFX01BUF9DT05UQUlORVJfVFlQRSIsIl9vdmVyJGRhdGEkY3VycmVudCRpbiIsIl9vdmVyJGRhdGEkY3VycmVudCIsIm1hcEluZGV4IiwiaW5kZXgiLCJ0b2dnbGVMYXllckZvck1hcCIsIlNPUl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