UNPKG

kepler.gl

Version:

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

45 lines (43 loc) 5.91 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.hexagonToPolygonGeo = hexagonToPolygonGeo; var _core = require("@deck.gl/core"); var _console = _interopRequireDefault(require("global/console")); // SPDX-License-Identifier: MIT // Copyright contributors to the kepler.gl project function hexagonToPolygonGeo(object, properties, radius, mapState) { var viewport = new _core.WebMercatorViewport(mapState); if (!Array.isArray(object.position)) { return null; } var screenCenter = viewport.projectFlat(object.position); var _viewport$getDistance = viewport.getDistanceScales(object.position), unitsPerMeter = _viewport$getDistance.unitsPerMeter; if (!Array.isArray(unitsPerMeter)) { _console["default"].warn("unitsPerMeter is undefined"); return null; } var pixRadius = radius * unitsPerMeter[0]; var coordinates = []; for (var i = 0; i < 6; i++) { var vertex = hex_corner(screenCenter, pixRadius, i); coordinates.push(viewport.unprojectFlat(vertex)); } coordinates.push(coordinates[0]); return { geometry: { coordinates: coordinates, type: 'LineString' }, properties: properties }; } function hex_corner(center, radius, i) { var angle_deg = 60 * i + 30; var angle_rad = Math.PI / 180 * angle_deg; return [center[0] + radius * Math.cos(angle_rad), center[1] + radius * Math.sin(angle_rad)]; } //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfY29yZSIsInJlcXVpcmUiLCJfY29uc29sZSIsIl9pbnRlcm9wUmVxdWlyZURlZmF1bHQiLCJoZXhhZ29uVG9Qb2x5Z29uR2VvIiwib2JqZWN0IiwicHJvcGVydGllcyIsInJhZGl1cyIsIm1hcFN0YXRlIiwidmlld3BvcnQiLCJXZWJNZXJjYXRvclZpZXdwb3J0IiwiQXJyYXkiLCJpc0FycmF5IiwicG9zaXRpb24iLCJzY3JlZW5DZW50ZXIiLCJwcm9qZWN0RmxhdCIsIl92aWV3cG9ydCRnZXREaXN0YW5jZSIsImdldERpc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