kepler.gl
Version:
kepler.gl is a webgl based application to visualize large scale location data in the browser
72 lines (70 loc) • 12.5 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validateViewPort = exports.onViewPortChange = exports.getViewportFromMapState = exports.getMapLayersFromSplitMaps = void 0;
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _viewportMercatorProject = _interopRequireDefault(require("viewport-mercator-project"));
var _constants = require("@kepler.gl/constants");
var _dataUtils = require("./data-utils");
var _excluded = ["width", "height"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
/**
* Validates a ViewPort object.
* It retains all properties of the original ViewPort object,
* but ensures that the latitude is within the defined bounds.
* @param viewport - The ViewPort object to validate.
* @returns A new ViewPort object with validated latitude.
*/
var validateViewPort = exports.validateViewPort = function validateViewPort(viewport) {
return _objectSpread(_objectSpread(_objectSpread({}, viewport), viewport.latitude ? {
latitude: (0, _dataUtils.validateLatitude)(viewport.latitude)
} : {}), viewport.longitude ? {
longitude: (0, _dataUtils.validateLongitude)(viewport.longitude)
} : {});
};
var onViewPortChange = exports.onViewPortChange = function onViewPortChange(viewState, onUpdateMap, onViewStateChange) {
var primary = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
var mapIndex = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
var _viewState$width = viewState.width,
width = _viewState$width === void 0 ? 0 : _viewState$width,
_viewState$height = viewState.height,
height = _viewState$height === void 0 ? 0 : _viewState$height,
restViewState = (0, _objectWithoutProperties2["default"])(viewState, _excluded);
// react-map-gl sends 0,0 dimensions during initialization
// after we have received proper dimensions from observeDimensions
var next = _objectSpread(_objectSpread({}, width > 0 && height > 0 ? viewState : restViewState), {}, {
// enabling transition in two maps may lead to endless update loops
transitionDuration: primary ? _constants.TRANSITION_DURATION : 0
});
if (onViewStateChange && typeof onViewStateChange === 'function') {
onViewStateChange(next);
}
onUpdateMap(next, mapIndex);
};
var getMapLayersFromSplitMaps = exports.getMapLayersFromSplitMaps = function getMapLayersFromSplitMaps(splitMaps, mapIndex) {
var _splitMaps;
return (_splitMaps = splitMaps[mapIndex || 0]) === null || _splitMaps === void 0 ? void 0 : _splitMaps.layers;
};
/**
* Generates a viewport from a map state.
* @param mapState
* @returns A viewport.
*/
var getViewportFromMapState = exports.getViewportFromMapState = function getViewportFromMapState(mapState) {
// Make sure we capture error
// e.g. Error message: "Pixel project matrix not invertible"
var viewPort;
try {
viewPort = new _viewportMercatorProject["default"](mapState);
} catch (_unused) {
// catch error and fallback to default map state
viewPort = new _viewportMercatorProject["default"](validateViewPort(mapState));
}
return viewPort;
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfdmlld3BvcnRNZXJjYXRvclByb2plY3QiLCJfaW50ZXJvcFJlcXVpcmVEZWZhdWx0IiwicmVxdWlyZSIsIl9jb25zdGFudHMiLCJfZGF0YVV0aWxzIiwiX2V4Y2x1ZGVkIiwib3duS2V5cyIsImUiLCJyIiwidCIsIk9iamVjdCIsImtleXMiLCJnZXRPd25Qcm9wZXJ0eVN5bWJvbHMiLCJ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