UNPKG

kepler.gl

Version:

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

53 lines (49 loc) 7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findMapBounds = findMapBounds; exports.processLayerBounds = processLayerBounds; var _utils = require("@kepler.gl/utils"); // SPDX-License-Identifier: MIT // Copyright contributors to the kepler.gl project /** * takes a list of layer bounds and returns a single bound */ function processLayerBounds(layerBounds) { return layerBounds.reduce(function (res, b) { var minLongitude = Math.min(res[0], b[0]); var minLatitude = Math.min(res[1], b[1]); var maxLongitude = Math.max(res[2], b[2]); var maxLatitude = Math.max(res[3], b[3]); // for some reason WebMercatorViewport can't handle latitude -90,90 and throws an error // so we default to lat/lng (0,0) // viewport.js:81 Uncaught Error: Pixel project matrix not invertible // at WebMercatorViewport16.Viewport5 (viewport.js:81:13) // at new WebMercatorViewport16 (web-mercator-viewport.js:92:5) // at getViewportFromMapState (map-utils.js:46:66) return [(0, _utils.validateLongitude)(minLongitude), (0, _utils.validateLatitude)(minLatitude), (0, _utils.validateLongitude)(maxLongitude), (0, _utils.validateLatitude)(maxLatitude)]; }, [_utils.MAX_LONGITUDE, _utils.MAX_LATITUDE, _utils.MIN_LONGITUDE, _utils.MIN_LATITUDE]); } /** * return center of map from given points * @param layers * @returns coordinates of map center, empty if not found */ function findMapBounds(layers) { // find bounds in formatted layerData // take ALL layers into account when finding map bounds var availableLayerBounds = layers.reduce(function (res, l) { if (l.meta && l.meta.bounds) { res.push(l.meta.bounds); } return res; }, []); // return null if no layer is available if (availableLayerBounds.length === 0) { return null; } // merge bounds in each layer return processLayerBounds(availableLayerBounds); } //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfdXRpbHMiLCJyZXF1aXJlIiwicHJvY2Vzc0xheWVyQm91bmRzIiwibGF5ZXJCb3VuZHMiLCJyZWR1Y2UiLCJyZXMiLCJiIiwibWluTG9uZ2l0dWRlIiwiTWF0aCIsIm1pbiIsIm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