UNPKG

kepler.gl

Version:

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

115 lines (99 loc) 11.4 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.getDefaultInteraction = getDefaultInteraction; exports.findFieldsToShow = findFieldsToShow; exports.BRUSH_CONFIG = void 0; var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _defaultSettings = require("../constants/default-settings"); var _icons = require("../components/common/icons"); // 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. function getDefaultInteraction() { return { tooltip: { id: 'tooltip', label: 'interactions.tooltip', enabled: true, iconComponent: _icons.Messages, config: { fieldsToShow: {} } }, brush: { id: 'brush', label: 'interactions.brush', enabled: false, iconComponent: _icons.Crosshairs, config: { // size is in km size: 0.5 } }, coordinate: { id: 'coordinate', label: 'interactions.coordinate', enabled: false, iconComponent: _icons.CursorClick, position: null } }; } var BRUSH_CONFIG = { range: [0, 50] }; exports.BRUSH_CONFIG = BRUSH_CONFIG; function findFieldsToShow(_ref) { var fields = _ref.fields, id = _ref.id; // first find default tooltip fields for trips var fieldsToShow = _defaultSettings.DEFAULT_TOOLTIP_FIELDS.reduce(function (prev, curr) { if (fields.find(function (_ref2) { var name = _ref2.name; return curr === name; })) { prev.push(curr); } return prev; }, []); return (0, _defineProperty2["default"])({}, id, fieldsToShow.length ? fieldsToShow : autoFindTooltipFields(fields)); } function autoFindTooltipFields(fields) { var ptFields = _mergeFieldPairs(_defaultSettings.TRIP_POINT_FIELDS); // filter out the default fields that contains lat and lng and any geometry var fieldsToShow = fields.filter(function (_ref4) { var name = _ref4.name, type = _ref4.type; return name.replace(/[_,.]+/g, ' ').trim().split(' ').every(function (seg) { return !ptFields.includes(seg); }) && type !== _defaultSettings.ALL_FIELD_TYPES.geojson && type !== 'object'; }); return fieldsToShow.slice(0, _defaultSettings.MAX_DEFAULT_TOOLTIPS).map(function (d) { return d.name; }); } function _mergeFieldPairs(pairs) { return pairs.reduce(function (prev, pair) { return [].concat((0, _toConsumableArray2["default"])(prev), (0, _toConsumableArray2["default"])(pair)); }, []); } //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9pbnRlcmFjdGlvbi11dGlscy5qcyJdLCJuYW1lcyI6WyJnZXREZWZhdWx0SW50ZXJhY3Rpb24iLCJ0b29sdGlwIiwiaWQiLCJsYWJlbCIsImVuYWJsZWQiLCJpY29uQ29tcG9uZW50IiwiTWVzc2FnZXMiLCJjb25maWciLCJmaWVsZHNUb1Nob3ciLCJicnVzaCIsIkNyb3NzaGFpcnMiLCJzaXplIiwiY29vcmRpbmF0ZSIsIkN1cnNvckNsaWNrIiwicG9zaXRpb24iLCJCUlVTSF9DT05GSUciLCJyYW5nZSIsImZpbmRGaWVsZHNUb1Nob3ciLCJmaWVsZHMiLCJERUZBVUxUX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