Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@math.gl/web-mercator

Package Overview
Dependencies
Maintainers
3
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@math.gl/web-mercator - npm Package Compare versions

Comparing version 3.6.0-alpha.1 to 3.6.0-alpha.2

68

dist/es5/fit-bounds.js

@@ -10,3 +10,3 @@ "use strict";

var _webMercatorViewport = _interopRequireDefault(require("./web-mercator-viewport"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

@@ -17,32 +17,36 @@ var _assert = _interopRequireDefault(require("./assert"));

var _webMercatorUtils = require("./web-mercator-utils");
function fitBounds(options) {
const {
width,
height,
bounds,
minExtent = 0,
maxZoom = 24,
offset = [0, 0]
} = options;
const [[west, south], [east, north]] = bounds;
const padding = getPaddingObject(options.padding);
const viewport = new _webMercatorViewport.default({
width,
height,
longitude: 0,
latitude: 0,
zoom: 0
});
const nw = viewport.project([west, north]);
const se = viewport.project([east, south]);
const size = [Math.max(Math.abs(se[0] - nw[0]), minExtent), Math.max(Math.abs(se[1] - nw[1]), minExtent)];
const targetSize = [width - padding.left - padding.right - Math.abs(offset[0]) * 2, height - padding.top - padding.bottom - Math.abs(offset[1]) * 2];
var width = options.width,
height = options.height,
bounds = options.bounds,
_options$minExtent = options.minExtent,
minExtent = _options$minExtent === void 0 ? 0 : _options$minExtent,
_options$maxZoom = options.maxZoom,
maxZoom = _options$maxZoom === void 0 ? 24 : _options$maxZoom,
_options$offset = options.offset,
offset = _options$offset === void 0 ? [0, 0] : _options$offset;
var _bounds = (0, _slicedToArray2.default)(bounds, 2),
_bounds$ = (0, _slicedToArray2.default)(_bounds[0], 2),
west = _bounds$[0],
south = _bounds$[1],
_bounds$2 = (0, _slicedToArray2.default)(_bounds[1], 2),
east = _bounds$2[0],
north = _bounds$2[1];
var padding = getPaddingObject(options.padding);
var nw = (0, _webMercatorUtils.lngLatToWorld)([west, (0, _mathUtils.clamp)(north, -_webMercatorUtils.MAX_LATITUDE, _webMercatorUtils.MAX_LATITUDE)]);
var se = (0, _webMercatorUtils.lngLatToWorld)([east, (0, _mathUtils.clamp)(south, -_webMercatorUtils.MAX_LATITUDE, _webMercatorUtils.MAX_LATITUDE)]);
var size = [Math.max(Math.abs(se[0] - nw[0]), minExtent), Math.max(Math.abs(se[1] - nw[1]), minExtent)];
var targetSize = [width - padding.left - padding.right - Math.abs(offset[0]) * 2, height - padding.top - padding.bottom - Math.abs(offset[1]) * 2];
(0, _assert.default)(targetSize[0] > 0 && targetSize[1] > 0);
const scaleX = targetSize[0] / size[0];
const scaleY = targetSize[1] / size[1];
const offsetX = (padding.right - padding.left) / 2 / scaleX;
const offsetY = (padding.bottom - padding.top) / 2 / scaleY;
const center = [(se[0] + nw[0]) / 2 + offsetX, (se[1] + nw[1]) / 2 + offsetY];
const centerLngLat = viewport.unproject(center);
const zoom = Math.min(maxZoom, viewport.zoom + (0, _mathUtils.log2)(Math.abs(Math.min(scaleX, scaleY))));
var scaleX = targetSize[0] / size[0];
var scaleY = targetSize[1] / size[1];
var offsetX = (padding.right - padding.left) / 2 / scaleX;
var offsetY = (padding.bottom - padding.top) / 2 / scaleY;
var center = [(se[0] + nw[0]) / 2 + offsetX, (se[1] + nw[1]) / 2 + offsetY];
var centerLngLat = (0, _webMercatorUtils.worldToLngLat)(center);
var zoom = Math.min(maxZoom, (0, _mathUtils.log2)(Math.abs(Math.min(scaleX, scaleY))));
(0, _assert.default)(Number.isFinite(zoom));

@@ -52,7 +56,9 @@ return {

latitude: centerLngLat[1],
zoom
zoom: zoom
};
}
function getPaddingObject(padding = 0) {
function getPaddingObject() {
var padding = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
if (typeof padding === 'number') {

@@ -59,0 +65,0 @@ return {

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -9,2 +13,4 @@ value: true

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _mathUtils = require("./math-utils");

@@ -16,9 +22,19 @@

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const EPSILON = 0.01;
const VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];
const DEFAULT_OPTS = {
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
var EPSILON = 0.01;
var VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];
var DEFAULT_OPTS = {
curve: 1.414,

@@ -29,21 +45,30 @@ speed: 1.2

function flyToViewport(startProps, endProps, t, options) {
const {
startZoom,
startCenterXY,
uDelta,
w0,
u1,
S,
rho,
rho2,
r0
} = getFlyToTransitionParams(startProps, endProps, options);
var _getFlyToTransitionPa = getFlyToTransitionParams(startProps, endProps, options),
startZoom = _getFlyToTransitionPa.startZoom,
startCenterXY = _getFlyToTransitionPa.startCenterXY,
uDelta = _getFlyToTransitionPa.uDelta,
w0 = _getFlyToTransitionPa.w0,
u1 = _getFlyToTransitionPa.u1,
S = _getFlyToTransitionPa.S,
rho = _getFlyToTransitionPa.rho,
rho2 = _getFlyToTransitionPa.rho2,
r0 = _getFlyToTransitionPa.r0;
if (u1 < EPSILON) {
const viewport = {};
var viewport = {};
for (const key of VIEWPORT_TRANSITION_PROPS) {
const startValue = startProps[key];
const endValue = endProps[key];
viewport[key] = (0, _mathUtils.lerp)(startValue, endValue, t);
var _iterator = _createForOfIteratorHelper(VIEWPORT_TRANSITION_PROPS),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var key = _step.value;
var startValue = startProps[key];
var endValue = endProps[key];
viewport[key] = (0, _mathUtils.lerp)(startValue, endValue, t);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}

@@ -54,10 +79,10 @@

const s = t * S;
const w = Math.cosh(r0) / Math.cosh(r0 + rho * s);
const u = w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2) / u1;
const scaleIncrement = 1 / w;
const newZoom = startZoom + (0, _webMercatorUtils.scaleToZoom)(scaleIncrement);
const newCenterWorld = vec2.scale([], uDelta, u);
var s = t * S;
var w = Math.cosh(r0) / Math.cosh(r0 + rho * s);
var u = w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2) / u1;
var scaleIncrement = 1 / w;
var newZoom = startZoom + (0, _webMercatorUtils.scaleToZoom)(scaleIncrement);
var newCenterWorld = vec2.scale([], uDelta, u);
vec2.add(newCenterWorld, newCenterWorld, startCenterXY);
const newCenter = (0, _webMercatorUtils.worldToLngLat)(newCenterWorld);
var newCenter = (0, _webMercatorUtils.worldToLngLat)(newCenterWorld);
return {

@@ -71,17 +96,15 @@ longitude: newCenter[0],

function getFlyToDuration(startProps, endProps, options) {
const opts = { ...DEFAULT_OPTS,
...options
};
const {
screenSpeed,
speed,
maxDuration
} = opts;
const {
S,
rho
} = getFlyToTransitionParams(startProps, endProps, opts);
const length = 1000 * S;
let duration;
var opts = _objectSpread(_objectSpread({}, DEFAULT_OPTS), options);
var screenSpeed = opts.screenSpeed,
speed = opts.speed,
maxDuration = opts.maxDuration;
var _getFlyToTransitionPa2 = getFlyToTransitionParams(startProps, endProps, opts),
S = _getFlyToTransitionPa2.S,
rho = _getFlyToTransitionPa2.rho;
var length = 1000 * S;
var duration;
if (Number.isFinite(screenSpeed)) {

@@ -98,37 +121,37 @@ duration = length / (screenSpeed / rho);

opts = Object.assign({}, DEFAULT_OPTS, opts);
const rho = opts.curve;
const startZoom = startProps.zoom;
const startCenter = [startProps.longitude, startProps.latitude];
const startScale = (0, _webMercatorUtils.zoomToScale)(startZoom);
const endZoom = endProps.zoom;
const endCenter = [endProps.longitude, endProps.latitude];
const scale = (0, _webMercatorUtils.zoomToScale)(endZoom - startZoom);
const startCenterXY = (0, _webMercatorUtils.lngLatToWorld)(startCenter);
const endCenterXY = (0, _webMercatorUtils.lngLatToWorld)(endCenter);
const uDelta = vec2.sub([], endCenterXY, startCenterXY);
const w0 = Math.max(startProps.width, startProps.height);
const w1 = w0 / scale;
const u1 = vec2.length(uDelta) * startScale;
var rho = opts.curve;
var startZoom = startProps.zoom;
var startCenter = [startProps.longitude, startProps.latitude];
var startScale = (0, _webMercatorUtils.zoomToScale)(startZoom);
var endZoom = endProps.zoom;
var endCenter = [endProps.longitude, endProps.latitude];
var scale = (0, _webMercatorUtils.zoomToScale)(endZoom - startZoom);
var startCenterXY = (0, _webMercatorUtils.lngLatToWorld)(startCenter);
var endCenterXY = (0, _webMercatorUtils.lngLatToWorld)(endCenter);
var uDelta = vec2.sub([], endCenterXY, startCenterXY);
var w0 = Math.max(startProps.width, startProps.height);
var w1 = w0 / scale;
var u1 = vec2.length(uDelta) * startScale;
const _u1 = Math.max(u1, EPSILON);
var _u1 = Math.max(u1, EPSILON);
const rho2 = rho * rho;
const b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);
const b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);
const r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);
const r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
const S = (r1 - r0) / rho;
var rho2 = rho * rho;
var b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);
var b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);
var r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);
var r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
var S = (r1 - r0) / rho;
return {
startZoom,
startCenterXY,
uDelta,
w0,
u1,
S,
rho,
rho2,
r0,
r1
startZoom: startZoom,
startCenterXY: startCenterXY,
uDelta: uDelta,
w0: w0,
u1: u1,
S: S,
rho: rho,
rho2: rho2,
r0: r0,
r1: r1
};
}
//# sourceMappingURL=fly-to-viewport.js.map
"use strict";
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -14,23 +16,22 @@ value: true

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const DEGREES_TO_RADIANS = Math.PI / 180;
var DEGREES_TO_RADIANS = Math.PI / 180;
function getBounds(viewport, z = 0) {
const {
width,
height,
unproject
} = viewport;
const unprojectOps = {
function getBounds(viewport) {
var z = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var width = viewport.width,
height = viewport.height,
unproject = viewport.unproject;
var unprojectOps = {
targetZ: z
};
const bottomLeft = unproject([0, height], unprojectOps);
const bottomRight = unproject([width, height], unprojectOps);
let topLeft;
let topRight;
const halfFov = viewport.fovy ? 0.5 * viewport.fovy * DEGREES_TO_RADIANS : Math.atan(0.5 / viewport.altitude);
const angleToGround = (90 - viewport.pitch) * DEGREES_TO_RADIANS;
var bottomLeft = unproject([0, height], unprojectOps);
var bottomRight = unproject([width, height], unprojectOps);
var topLeft;
var topRight;
var halfFov = viewport.fovy ? 0.5 * viewport.fovy * DEGREES_TO_RADIANS : Math.atan(0.5 / viewport.altitude);
var angleToGround = (90 - viewport.pitch) * DEGREES_TO_RADIANS;

@@ -49,14 +50,12 @@ if (halfFov > angleToGround - 0.01) {

function unprojectOnFarPlane(viewport, x, targetZ) {
const {
pixelUnprojectionMatrix
} = viewport;
const coord0 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, 0, 1, 1]);
const coord1 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);
const z = targetZ * viewport.distanceScales.unitsPerMeter[2];
const t = (z - coord0[2]) / (coord1[2] - coord0[2]);
const coord = vec2.lerp([], coord0, coord1, t);
const result = (0, _webMercatorUtils.worldToLngLat)(coord);
result[2] = targetZ;
var pixelUnprojectionMatrix = viewport.pixelUnprojectionMatrix;
var coord0 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, 0, 1, 1]);
var coord1 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);
var z = targetZ * viewport.distanceScales.unitsPerMeter[2];
var t = (z - coord0[2]) / (coord1[2] - coord0[2]);
var coord = vec2.lerp([], coord0, coord1, t);
var result = (0, _webMercatorUtils.worldToLngLat)(coord);
result.push(targetZ);
return result;
}
//# sourceMappingURL=get-bounds.js.map

