kepler.gl
Version:
kepler.gl is a webgl based application to visualize large scale location data in the browser
34 lines (31 loc) • 3.62 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getS2Center = getS2Center;
exports.validS2Token = validS2Token;
var _long = _interopRequireDefault(require("long"));
var _s2Geometry = require("s2-geometry");
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
var MAXIMUM_TOKEN_LENGTH = 16;
/**
* Retrieve S2 geometry center
* @param s2Token string | number
* @return {*[]}
*/
function getS2Center(s2Token) {
var paddedToken = s2Token.toString().padEnd(MAXIMUM_TOKEN_LENGTH, '0');
var s2Id = _long["default"].fromString(paddedToken, MAXIMUM_TOKEN_LENGTH);
var _S2$idToLatLng = _s2Geometry.S2.idToLatLng(s2Id.toString()),
lat = _S2$idToLatLng.lat,
lng = _S2$idToLatLng.lng;
return [lng, lat];
}
var re = new RegExp('^[0-9a-z]*$', 'g');
// simple test to see if token only contains numbers and letters
function validS2Token(token) {
return typeof token === 'string' && Boolean(token.match(re));
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfbG9uZyIsIl9pbnRlcm9wUmVxdWlyZURlZmF1bHQiLCJyZXF1aXJlIiwiX3MyR2VvbWV0cnkiLCJNQVhJTVVNX1RPS0VOX0xFTkdUSCIsImdldFMyQ2VudGVyIiwiczJUb2tlbiIsInBhZGRlZFRva2VuIiwidG9TdHJpbmciLCJwYWRFbmQiLCJzMklkIiwiTG9uZyIsImZyb21TdHJpbmciLCJfUzIkaWRUb0xhdExuZyIsIlMyIiwiaWRUb0xhdExuZyIsImxhdCIsImxuZyIsInJlIiwiUmVnRXhwIiwidmFsaWRTMlRva2VuIiwidG9rZW4iLCJCb29sZWFuIiwibWF0Y2giXSwic291cmNlcyI6WyIuLi8uLi9zcmMvczItZ2VvbWV0cnktbGF5ZXIvczItdXRpbHMudHMiXSwic291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