@@ -5,2 +5,4 @@ "use strict";

var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -11,3 +13,3 @@ value: true

enumerable: true,
get: function () {
get: function get() {
return _webMercatorViewport.default;

@@ -18,3 +20,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _webMercatorViewport.default;

@@ -25,3 +27,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _getBounds.default;

@@ -32,3 +34,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _fitBounds.default;

@@ -39,3 +41,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _normalizeViewportProps.default;

@@ -46,3 +48,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _flyToViewport.default;

@@ -53,9 +55,15 @@ }

enumerable: true,
get: function () {
get: function get() {
return _flyToViewport.getFlyToDuration;
}
});
Object.defineProperty(exports, "MAX_LATITUDE", {
enumerable: true,
get: function get() {
return _webMercatorUtils.MAX_LATITUDE;
}
});
Object.defineProperty(exports, "lngLatToWorld", {
enumerable: true,
get: function () {
get: function get() {
return _webMercatorUtils.lngLatToWorld;

@@ -66,3 +74,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _webMercatorUtils.worldToLngLat;

@@ -73,3 +81,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _webMercatorUtils.worldToPixels;

@@ -80,3 +88,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _webMercatorUtils.pixelsToWorld;

@@ -87,3 +95,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _webMercatorUtils.zoomToScale;

@@ -94,3 +102,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _webMercatorUtils.scaleToZoom;

@@ -101,3 +109,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _webMercatorUtils.altitudeToFovy;

@@ -108,3 +116,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _webMercatorUtils.fovyToAltitude;

@@ -115,3 +123,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _webMercatorUtils.getMeterZoom;

@@ -122,3 +130,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _webMercatorUtils.getDistanceScales;

@@ -129,3 +137,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _webMercatorUtils.addMetersToLngLat;

@@ -136,3 +144,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _webMercatorUtils.getViewMatrix;

@@ -143,3 +151,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _webMercatorUtils.getProjectionMatrix;

@@ -150,3 +158,3 @@ }

enumerable: true,
get: function () {
get: function get() {
return _webMercatorUtils.getProjectionParameters;

@@ -168,5 +176,5 @@ }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
//# sourceMappingURL=index.js.map

@@ -10,2 +10,3 @@ "use strict";

exports.lerp = lerp;
exports.clamp = clamp;
exports.log2 = void 0;

@@ -20,3 +21,3 @@

function transformVector(matrix, vector) {
const result = (0, _vec.transformMat4)([], vector, matrix);
var result = (0, _vec.transformMat4)([], vector, matrix);
(0, _vec.scale)(result, result, 1 / result[3]);

@@ -27,3 +28,3 @@ return result;

function mod(value, divisor) {
const modulus = value % divisor;
var modulus = value % divisor;
return modulus < 0 ? divisor + modulus : modulus;

@@ -36,2 +37,6 @@ }

function clamp(x, min, max) {
return x < min ? min : x > max ? max : x;
}
function ieLog2(x) {

@@ -41,4 +46,4 @@ return Math.log(x) * Math.LOG2E;

const log2 = Math.log2 || ieLog2;
var log2 = Math.log2 || ieLog2;
exports.log2 = log2;
//# sourceMappingURL=math-utils.js.map

@@ -12,16 +12,14 @@ "use strict";

const TILE_SIZE = 512;
var TILE_SIZE = 512;
function normalizeViewportProps(props) {
const {
width,
height,
pitch = 0
} = props;
let {
longitude,
latitude,
zoom,
bearing = 0
} = props;
var width = props.width,
height = props.height,
_props$pitch = props.pitch,
pitch = _props$pitch === void 0 ? 0 : _props$pitch;
var longitude = props.longitude,
latitude = props.latitude,
zoom = props.zoom,
_props$bearing = props.bearing,
bearing = _props$bearing === void 0 ? 0 : _props$bearing;

@@ -36,3 +34,3 @@ if (longitude < -180 || longitude > 180) {

const minZoom = (0, _mathUtils.log2)(height / TILE_SIZE);
var minZoom = (0, _mathUtils.log2)(height / TILE_SIZE);

@@ -43,4 +41,4 @@ if (zoom <= minZoom) {

} else {
const halfHeightPixels = height / 2 / Math.pow(2, zoom);
const minLatitude = (0, _webMercatorUtils.worldToLngLat)([0, halfHeightPixels])[1];
var halfHeightPixels = height / 2 / Math.pow(2, zoom);
var minLatitude = (0, _webMercatorUtils.worldToLngLat)([0, halfHeightPixels])[1];

@@ -50,3 +48,3 @@ if (latitude < minLatitude) {

} else {
const maxLatitude = (0, _webMercatorUtils.worldToLngLat)([0, TILE_SIZE - halfHeightPixels])[1];
var maxLatitude = (0, _webMercatorUtils.worldToLngLat)([0, TILE_SIZE - halfHeightPixels])[1];

@@ -60,11 +58,11 @@ if (latitude > maxLatitude) {

return {
width,
height,
longitude,
latitude,
zoom,
pitch,
bearing
width: width,
height: height,
longitude: longitude,
latitude: latitude,
zoom: zoom,
pitch: pitch,
bearing: bearing
};
}
//# sourceMappingURL=normalize-viewport-props.js.map

@@ -5,2 +5,4 @@ "use strict";

var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -23,4 +25,6 @@ value: true

exports.pixelsToWorld = pixelsToWorld;
exports.DEFAULT_ALTITUDE = void 0;
exports.DEFAULT_ALTITUDE = exports.MAX_LATITUDE = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _mathUtils = require("./math-utils");

@@ -36,13 +40,15 @@

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const PI = Math.PI;
const PI_4 = PI / 4;
const DEGREES_TO_RADIANS = PI / 180;
const RADIANS_TO_DEGREES = 180 / PI;
const TILE_SIZE = 512;
const EARTH_CIRCUMFERENCE = 40.03e6;
const DEFAULT_ALTITUDE = 1.5;
var PI = Math.PI;
var PI_4 = PI / 4;
var DEGREES_TO_RADIANS = PI / 180;
var RADIANS_TO_DEGREES = 180 / PI;
var TILE_SIZE = 512;
var EARTH_CIRCUMFERENCE = 40.03e6;
var MAX_LATITUDE = 85.051129;
exports.MAX_LATITUDE = MAX_LATITUDE;
var DEFAULT_ALTITUDE = 1.5;
exports.DEFAULT_ALTITUDE = DEFAULT_ALTITUDE;

@@ -59,9 +65,12 @@

function lngLatToWorld(lngLat) {
const [lng, lat] = lngLat;
var _lngLat = (0, _slicedToArray2.default)(lngLat, 2),
lng = _lngLat[0],
lat = _lngLat[1];
(0, _assert.default)(Number.isFinite(lng));
(0, _assert.default)(Number.isFinite(lat) && lat >= -90 && lat <= 90, 'invalid latitude');
const lambda2 = lng * DEGREES_TO_RADIANS;
const phi2 = lat * DEGREES_TO_RADIANS;
const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
var lambda2 = lng * DEGREES_TO_RADIANS;
var phi2 = lat * DEGREES_TO_RADIANS;
var x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
var y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
return [x, y];

@@ -71,5 +80,8 @@ }

function worldToLngLat(xy) {
const [x, y] = xy;
const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
var _xy = (0, _slicedToArray2.default)(xy, 2),
x = _xy[0],
y = _xy[1];
var lambda2 = x / TILE_SIZE * (2 * PI) - PI;
var phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
return [lambda2 * RADIANS_TO_DEGREES, phi2 * RADIANS_TO_DEGREES];

@@ -79,7 +91,5 @@ }

function getMeterZoom(options) {
const {
latitude
} = options;
var latitude = options.latitude;
(0, _assert.default)(Number.isFinite(latitude));
const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
var latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
return scaleToZoom(EARTH_CIRCUMFERENCE * latCosine) - 9;

@@ -89,14 +99,13 @@ }

function getDistanceScales(options) {
const {
latitude,
longitude,
highPrecision = false
} = options;
var latitude = options.latitude,
longitude = options.longitude,
_options$highPrecisio = options.highPrecision,
highPrecision = _options$highPrecisio === void 0 ? false : _options$highPrecisio;
(0, _assert.default)(Number.isFinite(latitude) && Number.isFinite(longitude));
const worldSize = TILE_SIZE;
const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
const unitsPerDegreeX = worldSize / 360;
const unitsPerDegreeY = unitsPerDegreeX / latCosine;
const altUnitsPerMeter = worldSize / EARTH_CIRCUMFERENCE / latCosine;
const result = {
var worldSize = TILE_SIZE;
var latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
var unitsPerDegreeX = worldSize / 360;
var unitsPerDegreeY = unitsPerDegreeX / latCosine;
var altUnitsPerMeter = worldSize / EARTH_CIRCUMFERENCE / latCosine;
var result = {
unitsPerMeter: [altUnitsPerMeter, altUnitsPerMeter, altUnitsPerMeter],

@@ -109,6 +118,6 @@ metersPerUnit: [1 / altUnitsPerMeter, 1 / altUnitsPerMeter, 1 / altUnitsPerMeter],

if (highPrecision) {
const latCosine2 = DEGREES_TO_RADIANS * Math.tan(latitude * DEGREES_TO_RADIANS) / latCosine;
const unitsPerDegreeY2 = unitsPerDegreeX * latCosine2 / 2;
const altUnitsPerDegree2 = worldSize / EARTH_CIRCUMFERENCE * latCosine2;
const altUnitsPerMeter2 = altUnitsPerDegree2 / unitsPerDegreeY * altUnitsPerMeter;
var latCosine2 = DEGREES_TO_RADIANS * Math.tan(latitude * DEGREES_TO_RADIANS) / latCosine;
var unitsPerDegreeY2 = unitsPerDegreeX * latCosine2 / 2;
var altUnitsPerDegree2 = worldSize / EARTH_CIRCUMFERENCE * latCosine2;
var altUnitsPerMeter2 = altUnitsPerDegree2 / unitsPerDegreeY * altUnitsPerMeter;
result.unitsPerDegree2 = [0, unitsPerDegreeY2, altUnitsPerDegree2];

@@ -122,17 +131,25 @@ result.unitsPerMeter2 = [altUnitsPerMeter2, 0, altUnitsPerMeter2];

function addMetersToLngLat(lngLatZ, xyz) {
const [longitude, latitude, z0] = lngLatZ;
const [x, y, z] = xyz;
const {
unitsPerMeter,
unitsPerMeter2
} = getDistanceScales({
longitude,
latitude,
var _lngLatZ = (0, _slicedToArray2.default)(lngLatZ, 3),
longitude = _lngLatZ[0],
latitude = _lngLatZ[1],
z0 = _lngLatZ[2];
var _xyz = (0, _slicedToArray2.default)(xyz, 3),
x = _xyz[0],
y = _xyz[1],
z = _xyz[2];
var _getDistanceScales = getDistanceScales({
longitude: longitude,
latitude: latitude,
highPrecision: true
});
const worldspace = lngLatToWorld(lngLatZ);
}),
unitsPerMeter = _getDistanceScales.unitsPerMeter,
unitsPerMeter2 = _getDistanceScales.unitsPerMeter2;
var worldspace = lngLatToWorld(lngLatZ);
worldspace[0] += x * (unitsPerMeter[0] + unitsPerMeter2[0] * y);
worldspace[1] += y * (unitsPerMeter[1] + unitsPerMeter2[1] * y);
const newLngLat = worldToLngLat(worldspace);
const newZ = (z0 || 0) + (z || 0);
var newLngLat = worldToLngLat(worldspace);
var newZ = (z0 || 0) + (z || 0);
return Number.isFinite(z0) || Number.isFinite(z) ? [newLngLat[0], newLngLat[1], newZ] : newLngLat;

@@ -142,15 +159,13 @@ }

function getViewMatrix(options) {
const {
height,
pitch,
bearing,
altitude,
scale,
center = null
} = options;
const vm = (0, _mathUtils.createMat4)();
var height = options.height,
pitch = options.pitch,
bearing = options.bearing,
altitude = options.altitude,
scale = options.scale,
center = options.center;
var vm = (0, _mathUtils.createMat4)();
mat4.translate(vm, vm, [0, 0, -altitude]);
mat4.rotateX(vm, vm, -pitch * DEGREES_TO_RADIANS);
mat4.rotateZ(vm, vm, bearing * DEGREES_TO_RADIANS);
const relativeScale = scale / height;
var relativeScale = scale / height;
mat4.scale(vm, vm, [relativeScale, relativeScale, relativeScale]);

@@ -166,13 +181,13 @@

function getProjectionParameters(options) {
const {
width,
height,
altitude,
pitch = 0,
nearZMultiplier = 1,
farZMultiplier = 1
} = options;
let {
fovy = altitudeToFovy(DEFAULT_ALTITUDE)
} = options;
var width = options.width,
height = options.height,
altitude = options.altitude,
_options$pitch = options.pitch,
pitch = _options$pitch === void 0 ? 0 : _options$pitch,
_options$nearZMultipl = options.nearZMultiplier,
nearZMultiplier = _options$nearZMultipl === void 0 ? 1 : _options$nearZMultipl,
_options$farZMultipli = options.farZMultiplier,
farZMultiplier = _options$farZMultipli === void 0 ? 1 : _options$farZMultipli;
var _options$fovy = options.fovy,
fovy = _options$fovy === void 0 ? altitudeToFovy(DEFAULT_ALTITUDE) : _options$fovy;

@@ -183,11 +198,11 @@ if (altitude !== undefined) {

const halfFov = 0.5 * fovy * DEGREES_TO_RADIANS;
const focalDistance = fovyToAltitude(fovy);
const pitchRadians = pitch * DEGREES_TO_RADIANS;
const topHalfSurfaceDistance = Math.sin(halfFov) * focalDistance / Math.sin(Math.min(Math.max(Math.PI / 2 - pitchRadians - halfFov, 0.01), Math.PI - 0.01));
const farZ = Math.sin(pitchRadians) * topHalfSurfaceDistance + focalDistance;
var halfFov = 0.5 * fovy * DEGREES_TO_RADIANS;
var focalDistance = fovyToAltitude(fovy);
var pitchRadians = pitch * DEGREES_TO_RADIANS;
var topHalfSurfaceDistance = Math.sin(halfFov) * focalDistance / Math.sin(Math.min(Math.max(Math.PI / 2 - pitchRadians - halfFov, 0.01), Math.PI - 0.01));
var farZ = Math.sin(pitchRadians) * topHalfSurfaceDistance + focalDistance;
return {
fov: 2 * halfFov,
aspect: width / height,
focalDistance,
focalDistance: focalDistance,
near: nearZMultiplier,

@@ -199,9 +214,9 @@ far: farZ * farZMultiplier

function getProjectionMatrix(options) {
const {
fov,
aspect,
near,
far
} = getProjectionParameters(options);
const projectionMatrix = mat4.perspective([], fov, aspect, near, far);
var _getProjectionParamet = getProjectionParameters(options),
fov = _getProjectionParamet.fov,
aspect = _getProjectionParamet.aspect,
near = _getProjectionParamet.near,
far = _getProjectionParamet.far;
var projectionMatrix = mat4.perspective([], fov, aspect, near, far);
return projectionMatrix;

@@ -219,3 +234,8 @@ }

function worldToPixels(xyz, pixelProjectionMatrix) {
const [x, y, z = 0] = xyz;
var _xyz2 = (0, _slicedToArray2.default)(xyz, 3),
x = _xyz2[0],
y = _xyz2[1],
_xyz2$ = _xyz2[2],
z = _xyz2$ === void 0 ? 0 : _xyz2$;
(0, _assert.default)(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z));

@@ -225,18 +245,24 @@ return (0, _mathUtils.transformVector)(pixelProjectionMatrix, [x, y, z, 1]);

function pixelsToWorld(xyz, pixelUnprojectionMatrix, targetZ = 0) {
const [x, y, z] = xyz;
function pixelsToWorld(xyz, pixelUnprojectionMatrix) {
var targetZ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var _xyz3 = (0, _slicedToArray2.default)(xyz, 3),
x = _xyz3[0],
y = _xyz3[1],
z = _xyz3[2];
(0, _assert.default)(Number.isFinite(x) && Number.isFinite(y), 'invalid pixel coordinate');
if (Number.isFinite(z)) {
const coord = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, y, z, 1]);
var coord = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, y, z, 1]);
return coord;
}
const coord0 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, y, 0, 1]);
const coord1 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, y, 1, 1]);
const z0 = coord0[2];
const z1 = coord1[2];
const t = z0 === z1 ? 0 : ((targetZ || 0) - z0) / (z1 - z0);
var coord0 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, y, 0, 1]);
var coord1 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, y, 1, 1]);
var z0 = coord0[2];
var z1 = coord1[2];
var t = z0 === z1 ? 0 : ((targetZ || 0) - z0) / (z1 - z0);
return vec2.lerp([], coord0, coord1, t);
}
//# sourceMappingURL=web-mercator-utils.js.map

@@ -5,2 +5,4 @@ "use strict";

var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -11,2 +13,10 @@ value: true

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

@@ -18,3 +28,3 @@

var _fitBounds = _interopRequireDefault(require("./fit-bounds"));
var _fitBounds3 = _interopRequireDefault(require("./fit-bounds"));

@@ -29,11 +39,13 @@ var _getBounds = _interopRequireDefault(require("./get-bounds"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
class WebMercatorViewport {
constructor(props = {
width: 1,
height: 1
}) {
var WebMercatorViewport = function () {
function WebMercatorViewport() {
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
width: 1,
height: 1
};
(0, _classCallCheck2.default)(this, WebMercatorViewport);
(0, _defineProperty2.default)(this, "latitude", void 0);

@@ -57,18 +69,24 @@ (0, _defineProperty2.default)(this, "longitude", void 0);

(0, _defineProperty2.default)(this, "pixelUnprojectionMatrix", void 0);
let {
width,
height,
altitude = null,
fovy = null
} = props;
const {
latitude = 0,
longitude = 0,
zoom = 0,
pitch = 0,
bearing = 0,
position = null,
nearZMultiplier = 0.02,
farZMultiplier = 1.01
} = props;
var width = props.width,
height = props.height,
_props$altitude = props.altitude,
altitude = _props$altitude === void 0 ? null : _props$altitude,
_props$fovy = props.fovy,
fovy = _props$fovy === void 0 ? null : _props$fovy;
var _props$latitude = props.latitude,
latitude = _props$latitude === void 0 ? 0 : _props$latitude,
_props$longitude = props.longitude,
longitude = _props$longitude === void 0 ? 0 : _props$longitude,
_props$zoom = props.zoom,
zoom = _props$zoom === void 0 ? 0 : _props$zoom,
_props$pitch = props.pitch,
pitch = _props$pitch === void 0 ? 0 : _props$pitch,
_props$bearing = props.bearing,
bearing = _props$bearing === void 0 ? 0 : _props$bearing,
_props$position = props.position,
position = _props$position === void 0 ? null : _props$position,
_props$nearZMultiplie = props.nearZMultiplier,
nearZMultiplier = _props$nearZMultiplie === void 0 ? 0.02 : _props$nearZMultiplie,
_props$farZMultiplier = props.farZMultiplier,
farZMultiplier = _props$farZMultiplier === void 0 ? 1.01 : _props$farZMultiplier;
width = width || 1;

@@ -86,10 +104,10 @@ height = height || 1;

const scale = (0, _webMercatorUtils.zoomToScale)(zoom);
var scale = (0, _webMercatorUtils.zoomToScale)(zoom);
altitude = Math.max(0.75, altitude);
const distanceScales = (0, _webMercatorUtils.getDistanceScales)({
longitude,
latitude
var distanceScales = (0, _webMercatorUtils.getDistanceScales)({
longitude: longitude,
latitude: latitude
});
const center = (0, _webMercatorUtils.lngLatToWorld)([longitude, latitude]);
center[2] = 0;
var center = (0, _webMercatorUtils.lngLatToWorld)([longitude, latitude]);
center.push(0);

@@ -101,16 +119,16 @@ if (position) {

this.projectionMatrix = (0, _webMercatorUtils.getProjectionMatrix)({
width,
height,
pitch,
fovy,
nearZMultiplier,
farZMultiplier
width: width,
height: height,
pitch: pitch,
fovy: fovy,
nearZMultiplier: nearZMultiplier,
farZMultiplier: farZMultiplier
});
this.viewMatrix = (0, _webMercatorUtils.getViewMatrix)({
height,
scale,
center,
pitch,
bearing,
altitude
height: height,
scale: scale,
center: center,
pitch: pitch,
bearing: bearing,
altitude: altitude
});

@@ -141,144 +159,187 @@ this.width = width;

_initMatrices() {
const {
width,
height,
projectionMatrix,
viewMatrix
} = this;
const vpm = (0, _mathUtils.createMat4)();
mat4.multiply(vpm, vpm, projectionMatrix);
mat4.multiply(vpm, vpm, viewMatrix);
this.viewProjectionMatrix = vpm;
const m = (0, _mathUtils.createMat4)();
mat4.scale(m, m, [width / 2, -height / 2, 1]);
mat4.translate(m, m, [1, -1, 0]);
mat4.multiply(m, m, vpm);
const mInverse = mat4.invert((0, _mathUtils.createMat4)(), m);
(0, _createClass2.default)(WebMercatorViewport, [{
key: "_initMatrices",
value: function _initMatrices() {
var width = this.width,
height = this.height,
projectionMatrix = this.projectionMatrix,
viewMatrix = this.viewMatrix;
var vpm = (0, _mathUtils.createMat4)();
mat4.multiply(vpm, vpm, projectionMatrix);
mat4.multiply(vpm, vpm, viewMatrix);
this.viewProjectionMatrix = vpm;
var m = (0, _mathUtils.createMat4)();
mat4.scale(m, m, [width / 2, -height / 2, 1]);
mat4.translate(m, m, [1, -1, 0]);
mat4.multiply(m, m, vpm);
var mInverse = mat4.invert((0, _mathUtils.createMat4)(), m);
if (!mInverse) {
throw new Error('Pixel project matrix not invertible');
if (!mInverse) {
throw new Error('Pixel project matrix not invertible');
}
this.pixelProjectionMatrix = m;
this.pixelUnprojectionMatrix = mInverse;
}
}, {
key: "equals",
value: function equals(viewport) {
if (!(viewport instanceof WebMercatorViewport)) {
return false;
}
this.pixelProjectionMatrix = m;
this.pixelUnprojectionMatrix = mInverse;
}
equals(viewport) {
if (!(viewport instanceof WebMercatorViewport)) {
return false;
return viewport.width === this.width && viewport.height === this.height && mat4.equals(viewport.projectionMatrix, this.projectionMatrix) && mat4.equals(viewport.viewMatrix, this.viewMatrix);
}
}, {
key: "project",
value: function project(lngLatZ) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _options$topLeft = options.topLeft,
topLeft = _options$topLeft === void 0 ? true : _options$topLeft;
var worldPosition = this.projectPosition(lngLatZ);
var coord = (0, _webMercatorUtils.worldToPixels)(worldPosition, this.pixelProjectionMatrix);
return viewport.width === this.width && viewport.height === this.height && mat4.equals(viewport.projectionMatrix, this.projectionMatrix) && mat4.equals(viewport.viewMatrix, this.viewMatrix);
}
var _coord = (0, _slicedToArray2.default)(coord, 2),
x = _coord[0],
y = _coord[1];
project(lngLatZ, options = {}) {
const {
topLeft = true
} = options;
const worldPosition = this.projectPosition(lngLatZ);
const coord = (0, _webMercatorUtils.worldToPixels)(worldPosition, this.pixelProjectionMatrix);
const [x, y] = coord;
const y2 = topLeft ? y : this.height - y;
return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];
}
unproject(xyz, options = {}) {
const {
topLeft = true,
targetZ = undefined
} = options;
const [x, y, z] = xyz;
const y2 = topLeft ? y : this.height - y;
const targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];
const coord = (0, _webMercatorUtils.pixelsToWorld)([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);
const [X, Y, Z] = this.unprojectPosition(coord);
if (Number.isFinite(z)) {
return [X, Y, Z];
var y2 = topLeft ? y : this.height - y;
return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];
}
}, {
key: "unproject",
value: function unproject(xyz) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _options$topLeft2 = options.topLeft,
topLeft = _options$topLeft2 === void 0 ? true : _options$topLeft2,
_options$targetZ = options.targetZ,
targetZ = _options$targetZ === void 0 ? undefined : _options$targetZ;
return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];
}
var _xyz = (0, _slicedToArray2.default)(xyz, 3),
x = _xyz[0],
y = _xyz[1],
z = _xyz[2];
projectPosition(xyz) {
const [X, Y] = (0, _webMercatorUtils.lngLatToWorld)(xyz);
const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];
return [X, Y, Z];
}
var y2 = topLeft ? y : this.height - y;
var targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];
var coord = (0, _webMercatorUtils.pixelsToWorld)([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);
unprojectPosition(xyz) {
const [X, Y] = (0, _webMercatorUtils.worldToLngLat)(xyz);
const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];
return [X, Y, Z];
}
var _this$unprojectPositi = this.unprojectPosition(coord),
_this$unprojectPositi2 = (0, _slicedToArray2.default)(_this$unprojectPositi, 3),
X = _this$unprojectPositi2[0],
Y = _this$unprojectPositi2[1],
Z = _this$unprojectPositi2[2];
projectFlat(lngLat) {
return (0, _webMercatorUtils.lngLatToWorld)(lngLat);
}
if (Number.isFinite(z)) {
return [X, Y, Z];
}
unprojectFlat(xy) {
return (0, _webMercatorUtils.worldToLngLat)(xy);
}
return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];
}
}, {
key: "projectPosition",
value: function projectPosition(xyz) {
var _lngLatToWorld = (0, _webMercatorUtils.lngLatToWorld)(xyz),
_lngLatToWorld2 = (0, _slicedToArray2.default)(_lngLatToWorld, 2),
X = _lngLatToWorld2[0],
Y = _lngLatToWorld2[1];
getMapCenterByLngLatPosition({
lngLat,
pos
}) {
const fromLocation = (0, _webMercatorUtils.pixelsToWorld)(pos, this.pixelUnprojectionMatrix);
const toLocation = (0, _webMercatorUtils.lngLatToWorld)(lngLat);
const translate = vec2.add([], toLocation, vec2.negate([], fromLocation));
const newCenter = vec2.add([], this.center, translate);
return (0, _webMercatorUtils.worldToLngLat)(newCenter);
}
var Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];
return [X, Y, Z];
}
}, {
key: "unprojectPosition",
value: function unprojectPosition(xyz) {
var _worldToLngLat = (0, _webMercatorUtils.worldToLngLat)(xyz),
_worldToLngLat2 = (0, _slicedToArray2.default)(_worldToLngLat, 2),
X = _worldToLngLat2[0],
Y = _worldToLngLat2[1];
fitBounds(bounds, options = {}) {
const {
width,
height
} = this;
const {
longitude,
latitude,
zoom
} = (0, _fitBounds.default)(Object.assign({
width,
height,
bounds
}, options));
return new WebMercatorViewport({
width,
height,
longitude,
latitude,
zoom
});
}
var Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];
return [X, Y, Z];
}
}, {
key: "projectFlat",
value: function projectFlat(lngLat) {
return (0, _webMercatorUtils.lngLatToWorld)(lngLat);
}
}, {
key: "unprojectFlat",
value: function unprojectFlat(xy) {
return (0, _webMercatorUtils.worldToLngLat)(xy);
}
}, {
key: "getMapCenterByLngLatPosition",
value: function getMapCenterByLngLatPosition(_ref) {
var lngLat = _ref.lngLat,
pos = _ref.pos;
var fromLocation = (0, _webMercatorUtils.pixelsToWorld)(pos, this.pixelUnprojectionMatrix);
var toLocation = (0, _webMercatorUtils.lngLatToWorld)(lngLat);
var translate = vec2.add([], toLocation, vec2.negate([], fromLocation));
var newCenter = vec2.add([], this.center, translate);
return (0, _webMercatorUtils.worldToLngLat)(newCenter);
}
}, {
key: "fitBounds",
value: function fitBounds(bounds) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var width = this.width,
height = this.height;
getBounds(options) {
const corners = this.getBoundingRegion(options);
const west = Math.min(...corners.map(p => p[0]));
const east = Math.max(...corners.map(p => p[0]));
const south = Math.min(...corners.map(p => p[1]));
const north = Math.max(...corners.map(p => p[1]));
return [[west, south], [east, north]];
}
var _fitBounds2 = (0, _fitBounds3.default)(Object.assign({
width: width,
height: height,
bounds: bounds
}, options)),
longitude = _fitBounds2.longitude,
latitude = _fitBounds2.latitude,
zoom = _fitBounds2.zoom;
getBoundingRegion(options = {}) {
return (0, _getBounds.default)(this, options.z || 0);
}
return new WebMercatorViewport({
width: width,
height: height,
longitude: longitude,
latitude: latitude,
zoom: zoom
});
}
}, {
key: "getBounds",
value: function getBounds(options) {
var corners = this.getBoundingRegion(options);
var west = Math.min.apply(Math, (0, _toConsumableArray2.default)(corners.map(function (p) {
return p[0];
})));
var east = Math.max.apply(Math, (0, _toConsumableArray2.default)(corners.map(function (p) {
return p[0];
})));
var south = Math.min.apply(Math, (0, _toConsumableArray2.default)(corners.map(function (p) {
return p[1];
})));
var north = Math.max.apply(Math, (0, _toConsumableArray2.default)(corners.map(function (p) {
return p[1];
})));
return [[west, south], [east, north]];
}
}, {
key: "getBoundingRegion",
value: function getBoundingRegion() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return (0, _getBounds.default)(this, options.z || 0);
}
}, {
key: "getLocationAtPoint",
value: function getLocationAtPoint(_ref2) {
var lngLat = _ref2.lngLat,
pos = _ref2.pos;
return this.getMapCenterByLngLatPosition({
lngLat: lngLat,
pos: pos
});
}
}]);
return WebMercatorViewport;
}();
getLocationAtPoint({
lngLat,
pos
}) {
return this.getMapCenterByLngLatPosition({
lngLat,
pos
});
}
}
exports.default = WebMercatorViewport;
//# sourceMappingURL=web-mercator-viewport.js.map

@@ -1,4 +0,4 @@

import WebMercatorViewport from './web-mercator-viewport';
import assert from './assert';
import { log2 } from './math-utils';
import { log2, clamp } from './math-utils';
import { MAX_LATITUDE, lngLatToWorld, worldToLngLat } from './web-mercator-utils';
export default function fitBounds(options) {

@@ -15,11 +15,4 @@ const {

const padding = getPaddingObject(options.padding);
const viewport = new WebMercatorViewport({
width,
height,
longitude: 0,
latitude: 0,
zoom: 0
});
const nw = viewport.project([west, north]);
const se = viewport.project([east, south]);
const nw = lngLatToWorld([west, clamp(north, -MAX_LATITUDE, MAX_LATITUDE)]);
const se = lngLatToWorld([east, clamp(south, -MAX_LATITUDE, MAX_LATITUDE)]);
const size = [Math.max(Math.abs(se[0] - nw[0]), minExtent), Math.max(Math.abs(se[1] - nw[1]), minExtent)];

@@ -33,4 +26,4 @@ const targetSize = [width - padding.left - padding.right - Math.abs(offset[0]) * 2, height - padding.top - padding.bottom - Math.abs(offset[1]) * 2];

const center = [(se[0] + nw[0]) / 2 + offsetX, (se[1] + nw[1]) / 2 + offsetY];
const centerLngLat = viewport.unproject(center);
const zoom = Math.min(maxZoom, viewport.zoom + log2(Math.abs(Math.min(scaleX, scaleY))));
const centerLngLat = worldToLngLat(center);
const zoom = Math.min(maxZoom, log2(Math.abs(Math.min(scaleX, scaleY))));
assert(Number.isFinite(zoom));

@@ -37,0 +30,0 @@ return {

@@ -42,5 +42,5 @@ import { worldToLngLat } from './web-mercator-utils';

const result = worldToLngLat(coord);
result[2] = targetZ;
result.push(targetZ);
return result;
}
//# sourceMappingURL=get-bounds.js.map

@@ -7,3 +7,3 @@ export { default } from './web-mercator-viewport';

export { default as flyToViewport, getFlyToDuration } from './fly-to-viewport';
export { lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
export { MAX_LATITUDE, lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
//# sourceMappingURL=index.js.map

@@ -17,2 +17,5 @@ import { transformMat4, scale } from 'gl-matrix/vec4';

}
export function clamp(x, min, max) {
return x < min ? min : x > max ? max : x;
}

@@ -19,0 +22,0 @@ function ieLog2(x) {

@@ -12,2 +12,3 @@ import { createMat4, transformVector, log2 } from './math-utils';

const EARTH_CIRCUMFERENCE = 40.03e6;
export const MAX_LATITUDE = 85.051129;
export const DEFAULT_ALTITUDE = 1.5;

@@ -99,3 +100,3 @@ export function zoomToScale(zoom) {

scale,
center = null
center
} = options;

@@ -102,0 +103,0 @@ const vm = createMat4();

@@ -85,3 +85,3 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

const center = lngLatToWorld([longitude, latitude]);
center[2] = 0;
center.push(0);

@@ -88,0 +88,0 @@ if (position) {

@@ -34,3 +34,3 @@ /**

};
export declare type Bounds = {
declare type ViewportProps = {
longitude: number;

@@ -49,3 +49,4 @@ latitude: number;

*/
export default function fitBounds(options: FitBoundsOptions): Bounds;
export default function fitBounds(options: FitBoundsOptions): ViewportProps;
export {};
//# sourceMappingURL=fit-bounds.d.ts.map

@@ -1,4 +0,4 @@

import WebMercatorViewport from './web-mercator-viewport';
import assert from './assert';
import { log2 } from './math-utils';
import { log2, clamp } from './math-utils';
import { MAX_LATITUDE, lngLatToWorld, worldToLngLat } from './web-mercator-utils';
/**

@@ -19,11 +19,4 @@ * Returns map settings {latitude, longitude, zoom}

const padding = getPaddingObject(options.padding);
const viewport = new WebMercatorViewport({
width,
height,
longitude: 0,
latitude: 0,
zoom: 0
});
const nw = viewport.project([west, north]);
const se = viewport.project([east, south]);
const nw = lngLatToWorld([west, clamp(north, -MAX_LATITUDE, MAX_LATITUDE)]);
const se = lngLatToWorld([east, clamp(south, -MAX_LATITUDE, MAX_LATITUDE)]);
// width/height on the Web Mercator plane

@@ -46,4 +39,4 @@ const size = [

const center = [(se[0] + nw[0]) / 2 + offsetX, (se[1] + nw[1]) / 2 + offsetY];
const centerLngLat = viewport.unproject(center);
const zoom = Math.min(maxZoom, viewport.zoom + log2(Math.abs(Math.min(scaleX, scaleY))));
const centerLngLat = worldToLngLat(center);
const zoom = Math.min(maxZoom, log2(Math.abs(Math.min(scaleX, scaleY))));
assert(Number.isFinite(zoom));

@@ -50,0 +43,0 @@ return {

@@ -0,1 +1,2 @@

import type { ViewportProps } from './normalize-viewport-props';
export declare type FlytoTransitionOptions = {

@@ -7,7 +8,2 @@ curve?: number;

};
export declare type ViewportProps = {
longitude: number;
latitude: number;
zoom: number;
};
/**

@@ -18,4 +14,8 @@ * mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.

*/
export default function flyToViewport(startProps: ViewportProps, endProps: ViewportProps, t: number, options?: FlytoTransitionOptions): ViewportProps;
export default function flyToViewport(startProps: ViewportProps, endProps: ViewportProps, t: number, options?: FlytoTransitionOptions): {
longitude: number;
latitude: number;
zoom: number;
};
export declare function getFlyToDuration(startProps: ViewportProps, endProps: ViewportProps, options?: FlytoTransitionOptions): number;
//# sourceMappingURL=fly-to-viewport.d.ts.map

@@ -49,4 +49,4 @@ import { worldToLngLat } from './web-mercator-utils';

const result = worldToLngLat(coord);
result[2] = targetZ;
result.push(targetZ);
return result;
}

@@ -7,3 +7,6 @@ export { default } from './web-mercator-viewport';

export { default as flyToViewport, getFlyToDuration } from './fly-to-viewport';
export { lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
export { MAX_LATITUDE, lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
/** Types */
export type { FitBoundsOptions } from './fit-bounds';
export type { DistanceScales } from './web-mercator-utils';
//# sourceMappingURL=index.d.ts.map

@@ -8,2 +8,2 @@ // Classic web-mercator-project

export { default as flyToViewport, getFlyToDuration } from './fly-to-viewport';
export { lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
export { MAX_LATITUDE, lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
export declare function createMat4(): number[];
export declare function transformVector(matrix: any, vector: any): any;
export declare function transformVector(matrix: number[], vector: number[]): number[];
export declare function mod(value: number, divisor: number): number;
export declare function lerp(start: number, end: number, step: number): number;
export declare function clamp(x: number, min: number, max: number): number;
export declare const log2: (x: number) => number;
//# sourceMappingURL=math-utils.d.ts.map

@@ -19,2 +19,5 @@ import { transformMat4, scale } from 'gl-matrix/vec4';

}
export function clamp(x, min, max) {
return x < min ? min : x > max ? max : x;
}
function ieLog2(x) {

@@ -21,0 +24,0 @@ return Math.log(x) * Math.LOG2E;

/** Description of viewport */
declare type ViewportProps = {
export declare type ViewportProps = {
width: number;

@@ -16,3 +16,2 @@ height: number;

export default function normalizeViewportProps(props: ViewportProps): ViewportProps;
export {};
//# sourceMappingURL=normalize-viewport-props.d.ts.map

@@ -0,1 +1,2 @@

export declare const MAX_LATITUDE = 85.051129;
export declare const DEFAULT_ALTITUDE = 1.5;

@@ -41,3 +42,3 @@ export declare type DistanceScales = {

*/
export declare function lngLatToWorld(lngLat: number[]): number[];
export declare function lngLatToWorld(lngLat: number[]): [number, number];
/**

@@ -52,3 +53,3 @@ * Unproject world point [x,y] on map onto {lat, lon} on sphere

*/
export declare function worldToLngLat(xy: number[]): number[];
export declare function worldToLngLat(xy: number[]): [number, number];
/**

@@ -88,3 +89,3 @@ * Returns the zoom level that gives a 1 meter pixel at a certain latitude

scale: number;
center: number[];
center?: number[];
}): number[];

@@ -91,0 +92,0 @@ /**

@@ -15,2 +15,4 @@ // TODO - THE UTILITIES IN THIS FILE SHOULD BE IMPORTED FROM WEB-MERCATOR-VIEWPORT MODULE

const EARTH_CIRCUMFERENCE = 40.03e6;
// Latitude that makes a square world, 2 * atan(E ** PI) - PI / 2
export const MAX_LATITUDE = 85.051129;
// Mapbox default altitude

@@ -139,3 +141,2 @@ export const DEFAULT_ALTITUDE = 1.5;

worldspace[1] += y * (unitsPerMeter[1] + unitsPerMeter2[1] * y);
// @ts-ignore
const newLngLat = worldToLngLat(worldspace);

@@ -156,3 +157,3 @@ const newZ = (z0 || 0) + (z || 0);

// Pre-calculated parameters
scale, center = null } = options;
scale, center } = options;
// VIEW MATRIX: PROJECTS MERCATOR WORLD COORDINATES

@@ -159,0 +160,0 @@ // Note that mercator world coordinates typically need to be flipped

@@ -0,1 +1,2 @@

import { DistanceScales } from './web-mercator-utils';
import type { FitBoundsOptions } from './fit-bounds';

@@ -60,5 +61,3 @@ /**

readonly scale: number;
readonly distanceScales: {
unitsPerMeter: number[];
};
readonly distanceScales: DistanceScales;
readonly viewMatrix: number[];

@@ -113,4 +112,4 @@ readonly projectionMatrix: number[];

}): number[];
projectPosition(xyz: any): number[];
unprojectPosition(xyz: any): number[];
projectPosition(xyz: number[]): [number, number, number];
unprojectPosition(xyz: number[]): [number, number, number];
/**

@@ -117,0 +116,0 @@ * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.

@@ -52,3 +52,3 @@ // View and Projection Matrix calculations for mapbox-js style map view properties

const center = lngLatToWorld([longitude, latitude]);
center[2] = 0;
center.push(0);
if (position) {

@@ -192,3 +192,2 @@ vec3.add(center, center, vec3.mul([], position, distanceScales.unitsPerMeter));

const [X, Y] = worldToLngLat(xyz);
// @ts-expect-error
const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];

@@ -195,0 +194,0 @@ return [X, Y, Z];

@@ -6,3 +6,3 @@ {

"license": "MIT",
"version": "3.6.0-alpha.1",
"version": "3.6.0-alpha.2",
"keywords": [

@@ -31,3 +31,3 @@ "webgl",

"@babel/runtime": "^7.12.0",
"gl-matrix": "~3.3.0"
"gl-matrix": "^3.4.0"
},

@@ -38,3 +38,3 @@ "devDependencies": {

},
"gitHead": "45386981340895bf201c2ebb76257c9bbffd8ff6"
"gitHead": "ea7dc265c98b68af56218302d1d42b7d65f74ccb"
}

@@ -1,4 +0,4 @@

import WebMercatorViewport from './web-mercator-viewport';
import assert from './assert';
import {log2} from './math-utils';
import {log2, clamp} from './math-utils';
import {MAX_LATITUDE, lngLatToWorld, worldToLngLat} from './web-mercator-utils';

@@ -41,3 +41,3 @@ /**

export type Bounds = {
type ViewportProps = {
longitude: number;

@@ -57,3 +57,3 @@ latitude: number;

*/
export default function fitBounds(options: FitBoundsOptions): Bounds {
export default function fitBounds(options: FitBoundsOptions): ViewportProps {
const {

@@ -71,13 +71,5 @@ width,

const viewport = new WebMercatorViewport({
width,
height,
longitude: 0,
latitude: 0,
zoom: 0
});
const nw = lngLatToWorld([west, clamp(north, -MAX_LATITUDE, MAX_LATITUDE)]);
const se = lngLatToWorld([east, clamp(south, -MAX_LATITUDE, MAX_LATITUDE)]);
const nw = viewport.project([west, north]);
const se = viewport.project([east, south]);
// width/height on the Web Mercator plane

@@ -106,4 +98,4 @@ const size = [

const centerLngLat = viewport.unproject(center);
const zoom = Math.min(maxZoom, viewport.zoom + log2(Math.abs(Math.min(scaleX, scaleY))));
const centerLngLat = worldToLngLat(center);
const zoom = Math.min(maxZoom, log2(Math.abs(Math.min(scaleX, scaleY))));

@@ -110,0 +102,0 @@ assert(Number.isFinite(zoom));

@@ -5,4 +5,6 @@ import {lerp} from './math-utils';

import type {ViewportProps} from './normalize-viewport-props';
const EPSILON = 0.01;
const VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];
const VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'] as const;
const DEFAULT_OPTS = {

@@ -21,8 +23,2 @@ curve: 1.414,

export type ViewportProps = {
longitude: number;
latitude: number;
zoom: number;
};
/**

@@ -38,3 +34,7 @@ * mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.

options?: FlytoTransitionOptions
): ViewportProps {
): {
longitude: number;
latitude: number;
zoom: number;
} {
// Equations from above paper are referred where needed.

@@ -89,3 +89,3 @@

const length = 1000 * S;
let duration;
let duration: number;
if (Number.isFinite(screenSpeed)) {

@@ -103,3 +103,18 @@ duration = length / (screenSpeed / rho);

// Calculate all parameters that are static for given startProps and endProps
function getFlyToTransitionParams(startProps, endProps, opts) {
function getFlyToTransitionParams(
startProps: ViewportProps,
endProps: ViewportProps,
opts: FlytoTransitionOptions
): {
startZoom: number;
startCenterXY: number[];
uDelta: number[];
w0: number;
u1: number;
S: number;
rho: number;
rho2: number;
r0: number;
r1: number;
} {
opts = Object.assign({}, DEFAULT_OPTS, opts);

@@ -116,3 +131,3 @@ const rho = opts.curve;

const endCenterXY = lngLatToWorld(endCenter);
const uDelta = vec2.sub([], endCenterXY, startCenterXY);
const uDelta = vec2.sub([] as number[], endCenterXY, startCenterXY);

@@ -119,0 +134,0 @@ const w0 = Math.max(startProps.width, startProps.height);

@@ -19,4 +19,4 @@ import {worldToLngLat} from './web-mercator-utils';

const bottomRight = unproject([width, height], unprojectOps);
let topLeft;
let topRight;
let topLeft: number[];
let topRight: number[];

@@ -47,3 +47,3 @@ const halfFov = viewport.fovy

*/
function unprojectOnFarPlane(viewport: WebMercatorViewport, x: number, targetZ) {
function unprojectOnFarPlane(viewport: WebMercatorViewport, x: number, targetZ: number): number[] {
const {pixelUnprojectionMatrix} = viewport;

@@ -58,4 +58,4 @@ const coord0 = transformVector(pixelUnprojectionMatrix, [x, 0, 1, 1]);

const result = worldToLngLat(coord);
result[2] = targetZ;
result.push(targetZ);
return result;
}

@@ -11,2 +11,3 @@ // Classic web-mercator-project

export {
MAX_LATITUDE,
lngLatToWorld,

@@ -27,1 +28,5 @@ worldToLngLat,

} from './web-mercator-utils';
/** Types */
export type {FitBoundsOptions} from './fit-bounds';
export type {DistanceScales} from './web-mercator-utils';

@@ -9,4 +9,4 @@ import {transformMat4, scale} from 'gl-matrix/vec4';

// Transforms a vec4 with a projection matrix
export function transformVector(matrix, vector) {
const result = transformMat4([], vector, matrix);
export function transformVector(matrix: number[], vector: number[]): number[] {
const result = transformMat4([] as number[], vector, matrix);
scale(result, result, 1 / result[3]);

@@ -25,2 +25,6 @@ return result;

export function clamp(x: number, min: number, max: number): number {
return x < min ? min : x > max ? max : x;
}
function ieLog2(x: number): number {

@@ -27,0 +31,0 @@ return Math.log(x) * Math.LOG2E;

@@ -8,3 +8,3 @@ import {worldToLngLat} from './web-mercator-utils';

/** Description of viewport */
type ViewportProps = {
export type ViewportProps = {
width: number;

@@ -11,0 +11,0 @@ height: number;

@@ -18,2 +18,4 @@ // TODO - THE UTILITIES IN THIS FILE SHOULD BE IMPORTED FROM WEB-MERCATOR-VIEWPORT MODULE

const EARTH_CIRCUMFERENCE = 40.03e6;
// Latitude that makes a square world, 2 * atan(E ** PI) - PI / 2
export const MAX_LATITUDE = 85.051129;

@@ -70,3 +72,3 @@ // Mapbox default altitude

*/
export function lngLatToWorld(lngLat: number[]): number[] {
export function lngLatToWorld(lngLat: number[]): [number, number] {
const [lng, lat] = lngLat;

@@ -92,3 +94,3 @@ assert(Number.isFinite(lng));

*/
export function worldToLngLat(xy: number[]): number[] {
export function worldToLngLat(xy: number[]): [number, number] {
const [x, y] = xy;

@@ -195,3 +197,2 @@ const lambda2 = (x / TILE_SIZE) * (2 * PI) - PI;

// @ts-ignore
const newLngLat = worldToLngLat(worldspace);

@@ -217,3 +218,3 @@ const newZ = (z0 || 0) + (z || 0);

scale: number;
center: number[];
center?: number[];
}): number[] {

@@ -228,3 +229,3 @@ const {

scale,
center = null
center
} = options;

@@ -335,3 +336,3 @@ // VIEW MATRIX: PROJECTS MERCATOR WORLD COORDINATES

const projectionMatrix = mat4.perspective(
[],
[] as number[],
fov, // fov in radians

@@ -380,3 +381,3 @@ aspect, // aspect ratio

// Project flat coordinates to pixels on screen.
export function worldToPixels(xyz, pixelProjectionMatrix) {
export function worldToPixels(xyz: number[], pixelProjectionMatrix: number[]): number[] {
const [x, y, z = 0] = xyz;

@@ -420,3 +421,3 @@ assert(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z));

const t = z0 === z1 ? 0 : ((targetZ || 0) - z0) / (z1 - z0);
return vec2.lerp([], coord0, coord1, t);
return vec2.lerp([] as number[], coord0, coord1, t);
}

@@ -15,7 +15,8 @@ // View and Projection Matrix calculations for mapbox-js style map view properties

getDistanceScales,
getViewMatrix
getViewMatrix,
DistanceScales
} from './web-mercator-utils';
import fitBounds from './fit-bounds';
import getBounds from './get-bounds';
import type {Bounds, FitBoundsOptions} from './fit-bounds';
import type {FitBoundsOptions} from './fit-bounds';

@@ -88,5 +89,3 @@ import * as mat4 from 'gl-matrix/mat4';

readonly scale: number;
readonly distanceScales: {
unitsPerMeter: number[];
};
readonly distanceScales: DistanceScales;

@@ -150,3 +149,3 @@ readonly viewMatrix: number[];

const center = lngLatToWorld([longitude, latitude]);
center[2] = 0;
center.push(0);

@@ -204,3 +203,3 @@ if (position) {

_initMatrices() {
_initMatrices(): void {
const {width, height, projectionMatrix, viewMatrix} = this;

@@ -310,3 +309,3 @@

projectPosition(xyz) {
projectPosition(xyz: number[]): [number, number, number] {
const [X, Y] = lngLatToWorld(xyz);

@@ -317,5 +316,4 @@ const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];

unprojectPosition(xyz) {
unprojectPosition(xyz: number[]): [number, number, number] {
const [X, Y] = worldToLngLat(xyz);
// @ts-expect-error
const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];

@@ -322,0 +320,0 @@ return [X, Y, Z];

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc