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

viewport-mercator-project

Package Overview
Dependencies
Maintainers
4
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

viewport-mercator-project - npm Package Compare versions

Comparing version 5.1.0-alpha.2 to 5.1.0

9

CHANGELOG.md
# Change Log
## 5.0 Release
## 5.1 Release
### 5.1.0-alpha.2
### 5.1.0
- Add esnext dist
- Add test-size-* scripts
- Remove dependeny on external assert
- Bump to math.gl v1.1.0 for esnext dist
### 5.1.0-alpha.1
- Bump to math.gl v1.1.0-alpha.1 for esnext dist
## 5.0 Release
### 5.0.1

@@ -14,0 +15,0 @@ - Fix bug in `getMeterZoom` where `latitude: 0` throws error

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

'use strict';
"use strict";

@@ -7,2 +7,3 @@ Object.defineProperty(exports, "__esModule", {

exports.default = assert;
// Replacement for the external assert method to reduce bundle size

@@ -9,0 +10,0 @@ // Note: We don't use the second "message" argument in calling code,

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

'use strict';
"use strict";

@@ -6,14 +6,28 @@ Object.defineProperty(exports, "__esModule", {

});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
exports.default = fitBounds;
var _webMercatorViewport = require('./web-mercator-viewport');
var _webMercatorViewport = _interopRequireDefault(require("./web-mercator-viewport"));
var _webMercatorViewport2 = _interopRequireDefault(_webMercatorViewport);
var _assert = _interopRequireDefault(require("./assert"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
/**
* * An object describing the padding to add to the bounds.
* @typedef {Object} PaddingObject
* @property {Number} top - Padding from top in pixels to add to the given bounds
* @property {Number} bottom - Padding from bottom in pixels to add to the given bounds
* @property {Number} left - Padding from left in pixels to add to the given bounds
* @property {Number} right - Padding from right in pixels to add to the given bounds
*/
/**
* Returns map settings {latitude, longitude, zoom}

@@ -25,3 +39,5 @@ * that will contain the provided corners within the provided width.

* @param {Array} bounds - [[lon, lat], [lon, lat]]
* @param {Number} [padding] - The amount of padding in pixels to add to the given bounds.
* @param {Number|PaddingObject} [padding] - The amount of padding in pixels
* to add to the given bounds. Can also be an object with top, bottom, left and right
* properties defining the padding.
* @param {Array} [offset] - The center of the given bounds relative to the map's center,

@@ -36,5 +52,5 @@ * [x, y] measured in pixels.

_ref$padding = _ref.padding,
padding = _ref$padding === undefined ? 0 : _ref$padding,
padding = _ref$padding === void 0 ? 0 : _ref$padding,
_ref$offset = _ref.offset,
offset = _ref$offset === undefined ? [0, 0] : _ref$offset;
offset = _ref$offset === void 0 ? [0, 0] : _ref$offset;

@@ -49,3 +65,16 @@ var _bounds = _slicedToArray(bounds, 2),

var viewport = new _webMercatorViewport2.default({
if (Number.isFinite(padding)) {
var p = padding;
padding = {
top: p,
bottom: p,
left: p,
right: p
};
} else {
// Make sure all the required properties are set
(0, _assert.default)(Number.isFinite(padding.top) && Number.isFinite(padding.bottom) && Number.isFinite(padding.left) && Number.isFinite(padding.right));
}
var viewport = new _webMercatorViewport.default({
width: width,

@@ -57,14 +86,17 @@ height: height,

});
var nw = viewport.project([west, north]);
var se = viewport.project([east, south]); // width/height on the Web Mercator plane
var nw = viewport.project([west, north]);
var se = viewport.project([east, south]);
var size = [Math.abs(se[0] - nw[0]), Math.abs(se[1] - nw[1])];
var center = [(se[0] + nw[0]) / 2, (se[1] + nw[1]) / 2];
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); // scale = screen pixels per unit on the Web Mercator plane
var scaleX = (width - padding * 2 - Math.abs(offset[0]) * 2) / size[0];
var scaleY = (height - padding * 2 - Math.abs(offset[1]) * 2) / size[1];
var scaleX = targetSize[0] / size[0];
var scaleY = targetSize[1] / size[1]; // Find how much we need to shift the center
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 = viewport.unproject(center);
var zoom = viewport.zoom + Math.log2(Math.abs(Math.min(scaleX, scaleY)));
return {

@@ -71,0 +103,0 @@ longitude: centerLngLat[0],

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

'use strict';
"use strict";

@@ -8,11 +8,10 @@ Object.defineProperty(exports, "__esModule", {

var _math = require('math.gl');
var _math = require("math.gl");
var _mathUtils = require('./math-utils');
var _mathUtils = require("./math-utils");
var _webMercatorUtils = require('./web-mercator-utils');
var _webMercatorUtils = require("./web-mercator-utils");
var EPSILON = 0.01;
var VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];
/**

@@ -23,11 +22,10 @@ * mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.

*/
/* eslint-disable max-statements */
function flyToViewport(startProps, endProps, t) {
// Equations from above paper are referred where needed.
var viewport = {}; // TODO: add this as an option for applications.
var viewport = {};
// TODO: add this as an option for applications.
var rho = 1.414;
var startZoom = startProps.zoom;

@@ -39,45 +37,22 @@ var startCenter = [startProps.longitude, startProps.latitude];

var scale = (0, _webMercatorUtils.zoomToScale)(endZoom - startZoom);
var startCenterXY = new _math.Vector2((0, _webMercatorUtils.lngLatToWorld)(startCenter, startScale));
var endCenterXY = new _math.Vector2((0, _webMercatorUtils.lngLatToWorld)(endCenter, startScale));
var uDelta = endCenterXY.subtract(startCenterXY);
var w0 = Math.max(startProps.width, startProps.height);
var w1 = w0 / scale;
var u1 = Math.sqrt(uDelta.x * uDelta.x + uDelta.y * uDelta.y);
// u0 is treated as '0' in Eq (9).
var u1 = Math.sqrt(uDelta.x * uDelta.x + uDelta.y * uDelta.y); // u0 is treated as '0' in Eq (9).
// If change in center is too small, do linear interpolaiton.
// If change in center is too small, do linear interpolaiton.
if (Math.abs(u1) < EPSILON) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = VIEWPORT_TRANSITION_PROPS[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var key = _step.value;
var startValue = startProps[key];
var endValue = endProps[key];
viewport[key] = (0, _mathUtils.lerp)(startValue, endValue, t);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
for (var _i = 0; _i < VIEWPORT_TRANSITION_PROPS.length; _i++) {
var key = VIEWPORT_TRANSITION_PROPS[_i];
var startValue = startProps[key];
var endValue = endProps[key];
viewport[key] = (0, _mathUtils.lerp)(startValue, endValue, t);
}
return viewport;
}
} // Implement Equation (9) from above algorithm.
// Implement Equation (9) from above algorithm.
var rho2 = rho * rho;

@@ -90,9 +65,7 @@ var b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * u1 * u1) / (2 * w0 * rho2 * u1);

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; // Using w method for scaling.
var scaleIncrement = 1 / w; // Using w method for scaling.
var newZoom = startZoom + (0, _webMercatorUtils.scaleToZoom)(scaleIncrement);
var newCenter = (0, _webMercatorUtils.worldToLngLat)(startCenterXY.add(uDelta.scale(u)).scale(scaleIncrement), (0, _webMercatorUtils.zoomToScale)(newZoom));

@@ -99,0 +72,0 @@ viewport.longitude = newCenter[0];

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

'use strict';
"use strict";

@@ -6,54 +6,45 @@ Object.defineProperty(exports, "__esModule", {

});
var _webMercatorViewport = require('./web-mercator-viewport');
Object.defineProperty(exports, 'default', {
Object.defineProperty(exports, "default", {
enumerable: true,
get: function get() {
return _interopRequireDefault(_webMercatorViewport).default;
return _webMercatorViewport.default;
}
});
Object.defineProperty(exports, 'WebMercatorViewport', {
Object.defineProperty(exports, "WebMercatorViewport", {
enumerable: true,
get: function get() {
return _interopRequireDefault(_webMercatorViewport).default;
return _webMercatorViewport.default;
}
});
var _fitBounds = require('./fit-bounds');
Object.defineProperty(exports, 'fitBounds', {
Object.defineProperty(exports, "PerspectiveMercatorViewport", {
enumerable: true,
get: function get() {
return _interopRequireDefault(_fitBounds).default;
return _webMercatorViewport.default;
}
});
var _normalizeViewportProps = require('./normalize-viewport-props');
Object.defineProperty(exports, 'normalizeViewportProps', {
Object.defineProperty(exports, "fitBounds", {
enumerable: true,
get: function get() {
return _interopRequireDefault(_normalizeViewportProps).default;
return _fitBounds.default;
}
});
var _flyToViewport = require('./fly-to-viewport');
Object.defineProperty(exports, 'flyToViewport', {
Object.defineProperty(exports, "normalizeViewportProps", {
enumerable: true,
get: function get() {
return _interopRequireDefault(_flyToViewport).default;
return _normalizeViewportProps.default;
}
});
var _webMercatorUtils = require('./web-mercator-utils');
Object.defineProperty(exports, 'lngLatToWorld', {
Object.defineProperty(exports, "flyToViewport", {
enumerable: true,
get: function get() {
return _flyToViewport.default;
}
});
Object.defineProperty(exports, "lngLatToWorld", {
enumerable: true,
get: function get() {
return _webMercatorUtils.lngLatToWorld;
}
});
Object.defineProperty(exports, 'worldToLngLat', {
Object.defineProperty(exports, "worldToLngLat", {
enumerable: true,

@@ -64,3 +55,3 @@ get: function get() {

});
Object.defineProperty(exports, 'worldToPixels', {
Object.defineProperty(exports, "worldToPixels", {
enumerable: true,

@@ -71,3 +62,3 @@ get: function get() {

});
Object.defineProperty(exports, 'pixelsToWorld', {
Object.defineProperty(exports, "pixelsToWorld", {
enumerable: true,

@@ -78,3 +69,3 @@ get: function get() {

});
Object.defineProperty(exports, 'getMeterZoom', {
Object.defineProperty(exports, "getMeterZoom", {
enumerable: true,

@@ -85,3 +76,3 @@ get: function get() {

});
Object.defineProperty(exports, 'getDistanceScales', {
Object.defineProperty(exports, "getDistanceScales", {
enumerable: true,

@@ -92,3 +83,3 @@ get: function get() {

});
Object.defineProperty(exports, 'getWorldPosition', {
Object.defineProperty(exports, "getWorldPosition", {
enumerable: true,

@@ -99,3 +90,3 @@ get: function get() {

});
Object.defineProperty(exports, 'getViewMatrix', {
Object.defineProperty(exports, "getViewMatrix", {
enumerable: true,

@@ -106,3 +97,3 @@ get: function get() {

});
Object.defineProperty(exports, 'getProjectionMatrix', {
Object.defineProperty(exports, "getProjectionMatrix", {
enumerable: true,

@@ -113,3 +104,3 @@ get: function get() {

});
Object.defineProperty(exports, 'getProjectionParameters', {
Object.defineProperty(exports, "getProjectionParameters", {
enumerable: true,

@@ -120,15 +111,9 @@ get: function get() {

});
Object.defineProperty(exports, 'PerspectiveMercatorViewport', {
Object.defineProperty(exports, "getUncenteredViewMatrix", {
enumerable: true,
get: function get() {
return _interopRequireDefault(_webMercatorViewport).default;
}
});
Object.defineProperty(exports, 'getUncenteredViewMatrix', {
enumerable: true,
get: function get() {
return _webMercatorUtils.getViewMatrix;
}
});
Object.defineProperty(exports, 'projectFlat', {
Object.defineProperty(exports, "projectFlat", {
enumerable: true,

@@ -139,3 +124,3 @@ get: function get() {

});
Object.defineProperty(exports, 'unprojectFlat', {
Object.defineProperty(exports, "unprojectFlat", {
enumerable: true,

@@ -147,3 +132,13 @@ get: function get() {

var _webMercatorViewport = _interopRequireDefault(require("./web-mercator-viewport"));
var _fitBounds = _interopRequireDefault(require("./fit-bounds"));
var _normalizeViewportProps = _interopRequireDefault(require("./normalize-viewport-props"));
var _flyToViewport = _interopRequireDefault(require("./fly-to-viewport"));
var _webMercatorUtils = require("./web-mercator-utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//# sourceMappingURL=index.js.map

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

'use strict';
"use strict";

@@ -11,10 +11,6 @@ Object.defineProperty(exports, "__esModule", {

var _scale = require('gl-vec4/scale');
var _scale = _interopRequireDefault(require("gl-vec4/scale"));
var _scale2 = _interopRequireDefault(_scale);
var _transformMat = _interopRequireDefault(require("gl-vec4/transformMat4"));
var _transformMat = require('gl-vec4/transformMat4');
var _transformMat2 = _interopRequireDefault(_transformMat);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -25,8 +21,8 @@

return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
}
} // Transforms a vec4 with a projection matrix
// Transforms a vec4 with a projection matrix
function transformVector(matrix, vector) {
var result = (0, _transformMat2.default)([], vector, matrix);
(0, _scale2.default)(result, result, 1 / result[3]);
var result = (0, _transformMat.default)([], vector, matrix);
(0, _scale.default)(result, result, 1 / result[3]);
return result;

@@ -33,0 +29,0 @@ }

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

'use strict';
"use strict";

@@ -8,8 +8,6 @@ Object.defineProperty(exports, "__esModule", {

var _webMercatorViewport = require('./web-mercator-viewport');
var _webMercatorViewport = _interopRequireDefault(require("./web-mercator-viewport"));
var _webMercatorViewport2 = _interopRequireDefault(_webMercatorViewport);
var _mathUtils = require("./math-utils");
var _mathUtils = require('./math-utils');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -19,6 +17,6 @@

var MAX_LATITUDE = 85.05113;
var MIN_LATITUDE = -85.05113;
var MIN_LATITUDE = -85.05113; // Apply mathematical constraints to viewport props
// Apply mathematical constraints to viewport props
/* eslint-disable complexity */
function normalizeViewportProps(_ref) {

@@ -31,5 +29,5 @@ var width = _ref.width,

_ref$pitch = _ref.pitch,
pitch = _ref$pitch === undefined ? 0 : _ref$pitch,
pitch = _ref$pitch === void 0 ? 0 : _ref$pitch,
_ref$bearing = _ref.bearing,
bearing = _ref$bearing === undefined ? 0 : _ref$bearing;
bearing = _ref$bearing === void 0 ? 0 : _ref$bearing;

@@ -40,8 +38,15 @@ // Normalize degrees

}
if (bearing < -180 || bearing > 180) {
bearing = (0, _mathUtils.mod)(bearing + 180, 360) - 180;
}
} // Constrain zoom and shift center at low zoom levels
// Constrain zoom and shift center at low zoom levels
var flatViewport = new _webMercatorViewport2.default({ width: width, height: height, longitude: longitude, latitude: latitude, zoom: zoom });
var flatViewport = new _webMercatorViewport.default({
width: width,
height: height,
longitude: longitude,
latitude: latitude,
zoom: zoom
});
var topY = flatViewport.project([longitude, MAX_LATITUDE])[1];

@@ -54,9 +59,15 @@ var bottomY = flatViewport.project([longitude, MIN_LATITUDE])[1];

// Zoom out map to fit map height into viewport
zoom += Math.log2(height / (bottomY - topY));
zoom += Math.log2(height / (bottomY - topY)); // Calculate top and bottom using new zoom
// Calculate top and bottom using new zoom
flatViewport = new _webMercatorViewport2.default({ width: width, height: height, longitude: longitude, latitude: latitude, zoom: zoom });
flatViewport = new _webMercatorViewport.default({
width: width,
height: height,
longitude: longitude,
latitude: latitude,
zoom: zoom
});
topY = flatViewport.project([longitude, MAX_LATITUDE])[1];
bottomY = flatViewport.project([longitude, MIN_LATITUDE])[1];
}
if (topY > 0) {

@@ -69,2 +80,3 @@ // Compensate for white gap on top

}
if (shiftY) {

@@ -74,4 +86,12 @@ latitude = flatViewport.unproject([width / 2, height / 2 + shiftY])[1];

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

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

'use strict';
"use strict";

@@ -6,39 +6,41 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _math = require("math.gl");
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); // View and Projection Matrix management
var _mathUtils = require("./math-utils");
/* eslint-disable camelcase */
var _webMercatorUtils = require("./web-mercator-utils");
var _scale = _interopRequireDefault(require("gl-mat4/scale"));
var _math = require('math.gl');
var _translate = _interopRequireDefault(require("gl-mat4/translate"));
var _mathUtils = require('./math-utils');
var _multiply = _interopRequireDefault(require("gl-mat4/multiply"));
var _webMercatorUtils = require('./web-mercator-utils');
var _invert = _interopRequireDefault(require("gl-mat4/invert"));
var _scale = require('gl-mat4/scale');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _scale2 = _interopRequireDefault(_scale);
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
var _translate = require('gl-mat4/translate');
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
var _translate2 = _interopRequireDefault(_translate);
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
var _multiply = require('gl-mat4/multiply');
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var _multiply2 = _interopRequireDefault(_multiply);
function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return right[Symbol.hasInstance](left); } else { return left instanceof right; } }
var _invert = require('gl-mat4/invert');
function _classCallCheck(instance, Constructor) { if (!_instanceof(instance, Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _invert2 = _interopRequireDefault(_invert);
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var IDENTITY = (0, _mathUtils.createMat4)();
var Viewport = function () {
var Viewport =
/*#__PURE__*/
function () {
/**

@@ -69,2 +71,3 @@ * @classdesc

*/
/* eslint-disable complexity */

@@ -76,5 +79,5 @@ function Viewport() {

_ref$viewMatrix = _ref.viewMatrix,
viewMatrix = _ref$viewMatrix === undefined ? IDENTITY : _ref$viewMatrix,
viewMatrix = _ref$viewMatrix === void 0 ? IDENTITY : _ref$viewMatrix,
_ref$projectionMatrix = _ref.projectionMatrix,
projectionMatrix = _ref$projectionMatrix === undefined ? IDENTITY : _ref$projectionMatrix;
projectionMatrix = _ref$projectionMatrix === void 0 ? IDENTITY : _ref$projectionMatrix;

@@ -87,14 +90,11 @@ _classCallCheck(this, Viewport);

this.scale = 1;
this.viewMatrix = viewMatrix;
this.projectionMatrix = projectionMatrix;
this.projectionMatrix = projectionMatrix; // Note: As usual, matrix operations should be applied in "reverse" order
// since vectors will be multiplied in from the right during transformation
// Note: As usual, matrix operations should be applied in "reverse" order
// since vectors will be multiplied in from the right during transformation
var vpm = (0, _mathUtils.createMat4)();
(0, _multiply2.default)(vpm, vpm, this.projectionMatrix);
(0, _multiply2.default)(vpm, vpm, this.viewMatrix);
this.viewProjectionMatrix = vpm;
(0, _multiply.default)(vpm, vpm, this.projectionMatrix);
(0, _multiply.default)(vpm, vpm, this.viewMatrix);
this.viewProjectionMatrix = vpm; // Calculate matrices and scales needed for projection
// Calculate matrices and scales needed for projection
/**

@@ -109,11 +109,10 @@ * Builds matrices that converts preprojected lngLats to screen pixels

*/
var m = (0, _mathUtils.createMat4)();
// matrix for conversion from location to screen coordinates
(0, _scale2.default)(m, m, [this.width / 2, -this.height / 2, 1]);
(0, _translate2.default)(m, m, [1, -1, 0]);
var m = (0, _mathUtils.createMat4)(); // matrix for conversion from location to screen coordinates
(0, _multiply2.default)(m, m, this.viewProjectionMatrix);
(0, _scale.default)(m, m, [this.width / 2, -this.height / 2, 1]);
(0, _translate.default)(m, m, [1, -1, 0]);
(0, _multiply.default)(m, m, this.viewProjectionMatrix);
var mInverse = (0, _invert.default)((0, _mathUtils.createMat4)(), m);
var mInverse = (0, _invert2.default)((0, _mathUtils.createMat4)(), m);
if (!mInverse) {

@@ -124,5 +123,4 @@ throw new Error('Pixel project matrix not invertible');

this.pixelProjectionMatrix = m;
this.pixelUnprojectionMatrix = mInverse;
this.pixelUnprojectionMatrix = mInverse; // Bind methods for easy access
// Bind methods for easy access
this.equals = this.equals.bind(this);

@@ -135,3 +133,2 @@ this.project = this.project.bind(this);

/* eslint-enable complexity */
// Two viewports are equal if width and height are identical, and if

@@ -142,5 +139,5 @@ // their view and projection matrices are (approximately) equal.

_createClass(Viewport, [{
key: 'equals',
key: "equals",
value: function equals(viewport) {
if (!(viewport instanceof Viewport)) {
if (!_instanceof(viewport, Viewport)) {
return false;

@@ -151,3 +148,2 @@ }

}
/**

@@ -167,7 +163,7 @@ * Projects xyz (possibly latitude and longitude) to pixel coordinates in window

}, {
key: 'project',
key: "project",
value: function project(xyz) {
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref2$topLeft = _ref2.topLeft,
topLeft = _ref2$topLeft === undefined ? true : _ref2$topLeft;
topLeft = _ref2$topLeft === void 0 ? true : _ref2$topLeft;

@@ -193,3 +189,2 @@ var _xyz = _slicedToArray(xyz, 3),

}
/**

@@ -209,7 +204,7 @@ * Unproject pixel coordinates on screen onto world coordinates,

}, {
key: 'unproject',
key: "unproject",
value: function unproject(xyz) {
var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref3$topLeft = _ref3.topLeft,
topLeft = _ref3$topLeft === undefined ? true : _ref3$topLeft,
topLeft = _ref3$topLeft === void 0 ? true : _ref3$topLeft,
targetZ = _ref3.targetZ;

@@ -236,5 +231,3 @@

return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];
}
// NON_LINEAR PROJECTION HOOKS
} // NON_LINEAR PROJECTION HOOKS
// Used for web meractor projection

@@ -251,9 +244,7 @@

}, {
key: 'projectFlat',
key: "projectFlat",
value: function projectFlat(xyz) {
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.scale;
return xyz;
}
/**

@@ -268,6 +259,5 @@ * Project world coordinates to map coordinates.

}, {
key: 'unprojectFlat',
key: "unprojectFlat",
value: function unprojectFlat(xyz) {
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.scale;
return xyz;

@@ -274,0 +264,0 @@ }

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

'use strict';
"use strict";

@@ -6,5 +6,2 @@ Object.defineProperty(exports, "__esModule", {

});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); // TODO - THE UTILITIES IN THIS FILE SHOULD BE IMPORTED FROM WEB-MERCATOR-VIEWPORT MODULE
exports.zoomToScale = zoomToScale;

@@ -23,36 +20,30 @@ exports.scaleToZoom = scaleToZoom;

var _math = require('math.gl');
var _math = require("math.gl");
var _mathUtils = require('./math-utils');
var _mathUtils = require("./math-utils");
var _perspective = require('gl-mat4/perspective');
var _perspective = _interopRequireDefault(require("gl-mat4/perspective"));
var _perspective2 = _interopRequireDefault(_perspective);
var _scale = _interopRequireDefault(require("gl-mat4/scale"));
var _scale = require('gl-mat4/scale');
var _translate = _interopRequireDefault(require("gl-mat4/translate"));
var _scale2 = _interopRequireDefault(_scale);
var _rotateX = _interopRequireDefault(require("gl-mat4/rotateX"));
var _translate = require('gl-mat4/translate');
var _rotateZ = _interopRequireDefault(require("gl-mat4/rotateZ"));
var _translate2 = _interopRequireDefault(_translate);
var _lerp = _interopRequireDefault(require("gl-vec2/lerp"));
var _rotateX = require('gl-mat4/rotateX');
var _assert = _interopRequireDefault(require("./assert"));
var _rotateX2 = _interopRequireDefault(_rotateX);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _rotateZ = require('gl-mat4/rotateZ');
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
var _rotateZ2 = _interopRequireDefault(_rotateZ);
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
var _lerp = require('gl-vec2/lerp');
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
var _lerp2 = _interopRequireDefault(_lerp);
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var _assert = require('./assert');
var _assert2 = _interopRequireDefault(_assert);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// CONSTANTS

@@ -63,10 +54,9 @@ var PI = Math.PI;

var RADIANS_TO_DEGREES = 180 / PI;
var TILE_SIZE = 512;
// Average circumference (40075 km equatorial, 40007 km meridional)
var EARTH_CIRCUMFERENCE = 40.03e6;
var TILE_SIZE = 512; // Average circumference (40075 km equatorial, 40007 km meridional)
// Mapbox default altitude
var DEFAULT_ALITITUDE = 1.5;
var EARTH_CIRCUMFERENCE = 40.03e6; // Mapbox default altitude
var DEFAULT_ALTITUDE = 1.5;
/** Util functions **/
function zoomToScale(zoom) {

@@ -79,3 +69,2 @@ return Math.pow(2, zoom);

}
/**

@@ -91,2 +80,4 @@ * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.

*/
function lngLatToWorld(_ref, scale) {

@@ -104,3 +95,2 @@ var _ref2 = _slicedToArray(_ref, 2),

}
/**

@@ -115,2 +105,4 @@ * Unproject world point [x,y] on map onto {lat, lon} on sphere

*/
function worldToLngLat(_ref3, scale) {

@@ -125,14 +117,12 @@ var _ref4 = _slicedToArray(_ref3, 2),

return [lambda2 * RADIANS_TO_DEGREES, phi2 * RADIANS_TO_DEGREES];
}
} // Returns the zoom level that gives a 1 meter pixel at a certain latitude
// 1 = C*cos(y)/2^z/TILE_SIZE = C*cos(y)/2^(z+9)
// Returns the zoom level that gives a 1 meter pixel at a certain latitude
// S=C*cos(y)/2^(z+8)
function getMeterZoom(_ref5) {
var latitude = _ref5.latitude;
(0, _assert2.default)(Number.isFinite(latitude));
(0, _assert.default)(Number.isFinite(latitude));
var latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
return scaleToZoom(EARTH_CIRCUMFERENCE * latCosine) - 8;
return scaleToZoom(EARTH_CIRCUMFERENCE * latCosine) - 9;
}
/**

@@ -144,2 +134,4 @@ * Calculate distance scales in meters around current lat/lon, both for

*/
function getDistanceScales(_ref6) {

@@ -151,13 +143,9 @@ var latitude = _ref6.latitude,

_ref6$highPrecision = _ref6.highPrecision,
highPrecision = _ref6$highPrecision === undefined ? false : _ref6$highPrecision;
highPrecision = _ref6$highPrecision === void 0 ? false : _ref6$highPrecision;
// Calculate scale from zoom if not provided
scale = scale !== undefined ? scale : zoomToScale(zoom);
(0, _assert2.default)(Number.isFinite(latitude) && Number.isFinite(longitude) && Number.isFinite(scale));
(0, _assert.default)(Number.isFinite(latitude) && Number.isFinite(longitude) && Number.isFinite(scale));
var result = {};
var worldSize = TILE_SIZE * scale;
var latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
/**

@@ -170,16 +158,14 @@ * Number of pixels occupied by one degree longitude around current lat/lon:

*/
var pixelsPerDegreeX = worldSize / 360;
var pixelsPerDegreeY = pixelsPerDegreeX / latCosine;
/**
* Number of pixels occupied by one meter around current lat/lon:
*/
var altPixelsPerMeter = worldSize / EARTH_CIRCUMFERENCE / latCosine;
result.pixelsPerMeter = [altPixelsPerMeter, altPixelsPerMeter, altPixelsPerMeter];
result.metersPerPixel = [1 / altPixelsPerMeter, 1 / altPixelsPerMeter, 1 / altPixelsPerMeter];
result.pixelsPerDegree = [pixelsPerDegreeX, pixelsPerDegreeY, altPixelsPerMeter];
result.degreesPerPixel = [1 / pixelsPerDegreeX, 1 / pixelsPerDegreeY, 1 / altPixelsPerMeter];
/**

@@ -191,2 +177,3 @@ * Taylor series 2nd order for 1/latCosine

*/
if (highPrecision) {

@@ -197,11 +184,9 @@ var latCosine2 = DEGREES_TO_RADIANS * Math.tan(latitude * DEGREES_TO_RADIANS) / latCosine;

var altPixelsPerMeter2 = altPixelsPerDegree2 / pixelsPerDegreeY * altPixelsPerMeter;
result.pixelsPerDegree2 = [0, pixelsPerDegreeY2, altPixelsPerDegree2];
result.pixelsPerMeter2 = [altPixelsPerMeter2, 0, altPixelsPerMeter2];
}
} // Main results, used for converting meters to latlng deltas and scaling offsets
// Main results, used for converting meters to latlng deltas and scaling offsets
return result;
}
/**

@@ -211,2 +196,4 @@ * Calculates a mercator world position ("pixels" in given zoom level)

*/
function getWorldPosition(_ref7) {

@@ -219,8 +206,6 @@ var longitude = _ref7.longitude,

_ref7$distanceScales = _ref7.distanceScales,
distanceScales = _ref7$distanceScales === undefined ? null : _ref7$distanceScales;
distanceScales = _ref7$distanceScales === void 0 ? null : _ref7$distanceScales;
// Calculate scale from zoom if not provided
scale = scale !== undefined ? scale : zoomToScale(zoom);
scale = scale !== undefined ? scale : zoomToScale(zoom); // Make a centered version of the matrix for projection modes without an offset
// Make a centered version of the matrix for projection modes without an offset
var center2d = lngLatToWorld([longitude, latitude], scale);

@@ -231,8 +216,9 @@ var center = new _math.Vector3(center2d[0], center2d[1], 0);

// Calculate distance scales if lng/lat/zoom are provided
distanceScales = distanceScales || getDistanceScales({ latitude: latitude, longitude: longitude, scale: scale });
var pixelPosition = new _math.Vector3(meterOffset)
// Convert to pixels in current zoom
.scale(distanceScales.pixelsPerMeter)
// We want positive Y to represent an offset towards north,
distanceScales = distanceScales || getDistanceScales({
latitude: latitude,
longitude: longitude,
scale: scale
});
var pixelPosition = new _math.Vector3(meterOffset) // Convert to pixels in current zoom
.scale(distanceScales.pixelsPerMeter) // We want positive Y to represent an offset towards north,
// but web mercator world coordinates is top-left

@@ -244,5 +230,3 @@ .scale([1, -1, 1]);

return center;
}
// ATTRIBUTION:
} // ATTRIBUTION:
// view and projection matrix creation is intentionally kept compatible with

@@ -252,2 +236,3 @@ // mapbox-gl's implementation to ensure that seamless interoperation

function getViewMatrix(_ref8) {

@@ -259,7 +244,5 @@ var height = _ref8.height,

_ref8$center = _ref8.center,
center = _ref8$center === undefined ? null : _ref8$center,
center = _ref8$center === void 0 ? null : _ref8$center,
_ref8$flipY = _ref8.flipY,
flipY = _ref8$flipY === undefined ? false : _ref8$flipY;
flipY = _ref8$flipY === void 0 ? false : _ref8$flipY;
// VIEW MATRIX: PROJECTS MERCATOR WORLD COORDINATES

@@ -270,29 +253,26 @@ // Note that mercator world coordinates typically need to be flipped

// since vectors will be multiplied from the right during transformation
var vm = (0, _mathUtils.createMat4)();
var vm = (0, _mathUtils.createMat4)(); // Move camera to altitude (along the pitch & bearing direction)
// Move camera to altitude (along the pitch & bearing direction)
(0, _translate2.default)(vm, vm, [0, 0, -altitude]);
// After the rotateX, z values are in pixel units. Convert them to
(0, _translate.default)(vm, vm, [0, 0, -altitude]); // After the rotateX, z values are in pixel units. Convert them to
// altitude units. 1 altitude unit = the screen height.
(0, _scale2.default)(vm, vm, [1, 1, 1 / height]);
// Rotate by bearing, and then by pitch (which tilts the view)
(0, _rotateX2.default)(vm, vm, -pitch * DEGREES_TO_RADIANS);
(0, _rotateZ2.default)(vm, vm, bearing * DEGREES_TO_RADIANS);
(0, _scale.default)(vm, vm, [1, 1, 1 / height]); // Rotate by bearing, and then by pitch (which tilts the view)
(0, _rotateX.default)(vm, vm, -pitch * DEGREES_TO_RADIANS);
(0, _rotateZ.default)(vm, vm, bearing * DEGREES_TO_RADIANS);
if (flipY) {
(0, _scale2.default)(vm, vm, [1, -1, 1]);
(0, _scale.default)(vm, vm, [1, -1, 1]);
}
if (center) {
(0, _translate2.default)(vm, vm, new _math.Vector3(center).negate());
(0, _translate.default)(vm, vm, new _math.Vector3(center).negate());
}
return vm;
}
// PROJECTION MATRIX PARAMETERS
} // PROJECTION MATRIX PARAMETERS
// This is a "Mapbox" projection matrix - matches mapbox exactly if farZMultiplier === 1
// Variable fov (in radians)
function getProjectionParameters(_ref9) {

@@ -302,8 +282,7 @@ var width = _ref9.width,

_ref9$altitude = _ref9.altitude,
altitude = _ref9$altitude === undefined ? DEFAULT_ALITITUDE : _ref9$altitude,
altitude = _ref9$altitude === void 0 ? DEFAULT_ALTITUDE : _ref9$altitude,
_ref9$pitch = _ref9.pitch,
pitch = _ref9$pitch === undefined ? 0 : _ref9$pitch,
pitch = _ref9$pitch === void 0 ? 0 : _ref9$pitch,
_ref9$farZMultiplier = _ref9.farZMultiplier,
farZMultiplier = _ref9$farZMultiplier === undefined ? 1 : _ref9$farZMultiplier;
farZMultiplier = _ref9$farZMultiplier === void 0 ? 1 : _ref9$farZMultiplier;
// Find the distance from the center point to the center top

@@ -313,7 +292,5 @@ // in altitude units using law of sines.

var halfFov = Math.atan(0.5 / altitude);
var topHalfSurfaceDistance = Math.sin(halfFov) * altitude / Math.sin(Math.PI / 2 - pitchRadians - halfFov);
var topHalfSurfaceDistance = Math.sin(halfFov) * altitude / Math.sin(Math.PI / 2 - pitchRadians - halfFov); // Calculate z value of the farthest fragment that should be rendered.
// Calculate z value of the farthest fragment that should be rendered.
var farZ = Math.cos(Math.PI / 2 - pitchRadians) * topHalfSurfaceDistance + altitude;
return {

@@ -326,7 +303,7 @@ fov: 2 * Math.atan(height / 2 / altitude),

};
}
// PROJECTION MATRIX: PROJECTS FROM CAMERA (VIEW) SPACE TO CLIPSPACE
} // PROJECTION MATRIX: PROJECTS FROM CAMERA (VIEW) SPACE TO CLIPSPACE
// This is a "Mapbox" projection matrix - matches mapbox exactly if farZMultiplier === 1
// Variable fov (in radians)
function getProjectionMatrix(_ref10) {

@@ -338,5 +315,11 @@ var width = _ref10.width,

_ref10$farZMultiplier = _ref10.farZMultiplier,
farZMultiplier = _ref10$farZMultiplier === undefined ? 10 : _ref10$farZMultiplier;
farZMultiplier = _ref10$farZMultiplier === void 0 ? 10 : _ref10$farZMultiplier;
var _getProjectionParamet = getProjectionParameters({ width: width, height: height, altitude: altitude, pitch: pitch, farZMultiplier: farZMultiplier }),
var _getProjectionParamet = getProjectionParameters({
width: width,
height: height,
altitude: altitude,
pitch: pitch,
farZMultiplier: farZMultiplier
}),
fov = _getProjectionParamet.fov,

@@ -347,3 +330,3 @@ aspect = _getProjectionParamet.aspect,

var projectionMatrix = (0, _perspective2.default)([], fov, // fov in radians
var projectionMatrix = (0, _perspective.default)([], fov, // fov in radians
aspect, // aspect ratio

@@ -353,6 +336,4 @@ near, // near plane

);
return projectionMatrix;
}
/**

@@ -365,2 +346,4 @@ * Project flat coordinates to pixels on screen.

*/
function worldToPixels(xyz, pixelProjectionMatrix) {

@@ -371,9 +354,7 @@ var _xyz = _slicedToArray(xyz, 3),

_xyz$ = _xyz[2],
z = _xyz$ === undefined ? 0 : _xyz$;
z = _xyz$ === void 0 ? 0 : _xyz$;
(0, _assert2.default)(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z));
(0, _assert.default)(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z));
return (0, _mathUtils.transformVector)(pixelProjectionMatrix, [x, y, z, 1]);
}
/**

@@ -388,2 +369,4 @@ * Unproject pixels on screen to flat coordinates.

*/
function pixelsToWorld(xyz, pixelUnprojectionMatrix) {

@@ -397,3 +380,3 @@ var targetZ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;

(0, _assert2.default)(Number.isFinite(x) && Number.isFinite(y));
(0, _assert.default)(Number.isFinite(x) && Number.isFinite(y));

@@ -404,15 +387,13 @@ if (Number.isFinite(z)) {

return coord;
}
} // since we don't know the correct projected z value for the point,
// unproject two points to get a line and then find the point on that line with z=0
// since we don't know the correct projected z value for the point,
// unproject two points to get a line and then find the point on that line with z=0
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 (0, _lerp2.default)([], coord0, coord1, t);
return (0, _lerp.default)([], coord0, coord1, t);
}
//# sourceMappingURL=web-mercator-utils.js.map

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

'use strict';
"use strict";

@@ -6,33 +6,35 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _viewport = _interopRequireDefault(require("./viewport"));
var _viewport = require('./viewport');
var _webMercatorUtils = require("./web-mercator-utils");
var _viewport2 = _interopRequireDefault(_viewport);
var _fitBounds3 = _interopRequireDefault(require("./fit-bounds"));
var _webMercatorUtils = require('./web-mercator-utils');
var _add = _interopRequireDefault(require("gl-vec2/add"));
var _fitBounds3 = require('./fit-bounds');
var _negate = _interopRequireDefault(require("gl-vec2/negate"));
var _fitBounds4 = _interopRequireDefault(_fitBounds3);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _add = require('gl-vec2/add');
function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return right[Symbol.hasInstance](left); } else { return left instanceof right; } }
var _add2 = _interopRequireDefault(_add);
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var _negate = require('gl-vec2/negate');
function _classCallCheck(instance, Constructor) { if (!_instanceof(instance, Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _negate2 = _interopRequireDefault(_negate);
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // View and Projection Matrix calculations for mapbox-js style map view properties
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
var WebMercatorViewport = function (_Viewport) {
var WebMercatorViewport =
/*#__PURE__*/
function (_Viewport) {
_inherits(WebMercatorViewport, _Viewport);

@@ -68,4 +70,7 @@

*/
/* eslint-disable complexity */
function WebMercatorViewport() {
var _this;
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},

@@ -75,15 +80,15 @@ width = _ref.width,

_ref$latitude = _ref.latitude,
latitude = _ref$latitude === undefined ? 0 : _ref$latitude,
latitude = _ref$latitude === void 0 ? 0 : _ref$latitude,
_ref$longitude = _ref.longitude,
longitude = _ref$longitude === undefined ? 0 : _ref$longitude,
longitude = _ref$longitude === void 0 ? 0 : _ref$longitude,
_ref$zoom = _ref.zoom,
zoom = _ref$zoom === undefined ? 0 : _ref$zoom,
zoom = _ref$zoom === void 0 ? 0 : _ref$zoom,
_ref$pitch = _ref.pitch,
pitch = _ref$pitch === undefined ? 0 : _ref$pitch,
pitch = _ref$pitch === void 0 ? 0 : _ref$pitch,
_ref$bearing = _ref.bearing,
bearing = _ref$bearing === undefined ? 0 : _ref$bearing,
bearing = _ref$bearing === void 0 ? 0 : _ref$bearing,
_ref$altitude = _ref.altitude,
altitude = _ref$altitude === undefined ? 1.5 : _ref$altitude,
altitude = _ref$altitude === void 0 ? 1.5 : _ref$altitude,
_ref$farZMultiplier = _ref.farZMultiplier,
farZMultiplier = _ref$farZMultiplier === undefined ? 10 : _ref$farZMultiplier;
farZMultiplier = _ref$farZMultiplier === void 0 ? 10 : _ref$farZMultiplier;

@@ -95,10 +100,11 @@ _classCallCheck(this, WebMercatorViewport);

height = height || 1;
var scale = (0, _webMercatorUtils.zoomToScale)(zoom); // Altitude - prevent division by 0
// TODO - just throw an Error instead?
var scale = (0, _webMercatorUtils.zoomToScale)(zoom);
// Altitude - prevent division by 0
// TODO - just throw an Error instead?
altitude = Math.max(0.75, altitude);
var center = (0, _webMercatorUtils.getWorldPosition)({ longitude: longitude, latitude: latitude, scale: scale });
var center = (0, _webMercatorUtils.getWorldPosition)({
longitude: longitude,
latitude: latitude,
scale: scale
});
var projectionMatrix = (0, _webMercatorUtils.getProjectionMatrix)({

@@ -112,3 +118,2 @@ width: width,

});
var viewMatrix = (0, _webMercatorUtils.getViewMatrix)({

@@ -122,6 +127,9 @@ height: height,

});
_this = _possibleConstructorReturn(this, (WebMercatorViewport.__proto__ || Object.getPrototypeOf(WebMercatorViewport)).call(this, {
width: width,
height: height,
viewMatrix: viewMatrix,
projectionMatrix: projectionMatrix
})); // Save parameters
// Save parameters
var _this = _possibleConstructorReturn(this, (WebMercatorViewport.__proto__ || Object.getPrototypeOf(WebMercatorViewport)).call(this, { width: width, height: height, viewMatrix: viewMatrix, projectionMatrix: projectionMatrix }));
_this.latitude = latitude;

@@ -133,7 +141,5 @@ _this.longitude = longitude;

_this.altitude = altitude;
_this.scale = scale;
_this.center = center;
Object.freeze(_this);
Object.freeze(_assertThisInitialized(_this));
return _this;

@@ -156,9 +162,7 @@ }

_createClass(WebMercatorViewport, [{
key: 'projectFlat',
key: "projectFlat",
value: function projectFlat(lngLat) {
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.scale;
return (0, _webMercatorUtils.lngLatToWorld)(lngLat, scale);
}
/**

@@ -175,9 +179,7 @@ * Unproject world point [x,y] on map onto {lat, lon} on sphere

}, {
key: 'unprojectFlat',
key: "unprojectFlat",
value: function unprojectFlat(xy) {
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.scale;
return (0, _webMercatorUtils.worldToLngLat)(xy, scale);
}
/**

@@ -195,27 +197,23 @@ * Get the map center that place a given [lng, lat] coordinate at screen

}, {
key: 'getMapCenterByLngLatPosition',
key: "getMapCenterByLngLatPosition",
value: function getMapCenterByLngLatPosition(_ref2) {
var lngLat = _ref2.lngLat,
pos = _ref2.pos;
var fromLocation = (0, _webMercatorUtils.pixelsToWorld)(pos, this.pixelUnprojectionMatrix);
var toLocation = (0, _webMercatorUtils.lngLatToWorld)(lngLat, this.scale);
var translate = (0, _add2.default)([], toLocation, (0, _negate2.default)([], fromLocation));
var newCenter = (0, _add2.default)([], this.center, translate);
var translate = (0, _add.default)([], toLocation, (0, _negate.default)([], fromLocation));
var newCenter = (0, _add.default)([], this.center, translate);
return (0, _webMercatorUtils.worldToLngLat)(newCenter, this.scale);
}
} // Legacy method name
// Legacy method name
}, {
key: 'getLocationAtPoint',
key: "getLocationAtPoint",
value: function getLocationAtPoint(_ref3) {
var lngLat = _ref3.lngLat,
pos = _ref3.pos;
return this.getMapCenterByLngLatPosition({ lngLat: lngLat, pos: pos });
return this.getMapCenterByLngLatPosition({
lngLat: lngLat,
pos: pos
});
}
/**

@@ -232,3 +230,3 @@ * Returns a new viewport that fit around the given rectangle.

}, {
key: 'fitBounds',
key: "fitBounds",
value: function fitBounds(bounds) {

@@ -239,3 +237,7 @@ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

var _fitBounds2 = (0, _fitBounds4.default)(Object.assign({ width: width, height: height, bounds: bounds }, options)),
var _fitBounds2 = (0, _fitBounds3.default)(Object.assign({
width: width,
height: height,
bounds: bounds
}, options)),
longitude = _fitBounds2.longitude,

@@ -245,3 +247,9 @@ latitude = _fitBounds2.latitude,

return new WebMercatorViewport({ width: width, height: height, longitude: longitude, latitude: latitude, zoom: zoom });
return new WebMercatorViewport({
width: width,
height: height,
longitude: longitude,
latitude: latitude,
zoom: zoom
});
}

@@ -251,5 +259,5 @@ }]);

return WebMercatorViewport;
}(_viewport2.default);
}(_viewport.default);
exports.default = WebMercatorViewport;
//# sourceMappingURL=web-mercator-viewport.js.map

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

export default function assert(condition){if(!condition)throw new Error('viewport-mercator-project: assertion failed.')}
export default function assert(condition){if(!condition)throw new Error("viewport-mercator-project: assertion failed.")}
//# sourceMappingURL=assert.js.map

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

var _slicedToArray=function(){function sliceIterator(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!(i&&_arr.length===i));_n=!0);}catch(err){_d=!0,_e=err}finally{try{!_n&&_i['return']&&_i['return']()}finally{if(_d)throw _e}}return _arr}return function(arr,i){if(Array.isArray(arr))return arr;if(Symbol.iterator in Object(arr))return sliceIterator(arr,i);throw new TypeError('Invalid attempt to destructure non-iterable instance')}}();import WebMercatorViewport from'./web-mercator-viewport';export default function fitBounds({width,height,bounds,padding=0,offset=[0,0]}){var _Mathabs=Math.abs,_bounds=_slicedToArray(bounds,2),_bounds$=_slicedToArray(_bounds[0],2);const west=_bounds$[0],south=_bounds$[1];var _bounds$2=_slicedToArray(_bounds[1],2);const east=_bounds$2[0],north=_bounds$2[1],viewport=new WebMercatorViewport({width,height,longitude:0,latitude:0,zoom:0}),nw=viewport.project([west,north]),se=viewport.project([east,south]),size=[_Mathabs(se[0]-nw[0]),_Mathabs(se[1]-nw[1])],center=[(se[0]+nw[0])/2,(se[1]+nw[1])/2],scaleX=(width-2*padding-2*_Mathabs(offset[0]))/size[0],scaleY=(height-2*padding-2*_Mathabs(offset[1]))/size[1],centerLngLat=viewport.unproject(center),zoom=viewport.zoom+Math.log2(_Mathabs(Math.min(scaleX,scaleY)));return{longitude:centerLngLat[0],latitude:centerLngLat[1],zoom}}
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!(i&&_arr.length===i));_n=!0);}catch(err){_d=!0,_e=err}finally{try{_n||null==_i["return"]||_i["return"]()}finally{if(_d)throw _e}}return _arr}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}import WebMercatorViewport from"./web-mercator-viewport";import assert from"./assert";export default function fitBounds({width,height,bounds,padding=0,offset=[0,0]}){var _Mathabs=Math.abs,_NumberisFinite=Number.isFinite;const _bounds=_slicedToArray(bounds,2),_bounds$=_slicedToArray(_bounds[0],2),west=_bounds$[0],south=_bounds$[1],_bounds$2=_slicedToArray(_bounds[1],2),east=_bounds$2[0],north=_bounds$2[1];if(_NumberisFinite(padding)){const p=padding;padding={top:p,bottom:p,left:p,right:p}}else assert(_NumberisFinite(padding.top)&&_NumberisFinite(padding.bottom)&&_NumberisFinite(padding.left)&&_NumberisFinite(padding.right));const viewport=new WebMercatorViewport({width,height,longitude:0,latitude:0,zoom:0}),nw=viewport.project([west,north]),se=viewport.project([east,south]),size=[_Mathabs(se[0]-nw[0]),_Mathabs(se[1]-nw[1])],targetSize=[width-padding.left-padding.right-2*_Mathabs(offset[0]),height-padding.top-padding.bottom-2*_Mathabs(offset[1])];assert(0<targetSize[0]&&0<targetSize[1]);const scaleX=targetSize[0]/size[0],scaleY=targetSize[1]/size[1],offsetX=(padding.right-padding.left)/2/scaleX,offsetY=(padding.bottom-padding.top)/2/scaleY,center=[(se[0]+nw[0])/2+offsetX,(se[1]+nw[1])/2+offsetY],centerLngLat=viewport.unproject(center),zoom=viewport.zoom+Math.log2(_Mathabs(Math.min(scaleX,scaleY)));return{longitude:centerLngLat[0],latitude:centerLngLat[1],zoom}}
//# sourceMappingURL=fit-bounds.js.map

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

import{Vector2}from'math.gl';import{lerp}from'./math-utils';import{scaleToZoom,zoomToScale,lngLatToWorld,worldToLngLat}from'./web-mercator-utils';const EPSILON=.01,VIEWPORT_TRANSITION_PROPS=['longitude','latitude','zoom'];export default function flyToViewport(startProps,endProps,t){var _Mathcosh=Math.cosh,_Mathlog=Math.log,_Mathsqrt=Math.sqrt;const viewport={},rho=1.414,startZoom=startProps.zoom,startCenter=[startProps.longitude,startProps.latitude],startScale=zoomToScale(startZoom),endZoom=endProps.zoom,endCenter=[endProps.longitude,endProps.latitude],scale=zoomToScale(endZoom-startZoom),startCenterXY=new Vector2(lngLatToWorld(startCenter,startScale)),endCenterXY=new Vector2(lngLatToWorld(endCenter,startScale)),uDelta=endCenterXY.subtract(startCenterXY),w0=Math.max(startProps.width,startProps.height),w1=w0/scale,u1=_Mathsqrt(uDelta.x*uDelta.x+uDelta.y*uDelta.y);if(Math.abs(u1)<EPSILON){for(const key of VIEWPORT_TRANSITION_PROPS){const startValue=startProps[key],endValue=endProps[key];viewport[key]=lerp(startValue,endValue,t)}return viewport}const rho2=rho*rho,b0=(w1*w1-w0*w0+rho2*rho2*u1*u1)/(2*w0*rho2*u1),b1=(w1*w1-w0*w0-rho2*rho2*u1*u1)/(2*w1*rho2*u1),r0=_Mathlog(_Mathsqrt(b0*b0+1)-b0),r1=_Mathlog(_Mathsqrt(b1*b1+1)-b1),s=t*((r1-r0)/rho),w=_Mathcosh(r0)/_Mathcosh(r0+rho*s),u=w0*((_Mathcosh(r0)*Math.tanh(r0+rho*s)-Math.sinh(r0))/rho2)/u1,scaleIncrement=1/w,newZoom=startZoom+scaleToZoom(scaleIncrement),newCenter=worldToLngLat(startCenterXY.add(uDelta.scale(u)).scale(scaleIncrement),zoomToScale(newZoom));return viewport.longitude=newCenter[0],viewport.latitude=newCenter[1],viewport.zoom=newZoom,viewport}
import{Vector2}from"math.gl";import{lerp}from"./math-utils";import{scaleToZoom,zoomToScale,lngLatToWorld,worldToLngLat}from"./web-mercator-utils";const EPSILON=.01,VIEWPORT_TRANSITION_PROPS=["longitude","latitude","zoom"];export default function flyToViewport(startProps,endProps,t){var _Mathcosh=Math.cosh,_Mathlog=Math.log,_Mathsqrt=Math.sqrt;const viewport={},rho=1.414,startZoom=startProps.zoom,startCenter=[startProps.longitude,startProps.latitude],startScale=zoomToScale(startZoom),endZoom=endProps.zoom,endCenter=[endProps.longitude,endProps.latitude],scale=zoomToScale(endZoom-startZoom),startCenterXY=new Vector2(lngLatToWorld(startCenter,startScale)),endCenterXY=new Vector2(lngLatToWorld(endCenter,startScale)),uDelta=endCenterXY.subtract(startCenterXY),w0=Math.max(startProps.width,startProps.height),w1=w0/scale,u1=_Mathsqrt(uDelta.x*uDelta.x+uDelta.y*uDelta.y);if(Math.abs(u1)<EPSILON){for(const key of VIEWPORT_TRANSITION_PROPS){const startValue=startProps[key],endValue=endProps[key];viewport[key]=lerp(startValue,endValue,t)}return viewport}const rho2=rho*rho,b0=(w1*w1-w0*w0+rho2*rho2*u1*u1)/(2*w0*rho2*u1),b1=(w1*w1-w0*w0-rho2*rho2*u1*u1)/(2*w1*rho2*u1),r0=_Mathlog(_Mathsqrt(b0*b0+1)-b0),r1=_Mathlog(_Mathsqrt(b1*b1+1)-b1),s=t*((r1-r0)/rho),w=_Mathcosh(r0)/_Mathcosh(r0+rho*s),u=w0*((_Mathcosh(r0)*Math.tanh(r0+rho*s)-Math.sinh(r0))/rho2)/u1,scaleIncrement=1/w,newZoom=startZoom+scaleToZoom(scaleIncrement),newCenter=worldToLngLat(startCenterXY.add(uDelta.scale(u)).scale(scaleIncrement),zoomToScale(newZoom));return viewport.longitude=newCenter[0],viewport.latitude=newCenter[1],viewport.zoom=newZoom,viewport}
//# sourceMappingURL=fly-to-viewport.js.map

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

export{default}from'./web-mercator-viewport';export{default as WebMercatorViewport}from'./web-mercator-viewport';export{default as fitBounds}from'./fit-bounds';export{default as normalizeViewportProps}from'./normalize-viewport-props';export{default as flyToViewport}from'./fly-to-viewport';export{lngLatToWorld,worldToLngLat,worldToPixels,pixelsToWorld,getMeterZoom,getDistanceScales,getWorldPosition,getViewMatrix,getProjectionMatrix,getProjectionParameters}from'./web-mercator-utils';export{default as PerspectiveMercatorViewport}from'./web-mercator-viewport';export{getViewMatrix as getUncenteredViewMatrix,lngLatToWorld as projectFlat,worldToLngLat as unprojectFlat}from'./web-mercator-utils';
export{default}from"./web-mercator-viewport";export{default as WebMercatorViewport}from"./web-mercator-viewport";export{default as fitBounds}from"./fit-bounds";export{default as normalizeViewportProps}from"./normalize-viewport-props";export{default as flyToViewport}from"./fly-to-viewport";export{lngLatToWorld,worldToLngLat,worldToPixels,pixelsToWorld,getMeterZoom,getDistanceScales,getWorldPosition,getViewMatrix,getProjectionMatrix,getProjectionParameters}from"./web-mercator-utils";export{default as PerspectiveMercatorViewport}from"./web-mercator-viewport";export{getViewMatrix as getUncenteredViewMatrix,lngLatToWorld as projectFlat,worldToLngLat as unprojectFlat}from"./web-mercator-utils";
//# sourceMappingURL=index.js.map

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

import vec4_scale from'gl-vec4/scale';import vec4_transformMat4 from'gl-vec4/transformMat4';export function createMat4(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}export function transformVector(matrix,vector){const result=vec4_transformMat4([],vector,matrix);return vec4_scale(result,result,1/result[3]),result}export function mod(value,divisor){const modulus=value%divisor;return 0>modulus?divisor+modulus:modulus}export function lerp(start,end,step){return step*end+(1-step)*start}
import vec4_scale from"gl-vec4/scale";import vec4_transformMat4 from"gl-vec4/transformMat4";export function createMat4(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}export function transformVector(matrix,vector){const result=vec4_transformMat4([],vector,matrix);return vec4_scale(result,result,1/result[3]),result}export function mod(value,divisor){const modulus=value%divisor;return 0>modulus?divisor+modulus:modulus}export function lerp(start,end,step){return step*end+(1-step)*start}
//# sourceMappingURL=math-utils.js.map

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

import WebMercatorViewport from'./web-mercator-viewport';import{mod}from'./math-utils';const MAX_LATITUDE=85.05113,MIN_LATITUDE=-85.05113;export default function normalizeViewportProps({width,height,longitude,latitude,zoom,pitch=0,bearing=0}){(-180>longitude||180<longitude)&&(longitude=mod(longitude+180,360)-180),(-180>bearing||180<bearing)&&(bearing=mod(bearing+180,360)-180);let flatViewport=new WebMercatorViewport({width,height,longitude,latitude,zoom}),topY=flatViewport.project([longitude,MAX_LATITUDE])[1],bottomY=flatViewport.project([longitude,MIN_LATITUDE])[1],shiftY=0;return bottomY-topY<height&&(zoom+=Math.log2(height/(bottomY-topY)),flatViewport=new WebMercatorViewport({width,height,longitude,latitude,zoom}),topY=flatViewport.project([longitude,MAX_LATITUDE])[1],bottomY=flatViewport.project([longitude,MIN_LATITUDE])[1]),0<topY?shiftY=topY:bottomY<height&&(shiftY=bottomY-height),shiftY&&(latitude=flatViewport.unproject([width/2,height/2+shiftY])[1]),{width,height,longitude,latitude,zoom,pitch,bearing}}
import WebMercatorViewport from"./web-mercator-viewport";import{mod}from"./math-utils";const MAX_LATITUDE=85.05113,MIN_LATITUDE=-85.05113;export default function normalizeViewportProps({width,height,longitude,latitude,zoom,pitch=0,bearing=0}){(-180>longitude||180<longitude)&&(longitude=mod(longitude+180,360)-180),(-180>bearing||180<bearing)&&(bearing=mod(bearing+180,360)-180);let flatViewport=new WebMercatorViewport({width,height,longitude,latitude,zoom}),topY=flatViewport.project([longitude,MAX_LATITUDE])[1],bottomY=flatViewport.project([longitude,MIN_LATITUDE])[1],shiftY=0;return bottomY-topY<height&&(zoom+=Math.log2(height/(bottomY-topY)),flatViewport=new WebMercatorViewport({width,height,longitude,latitude,zoom}),topY=flatViewport.project([longitude,MAX_LATITUDE])[1],bottomY=flatViewport.project([longitude,MIN_LATITUDE])[1]),0<topY?shiftY=topY:bottomY<height&&(shiftY=bottomY-height),shiftY&&(latitude=flatViewport.unproject([width/2,height/2+shiftY])[1]),{width,height,longitude,latitude,zoom,pitch,bearing}}
//# sourceMappingURL=normalize-viewport-props.js.map

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

var _slicedToArray=function(){function sliceIterator(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!(i&&_arr.length===i));_n=!0);}catch(err){_d=!0,_e=err}finally{try{!_n&&_i['return']&&_i['return']()}finally{if(_d)throw _e}}return _arr}return function(arr,i){if(Array.isArray(arr))return arr;if(Symbol.iterator in Object(arr))return sliceIterator(arr,i);throw new TypeError('Invalid attempt to destructure non-iterable instance')}}();import{equals}from'math.gl';import{createMat4}from'./math-utils';import{worldToPixels,pixelsToWorld}from'./web-mercator-utils';import mat4_scale from'gl-mat4/scale';import mat4_translate from'gl-mat4/translate';import mat4_multiply from'gl-mat4/multiply';import mat4_invert from'gl-mat4/invert';const IDENTITY=createMat4();export default class Viewport{constructor({width,height,viewMatrix=IDENTITY,projectionMatrix=IDENTITY}={}){this.width=width||1,this.height=height||1,this.scale=1,this.viewMatrix=viewMatrix,this.projectionMatrix=projectionMatrix;const vpm=createMat4();mat4_multiply(vpm,vpm,this.projectionMatrix),mat4_multiply(vpm,vpm,this.viewMatrix),this.viewProjectionMatrix=vpm;const m=createMat4();mat4_scale(m,m,[this.width/2,-this.height/2,1]),mat4_translate(m,m,[1,-1,0]),mat4_multiply(m,m,this.viewProjectionMatrix);const mInverse=mat4_invert(createMat4(),m);if(!mInverse)throw new Error('Pixel project matrix not invertible');this.pixelProjectionMatrix=m,this.pixelUnprojectionMatrix=mInverse,this.equals=this.equals.bind(this),this.project=this.project.bind(this),this.unproject=this.unproject.bind(this),this.projectFlat=this.projectFlat.bind(this),this.unprojectFlat=this.unprojectFlat.bind(this)}equals(viewport){return!!(viewport instanceof Viewport)&&viewport.width===this.width&&viewport.height===this.height&&equals(viewport.projectionMatrix,this.projectionMatrix)&&equals(viewport.viewMatrix,this.viewMatrix)}project(xyz,{topLeft=!0}={}){var _xyz=_slicedToArray(xyz,3);const x0=_xyz[0],y0=_xyz[1],z0=_xyz[2];var _projectFlat=this.projectFlat([x0,y0]),_projectFlat2=_slicedToArray(_projectFlat,2);const X=_projectFlat2[0],Y=_projectFlat2[1],coord=worldToPixels([X,Y,z0],this.pixelProjectionMatrix);var _coord=_slicedToArray(coord,2);const x=_coord[0],y=_coord[1],y2=topLeft?y:this.height-y;return 2===xyz.length?[x,y2]:[x,y2,coord[2]]}unproject(xyz,{topLeft=!0,targetZ}={}){var _NumberisFinite=Number.isFinite,_xyz2=_slicedToArray(xyz,3);const x=_xyz2[0],y=_xyz2[1],z=_xyz2[2],y2=topLeft?y:this.height-y,coord=pixelsToWorld([x,y2,z],this.pixelUnprojectionMatrix,targetZ);var _unprojectFlat=this.unprojectFlat(coord),_unprojectFlat2=_slicedToArray(_unprojectFlat,2);const X=_unprojectFlat2[0],Y=_unprojectFlat2[1];return _NumberisFinite(z)?[X,Y,coord[2]]:_NumberisFinite(targetZ)?[X,Y,targetZ]:[X,Y]}projectFlat(xyz,scale=this.scale){return xyz}unprojectFlat(xyz,scale=this.scale){return xyz}}
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!(i&&_arr.length===i));_n=!0);}catch(err){_d=!0,_e=err}finally{try{_n||null==_i["return"]||_i["return"]()}finally{if(_d)throw _e}}return _arr}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}import{equals}from"math.gl";import{createMat4}from"./math-utils";import{worldToPixels,pixelsToWorld}from"./web-mercator-utils";import mat4_scale from"gl-mat4/scale";import mat4_translate from"gl-mat4/translate";import mat4_multiply from"gl-mat4/multiply";import mat4_invert from"gl-mat4/invert";const IDENTITY=createMat4();export default class Viewport{constructor({width,height,viewMatrix=IDENTITY,projectionMatrix=IDENTITY}={}){this.width=width||1,this.height=height||1,this.scale=1,this.viewMatrix=viewMatrix,this.projectionMatrix=projectionMatrix;const vpm=createMat4();mat4_multiply(vpm,vpm,this.projectionMatrix),mat4_multiply(vpm,vpm,this.viewMatrix),this.viewProjectionMatrix=vpm;const m=createMat4();mat4_scale(m,m,[this.width/2,-this.height/2,1]),mat4_translate(m,m,[1,-1,0]),mat4_multiply(m,m,this.viewProjectionMatrix);const mInverse=mat4_invert(createMat4(),m);if(!mInverse)throw new Error("Pixel project matrix not invertible");this.pixelProjectionMatrix=m,this.pixelUnprojectionMatrix=mInverse,this.equals=this.equals.bind(this),this.project=this.project.bind(this),this.unproject=this.unproject.bind(this),this.projectFlat=this.projectFlat.bind(this),this.unprojectFlat=this.unprojectFlat.bind(this)}equals(viewport){return!!(viewport instanceof Viewport)&&viewport.width===this.width&&viewport.height===this.height&&equals(viewport.projectionMatrix,this.projectionMatrix)&&equals(viewport.viewMatrix,this.viewMatrix)}project(xyz,{topLeft=!0}={}){const _xyz=_slicedToArray(xyz,3),x0=_xyz[0],y0=_xyz[1],z0=_xyz[2],_projectFlat=this.projectFlat([x0,y0]),_projectFlat2=_slicedToArray(_projectFlat,2),X=_projectFlat2[0],Y=_projectFlat2[1],coord=worldToPixels([X,Y,z0],this.pixelProjectionMatrix),_coord=_slicedToArray(coord,2),x=_coord[0],y=_coord[1],y2=topLeft?y:this.height-y;return 2===xyz.length?[x,y2]:[x,y2,coord[2]]}unproject(xyz,{topLeft=!0,targetZ}={}){var _NumberisFinite=Number.isFinite;const _xyz2=_slicedToArray(xyz,3),x=_xyz2[0],y=_xyz2[1],z=_xyz2[2],y2=topLeft?y:this.height-y,coord=pixelsToWorld([x,y2,z],this.pixelUnprojectionMatrix,targetZ),_unprojectFlat=this.unprojectFlat(coord),_unprojectFlat2=_slicedToArray(_unprojectFlat,2),X=_unprojectFlat2[0],Y=_unprojectFlat2[1];return _NumberisFinite(z)?[X,Y,coord[2]]:_NumberisFinite(targetZ)?[X,Y,targetZ]:[X,Y]}projectFlat(xyz,scale=this.scale){return xyz}unprojectFlat(xyz,scale=this.scale){return xyz}}
//# sourceMappingURL=viewport.js.map

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

var _slicedToArray=function(){function sliceIterator(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!(i&&_arr.length===i));_n=!0);}catch(err){_d=!0,_e=err}finally{try{!_n&&_i['return']&&_i['return']()}finally{if(_d)throw _e}}return _arr}return function(arr,i){if(Array.isArray(arr))return arr;if(Symbol.iterator in Object(arr))return sliceIterator(arr,i);throw new TypeError('Invalid attempt to destructure non-iterable instance')}}();import{Vector3}from'math.gl';import{createMat4,transformVector}from'./math-utils';import mat4_perspective from'gl-mat4/perspective';import mat4_scale from'gl-mat4/scale';import mat4_translate from'gl-mat4/translate';import mat4_rotateX from'gl-mat4/rotateX';import mat4_rotateZ from'gl-mat4/rotateZ';import vec2_lerp from'gl-vec2/lerp';import assert from'./assert';const PI=Math.PI,PI_4=PI/4,DEGREES_TO_RADIANS=PI/180,RADIANS_TO_DEGREES=180/PI,TILE_SIZE=512,EARTH_CIRCUMFERENCE=4003e4,DEFAULT_ALITITUDE=1.5;export function zoomToScale(zoom){return Math.pow(2,zoom)}export function scaleToZoom(scale){return Math.log2(scale)}export function lngLatToWorld([lng,lat],scale){scale*=TILE_SIZE;const x=scale*(lng*DEGREES_TO_RADIANS+PI)/(2*PI),y=scale*(PI-Math.log(Math.tan(PI_4+.5*(lat*DEGREES_TO_RADIANS))))/(2*PI);return[x,y]}export function worldToLngLat([x,y],scale){scale*=TILE_SIZE;const lambda2=x/scale*(2*PI)-PI,phi2=2*(Math.atan(Math.exp(PI-y/scale*(2*PI)))-PI_4);return[lambda2*RADIANS_TO_DEGREES,phi2*RADIANS_TO_DEGREES]}export function getMeterZoom({latitude}){assert(Number.isFinite(latitude));const latCosine=Math.cos(latitude*DEGREES_TO_RADIANS);return scaleToZoom(EARTH_CIRCUMFERENCE*latCosine)-8}export function getDistanceScales({latitude,longitude,zoom,scale,highPrecision=!1}){var _NumberisFinite=Number.isFinite;scale=void 0===scale?zoomToScale(zoom):scale,assert(_NumberisFinite(latitude)&&_NumberisFinite(longitude)&&_NumberisFinite(scale));const result={},worldSize=TILE_SIZE*scale,latCosine=Math.cos(latitude*DEGREES_TO_RADIANS),pixelsPerDegreeX=worldSize/360,pixelsPerDegreeY=pixelsPerDegreeX/latCosine,altPixelsPerMeter=worldSize/EARTH_CIRCUMFERENCE/latCosine;if(result.pixelsPerMeter=[altPixelsPerMeter,altPixelsPerMeter,altPixelsPerMeter],result.metersPerPixel=[1/altPixelsPerMeter,1/altPixelsPerMeter,1/altPixelsPerMeter],result.pixelsPerDegree=[pixelsPerDegreeX,pixelsPerDegreeY,altPixelsPerMeter],result.degreesPerPixel=[1/pixelsPerDegreeX,1/pixelsPerDegreeY,1/altPixelsPerMeter],highPrecision){const latCosine2=DEGREES_TO_RADIANS*Math.tan(latitude*DEGREES_TO_RADIANS)/latCosine,altPixelsPerDegree2=worldSize/EARTH_CIRCUMFERENCE*latCosine2,altPixelsPerMeter2=altPixelsPerDegree2/pixelsPerDegreeY*altPixelsPerMeter;result.pixelsPerDegree2=[0,pixelsPerDegreeX*latCosine2/2,altPixelsPerDegree2],result.pixelsPerMeter2=[altPixelsPerMeter2,0,altPixelsPerMeter2]}return result}export function getWorldPosition({longitude,latitude,zoom,scale,meterOffset,distanceScales=null}){scale=scale===void 0?zoomToScale(zoom):scale;const center2d=lngLatToWorld([longitude,latitude],scale),center=new Vector3(center2d[0],center2d[1],0);if(meterOffset){distanceScales=distanceScales||getDistanceScales({latitude,longitude,scale});const pixelPosition=new Vector3(meterOffset).scale(distanceScales.pixelsPerMeter).scale([1,-1,1]);center.add(pixelPosition)}return center}export function getViewMatrix({height,pitch,bearing,altitude,center=null,flipY=!1}){const vm=createMat4();return mat4_translate(vm,vm,[0,0,-altitude]),mat4_scale(vm,vm,[1,1,1/height]),mat4_rotateX(vm,vm,-pitch*DEGREES_TO_RADIANS),mat4_rotateZ(vm,vm,bearing*DEGREES_TO_RADIANS),flipY&&mat4_scale(vm,vm,[1,-1,1]),center&&mat4_translate(vm,vm,new Vector3(center).negate()),vm}export function getProjectionParameters({width,height,altitude=DEFAULT_ALITITUDE,pitch=0,farZMultiplier=1}){var _MathPI=Math.PI,_Mathsin=Math.sin,_Mathatan=Math.atan;const pitchRadians=pitch*DEGREES_TO_RADIANS,halfFov=_Mathatan(.5/altitude),topHalfSurfaceDistance=_Mathsin(halfFov)*altitude/_Mathsin(_MathPI/2-pitchRadians-halfFov),farZ=Math.cos(_MathPI/2-pitchRadians)*topHalfSurfaceDistance+altitude;return{fov:2*_Mathatan(height/2/altitude),aspect:width/height,focalDistance:altitude,near:.1,far:farZ*farZMultiplier}}export function getProjectionMatrix({width,height,pitch,altitude,farZMultiplier=10}){var _getProjectionParamet=getProjectionParameters({width,height,altitude,pitch,farZMultiplier});const fov=_getProjectionParamet.fov,aspect=_getProjectionParamet.aspect,near=_getProjectionParamet.near,far=_getProjectionParamet.far,projectionMatrix=mat4_perspective([],fov,aspect,near,far);return projectionMatrix}export function worldToPixels(xyz,pixelProjectionMatrix){var _NumberisFinite2=Number.isFinite,_xyz=_slicedToArray(xyz,3);const x=_xyz[0],y=_xyz[1];var _xyz$=_xyz[2];const z=void 0===_xyz$?0:_xyz$;return assert(_NumberisFinite2(x)&&_NumberisFinite2(y)&&_NumberisFinite2(z)),transformVector(pixelProjectionMatrix,[x,y,z,1])}export function pixelsToWorld(xyz,pixelUnprojectionMatrix,targetZ=0){var _NumberisFinite3=Number.isFinite,_xyz2=_slicedToArray(xyz,3);const x=_xyz2[0],y=_xyz2[1],z=_xyz2[2];if(assert(_NumberisFinite3(x)&&_NumberisFinite3(y)),_NumberisFinite3(z)){const coord=transformVector(pixelUnprojectionMatrix,[x,y,z,1]);return coord}const coord0=transformVector(pixelUnprojectionMatrix,[x,y,0,1]),coord1=transformVector(pixelUnprojectionMatrix,[x,y,1,1]),z0=coord0[2],z1=coord1[2],t=z0===z1?0:((targetZ||0)-z0)/(z1-z0);return vec2_lerp([],coord0,coord1,t)}
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!(i&&_arr.length===i));_n=!0);}catch(err){_d=!0,_e=err}finally{try{_n||null==_i["return"]||_i["return"]()}finally{if(_d)throw _e}}return _arr}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}import{Vector3}from"math.gl";import{createMat4,transformVector}from"./math-utils";import mat4_perspective from"gl-mat4/perspective";import mat4_scale from"gl-mat4/scale";import mat4_translate from"gl-mat4/translate";import mat4_rotateX from"gl-mat4/rotateX";import mat4_rotateZ from"gl-mat4/rotateZ";import vec2_lerp from"gl-vec2/lerp";import assert from"./assert";const PI=Math.PI,PI_4=PI/4,DEGREES_TO_RADIANS=PI/180,RADIANS_TO_DEGREES=180/PI,TILE_SIZE=512,EARTH_CIRCUMFERENCE=4003e4,DEFAULT_ALTITUDE=1.5;export function zoomToScale(zoom){return Math.pow(2,zoom)}export function scaleToZoom(scale){return Math.log2(scale)}export function lngLatToWorld([lng,lat],scale){scale*=TILE_SIZE;const x=scale*(lng*DEGREES_TO_RADIANS+PI)/(2*PI),y=scale*(PI-Math.log(Math.tan(PI_4+.5*(lat*DEGREES_TO_RADIANS))))/(2*PI);return[x,y]}export function worldToLngLat([x,y],scale){scale*=TILE_SIZE;const lambda2=x/scale*(2*PI)-PI,phi2=2*(Math.atan(Math.exp(PI-y/scale*(2*PI)))-PI_4);return[lambda2*RADIANS_TO_DEGREES,phi2*RADIANS_TO_DEGREES]}export function getMeterZoom({latitude}){assert(Number.isFinite(latitude));const latCosine=Math.cos(latitude*DEGREES_TO_RADIANS);return scaleToZoom(EARTH_CIRCUMFERENCE*latCosine)-9}export function getDistanceScales({latitude,longitude,zoom,scale,highPrecision=!1}){var _NumberisFinite=Number.isFinite;scale=void 0===scale?zoomToScale(zoom):scale,assert(_NumberisFinite(latitude)&&_NumberisFinite(longitude)&&_NumberisFinite(scale));const result={},worldSize=TILE_SIZE*scale,latCosine=Math.cos(latitude*DEGREES_TO_RADIANS),pixelsPerDegreeX=worldSize/360,pixelsPerDegreeY=pixelsPerDegreeX/latCosine,altPixelsPerMeter=worldSize/EARTH_CIRCUMFERENCE/latCosine;if(result.pixelsPerMeter=[altPixelsPerMeter,altPixelsPerMeter,altPixelsPerMeter],result.metersPerPixel=[1/altPixelsPerMeter,1/altPixelsPerMeter,1/altPixelsPerMeter],result.pixelsPerDegree=[pixelsPerDegreeX,pixelsPerDegreeY,altPixelsPerMeter],result.degreesPerPixel=[1/pixelsPerDegreeX,1/pixelsPerDegreeY,1/altPixelsPerMeter],highPrecision){const latCosine2=DEGREES_TO_RADIANS*Math.tan(latitude*DEGREES_TO_RADIANS)/latCosine,altPixelsPerDegree2=worldSize/EARTH_CIRCUMFERENCE*latCosine2,altPixelsPerMeter2=altPixelsPerDegree2/pixelsPerDegreeY*altPixelsPerMeter;result.pixelsPerDegree2=[0,pixelsPerDegreeX*latCosine2/2,altPixelsPerDegree2],result.pixelsPerMeter2=[altPixelsPerMeter2,0,altPixelsPerMeter2]}return result}export function getWorldPosition({longitude,latitude,zoom,scale,meterOffset,distanceScales=null}){scale=scale===void 0?zoomToScale(zoom):scale;const center2d=lngLatToWorld([longitude,latitude],scale),center=new Vector3(center2d[0],center2d[1],0);if(meterOffset){distanceScales=distanceScales||getDistanceScales({latitude,longitude,scale});const pixelPosition=new Vector3(meterOffset).scale(distanceScales.pixelsPerMeter).scale([1,-1,1]);center.add(pixelPosition)}return center}export function getViewMatrix({height,pitch,bearing,altitude,center=null,flipY=!1}){const vm=createMat4();return mat4_translate(vm,vm,[0,0,-altitude]),mat4_scale(vm,vm,[1,1,1/height]),mat4_rotateX(vm,vm,-pitch*DEGREES_TO_RADIANS),mat4_rotateZ(vm,vm,bearing*DEGREES_TO_RADIANS),flipY&&mat4_scale(vm,vm,[1,-1,1]),center&&mat4_translate(vm,vm,new Vector3(center).negate()),vm}export function getProjectionParameters({width,height,altitude=DEFAULT_ALTITUDE,pitch=0,farZMultiplier=1}){var _MathPI=Math.PI,_Mathsin=Math.sin,_Mathatan=Math.atan;const pitchRadians=pitch*DEGREES_TO_RADIANS,halfFov=_Mathatan(.5/altitude),topHalfSurfaceDistance=_Mathsin(halfFov)*altitude/_Mathsin(_MathPI/2-pitchRadians-halfFov),farZ=Math.cos(_MathPI/2-pitchRadians)*topHalfSurfaceDistance+altitude;return{fov:2*_Mathatan(height/2/altitude),aspect:width/height,focalDistance:altitude,near:.1,far:farZ*farZMultiplier}}export function getProjectionMatrix({width,height,pitch,altitude,farZMultiplier=10}){const _getProjectionParamet=getProjectionParameters({width,height,altitude,pitch,farZMultiplier}),fov=_getProjectionParamet.fov,aspect=_getProjectionParamet.aspect,near=_getProjectionParamet.near,far=_getProjectionParamet.far,projectionMatrix=mat4_perspective([],fov,aspect,near,far);return projectionMatrix}export function worldToPixels(xyz,pixelProjectionMatrix){var _NumberisFinite2=Number.isFinite;const _xyz=_slicedToArray(xyz,3),x=_xyz[0],y=_xyz[1],_xyz$=_xyz[2],z=void 0===_xyz$?0:_xyz$;return assert(_NumberisFinite2(x)&&_NumberisFinite2(y)&&_NumberisFinite2(z)),transformVector(pixelProjectionMatrix,[x,y,z,1])}export function pixelsToWorld(xyz,pixelUnprojectionMatrix,targetZ=0){var _NumberisFinite3=Number.isFinite;const _xyz2=_slicedToArray(xyz,3),x=_xyz2[0],y=_xyz2[1],z=_xyz2[2];if(assert(_NumberisFinite3(x)&&_NumberisFinite3(y)),_NumberisFinite3(z)){const coord=transformVector(pixelUnprojectionMatrix,[x,y,z,1]);return coord}const coord0=transformVector(pixelUnprojectionMatrix,[x,y,0,1]),coord1=transformVector(pixelUnprojectionMatrix,[x,y,1,1]),z0=coord0[2],z1=coord1[2],t=z0===z1?0:((targetZ||0)-z0)/(z1-z0);return vec2_lerp([],coord0,coord1,t)}
//# sourceMappingURL=web-mercator-utils.js.map

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

import Viewport from'./viewport';import{zoomToScale,getWorldPosition,pixelsToWorld,lngLatToWorld,worldToLngLat,getProjectionMatrix,getViewMatrix}from'./web-mercator-utils';import fitBounds from'./fit-bounds';import vec2_add from'gl-vec2/add';import vec2_negate from'gl-vec2/negate';export default class WebMercatorViewport extends Viewport{constructor({width,height,latitude=0,longitude=0,zoom=0,pitch=0,bearing=0,altitude=1.5,farZMultiplier=10}={}){width=width||1,height=height||1;const scale=zoomToScale(zoom);altitude=Math.max(.75,altitude);const center=getWorldPosition({longitude,latitude,scale}),projectionMatrix=getProjectionMatrix({width,height,pitch,bearing,altitude,farZMultiplier}),viewMatrix=getViewMatrix({height,center,pitch,bearing,altitude,flipY:!0});super({width,height,viewMatrix,projectionMatrix}),this.latitude=latitude,this.longitude=longitude,this.zoom=zoom,this.pitch=pitch,this.bearing=bearing,this.altitude=altitude,this.scale=scale,this.center=center,Object.freeze(this)}projectFlat(lngLat,scale=this.scale){return lngLatToWorld(lngLat,scale)}unprojectFlat(xy,scale=this.scale){return worldToLngLat(xy,scale)}getMapCenterByLngLatPosition({lngLat,pos}){const fromLocation=pixelsToWorld(pos,this.pixelUnprojectionMatrix),toLocation=lngLatToWorld(lngLat,this.scale),translate=vec2_add([],toLocation,vec2_negate([],fromLocation)),newCenter=vec2_add([],this.center,translate);return worldToLngLat(newCenter,this.scale)}getLocationAtPoint({lngLat,pos}){return this.getMapCenterByLngLatPosition({lngLat,pos})}fitBounds(bounds,options={}){const width=this.width,height=this.height;var _fitBounds=fitBounds(Object.assign({width,height,bounds},options));const longitude=_fitBounds.longitude,latitude=_fitBounds.latitude,zoom=_fitBounds.zoom;return new WebMercatorViewport({width,height,longitude,latitude,zoom})}}
import Viewport from"./viewport";import{zoomToScale,getWorldPosition,pixelsToWorld,lngLatToWorld,worldToLngLat,getProjectionMatrix,getViewMatrix}from"./web-mercator-utils";import fitBounds from"./fit-bounds";import vec2_add from"gl-vec2/add";import vec2_negate from"gl-vec2/negate";export default class WebMercatorViewport extends Viewport{constructor({width,height,latitude=0,longitude=0,zoom=0,pitch=0,bearing=0,altitude=1.5,farZMultiplier=10}={}){width=width||1,height=height||1;const scale=zoomToScale(zoom);altitude=Math.max(.75,altitude);const center=getWorldPosition({longitude,latitude,scale}),projectionMatrix=getProjectionMatrix({width,height,pitch,bearing,altitude,farZMultiplier}),viewMatrix=getViewMatrix({height,center,pitch,bearing,altitude,flipY:!0});super({width,height,viewMatrix,projectionMatrix}),this.latitude=latitude,this.longitude=longitude,this.zoom=zoom,this.pitch=pitch,this.bearing=bearing,this.altitude=altitude,this.scale=scale,this.center=center,Object.freeze(this)}projectFlat(lngLat,scale=this.scale){return lngLatToWorld(lngLat,scale)}unprojectFlat(xy,scale=this.scale){return worldToLngLat(xy,scale)}getMapCenterByLngLatPosition({lngLat,pos}){const fromLocation=pixelsToWorld(pos,this.pixelUnprojectionMatrix),toLocation=lngLatToWorld(lngLat,this.scale),translate=vec2_add([],toLocation,vec2_negate([],fromLocation)),newCenter=vec2_add([],this.center,translate);return worldToLngLat(newCenter,this.scale)}getLocationAtPoint({lngLat,pos}){return this.getMapCenterByLngLatPosition({lngLat,pos})}fitBounds(bounds,options={}){const width=this.width,height=this.height,_fitBounds=fitBounds(Object.assign({width,height,bounds},options)),longitude=_fitBounds.longitude,latitude=_fitBounds.latitude,zoom=_fitBounds.zoom;return new WebMercatorViewport({width,height,longitude,latitude,zoom})}}
//# sourceMappingURL=web-mercator-viewport.js.map

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

export default function assert(condition){if(!condition)throw new Error('viewport-mercator-project: assertion failed.')}
export default function assert(condition){if(!condition)throw new Error("viewport-mercator-project: assertion failed.")}
//# sourceMappingURL=assert.js.map

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

var _slicedToArray=function(){function sliceIterator(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!(i&&_arr.length===i));_n=!0);}catch(err){_d=!0,_e=err}finally{try{!_n&&_i['return']&&_i['return']()}finally{if(_d)throw _e}}return _arr}return function(arr,i){if(Array.isArray(arr))return arr;if(Symbol.iterator in Object(arr))return sliceIterator(arr,i);throw new TypeError('Invalid attempt to destructure non-iterable instance')}}();import WebMercatorViewport from'./web-mercator-viewport';export default function fitBounds(_ref){var _Mathabs=Math.abs,width=_ref.width,height=_ref.height,bounds=_ref.bounds,_ref$padding=_ref.padding,padding=void 0===_ref$padding?0:_ref$padding,_ref$offset=_ref.offset,offset=void 0===_ref$offset?[0,0]:_ref$offset,_bounds=_slicedToArray(bounds,2),_bounds$=_slicedToArray(_bounds[0],2),west=_bounds$[0],south=_bounds$[1],_bounds$2=_slicedToArray(_bounds[1],2),east=_bounds$2[0],north=_bounds$2[1],viewport=new WebMercatorViewport({width:width,height:height,longitude:0,latitude:0,zoom:0}),nw=viewport.project([west,north]),se=viewport.project([east,south]),size=[_Mathabs(se[0]-nw[0]),_Mathabs(se[1]-nw[1])],center=[(se[0]+nw[0])/2,(se[1]+nw[1])/2],scaleX=(width-2*padding-2*_Mathabs(offset[0]))/size[0],scaleY=(height-2*padding-2*_Mathabs(offset[1]))/size[1],centerLngLat=viewport.unproject(center),zoom=viewport.zoom+Math.log2(_Mathabs(Math.min(scaleX,scaleY)));return{longitude:centerLngLat[0],latitude:centerLngLat[1],zoom:zoom}}
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!(i&&_arr.length===i));_n=!0);}catch(err){_d=!0,_e=err}finally{try{_n||null==_i["return"]||_i["return"]()}finally{if(_d)throw _e}}return _arr}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}import WebMercatorViewport from"./web-mercator-viewport";import assert from"./assert";export default function fitBounds(_ref){var _Mathabs=Math.abs,_NumberisFinite=Number.isFinite,width=_ref.width,height=_ref.height,bounds=_ref.bounds,_ref$padding=_ref.padding,padding=void 0===_ref$padding?0:_ref$padding,_ref$offset=_ref.offset,offset=void 0===_ref$offset?[0,0]:_ref$offset,_bounds=_slicedToArray(bounds,2),_bounds$=_slicedToArray(_bounds[0],2),west=_bounds$[0],south=_bounds$[1],_bounds$2=_slicedToArray(_bounds[1],2),east=_bounds$2[0],north=_bounds$2[1];if(_NumberisFinite(padding)){var p=padding;padding={top:p,bottom:p,left:p,right:p}}else assert(_NumberisFinite(padding.top)&&_NumberisFinite(padding.bottom)&&_NumberisFinite(padding.left)&&_NumberisFinite(padding.right));var viewport=new WebMercatorViewport({width:width,height:height,longitude:0,latitude:0,zoom:0}),nw=viewport.project([west,north]),se=viewport.project([east,south]),size=[_Mathabs(se[0]-nw[0]),_Mathabs(se[1]-nw[1])],targetSize=[width-padding.left-padding.right-2*_Mathabs(offset[0]),height-padding.top-padding.bottom-2*_Mathabs(offset[1])];assert(0<targetSize[0]&&0<targetSize[1]);var scaleX=targetSize[0]/size[0],scaleY=targetSize[1]/size[1],offsetX=(padding.right-padding.left)/2/scaleX,offsetY=(padding.bottom-padding.top)/2/scaleY,center=[(se[0]+nw[0])/2+offsetX,(se[1]+nw[1])/2+offsetY],centerLngLat=viewport.unproject(center),zoom=viewport.zoom+Math.log2(_Mathabs(Math.min(scaleX,scaleY)));return{longitude:centerLngLat[0],latitude:centerLngLat[1],zoom:zoom}}
//# sourceMappingURL=fit-bounds.js.map

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

import{Vector2}from'math.gl';import{lerp}from'./math-utils';import{scaleToZoom,zoomToScale,lngLatToWorld,worldToLngLat}from'./web-mercator-utils';var EPSILON=.01,VIEWPORT_TRANSITION_PROPS=['longitude','latitude','zoom'];export default function flyToViewport(startProps,endProps,t){var _Mathcosh=Math.cosh,_Mathlog=Math.log,_Mathsqrt=Math.sqrt,viewport={},rho=1.414,startZoom=startProps.zoom,startCenter=[startProps.longitude,startProps.latitude],startScale=zoomToScale(startZoom),endZoom=endProps.zoom,endCenter=[endProps.longitude,endProps.latitude],scale=zoomToScale(endZoom-startZoom),startCenterXY=new Vector2(lngLatToWorld(startCenter,startScale)),endCenterXY=new Vector2(lngLatToWorld(endCenter,startScale)),uDelta=endCenterXY.subtract(startCenterXY),w0=Math.max(startProps.width,startProps.height),w1=w0/scale,u1=_Mathsqrt(uDelta.x*uDelta.x+uDelta.y*uDelta.y);if(Math.abs(u1)<EPSILON){var _iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0;try{for(var _step,_iterator=VIEWPORT_TRANSITION_PROPS[Symbol.iterator]();!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=!0){var key=_step.value,startValue=startProps[key],endValue=endProps[key];viewport[key]=lerp(startValue,endValue,t)}}catch(err){_didIteratorError=!0,_iteratorError=err}finally{try{!_iteratorNormalCompletion&&_iterator.return&&_iterator.return()}finally{if(_didIteratorError)throw _iteratorError}}return viewport}var rho2=rho*rho,b0=(w1*w1-w0*w0+rho2*rho2*u1*u1)/(2*w0*rho2*u1),b1=(w1*w1-w0*w0-rho2*rho2*u1*u1)/(2*w1*rho2*u1),r0=_Mathlog(_Mathsqrt(b0*b0+1)-b0),r1=_Mathlog(_Mathsqrt(b1*b1+1)-b1),s=t*((r1-r0)/rho),w=_Mathcosh(r0)/_Mathcosh(r0+rho*s),u=w0*((_Mathcosh(r0)*Math.tanh(r0+rho*s)-Math.sinh(r0))/rho2)/u1,scaleIncrement=1/w,newZoom=startZoom+scaleToZoom(scaleIncrement),newCenter=worldToLngLat(startCenterXY.add(uDelta.scale(u)).scale(scaleIncrement),zoomToScale(newZoom));return viewport.longitude=newCenter[0],viewport.latitude=newCenter[1],viewport.zoom=newZoom,viewport}
import{Vector2}from"math.gl";import{lerp}from"./math-utils";import{scaleToZoom,zoomToScale,lngLatToWorld,worldToLngLat}from"./web-mercator-utils";var EPSILON=.01,VIEWPORT_TRANSITION_PROPS=["longitude","latitude","zoom"];export default function flyToViewport(startProps,endProps,t){var _Mathcosh=Math.cosh,_Mathlog=Math.log,_Mathsqrt=Math.sqrt,viewport={},rho=1.414,startZoom=startProps.zoom,startCenter=[startProps.longitude,startProps.latitude],startScale=zoomToScale(startZoom),endZoom=endProps.zoom,endCenter=[endProps.longitude,endProps.latitude],scale=zoomToScale(endZoom-startZoom),startCenterXY=new Vector2(lngLatToWorld(startCenter,startScale)),endCenterXY=new Vector2(lngLatToWorld(endCenter,startScale)),uDelta=endCenterXY.subtract(startCenterXY),w0=Math.max(startProps.width,startProps.height),w1=w0/scale,u1=_Mathsqrt(uDelta.x*uDelta.x+uDelta.y*uDelta.y);if(Math.abs(u1)<EPSILON){for(var _i=0;_i<VIEWPORT_TRANSITION_PROPS.length;_i++){var key=VIEWPORT_TRANSITION_PROPS[_i],startValue=startProps[key],endValue=endProps[key];viewport[key]=lerp(startValue,endValue,t)}return viewport}var rho2=rho*rho,b0=(w1*w1-w0*w0+rho2*rho2*u1*u1)/(2*w0*rho2*u1),b1=(w1*w1-w0*w0-rho2*rho2*u1*u1)/(2*w1*rho2*u1),r0=_Mathlog(_Mathsqrt(b0*b0+1)-b0),r1=_Mathlog(_Mathsqrt(b1*b1+1)-b1),s=t*((r1-r0)/rho),w=_Mathcosh(r0)/_Mathcosh(r0+rho*s),u=w0*((_Mathcosh(r0)*Math.tanh(r0+rho*s)-Math.sinh(r0))/rho2)/u1,scaleIncrement=1/w,newZoom=startZoom+scaleToZoom(scaleIncrement),newCenter=worldToLngLat(startCenterXY.add(uDelta.scale(u)).scale(scaleIncrement),zoomToScale(newZoom));return viewport.longitude=newCenter[0],viewport.latitude=newCenter[1],viewport.zoom=newZoom,viewport}
//# sourceMappingURL=fly-to-viewport.js.map

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

export{default}from'./web-mercator-viewport';export{default as WebMercatorViewport}from'./web-mercator-viewport';export{default as fitBounds}from'./fit-bounds';export{default as normalizeViewportProps}from'./normalize-viewport-props';export{default as flyToViewport}from'./fly-to-viewport';export{lngLatToWorld,worldToLngLat,worldToPixels,pixelsToWorld,getMeterZoom,getDistanceScales,getWorldPosition,getViewMatrix,getProjectionMatrix,getProjectionParameters}from'./web-mercator-utils';export{default as PerspectiveMercatorViewport}from'./web-mercator-viewport';export{getViewMatrix as getUncenteredViewMatrix,lngLatToWorld as projectFlat,worldToLngLat as unprojectFlat}from'./web-mercator-utils';
export{default}from"./web-mercator-viewport";export{default as WebMercatorViewport}from"./web-mercator-viewport";export{default as fitBounds}from"./fit-bounds";export{default as normalizeViewportProps}from"./normalize-viewport-props";export{default as flyToViewport}from"./fly-to-viewport";export{lngLatToWorld,worldToLngLat,worldToPixels,pixelsToWorld,getMeterZoom,getDistanceScales,getWorldPosition,getViewMatrix,getProjectionMatrix,getProjectionParameters}from"./web-mercator-utils";export{default as PerspectiveMercatorViewport}from"./web-mercator-viewport";export{getViewMatrix as getUncenteredViewMatrix,lngLatToWorld as projectFlat,worldToLngLat as unprojectFlat}from"./web-mercator-utils";
//# sourceMappingURL=index.js.map

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

import vec4_scale from'gl-vec4/scale';import vec4_transformMat4 from'gl-vec4/transformMat4';export function createMat4(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}export function transformVector(matrix,vector){var result=vec4_transformMat4([],vector,matrix);return vec4_scale(result,result,1/result[3]),result}export function mod(value,divisor){var modulus=value%divisor;return 0>modulus?divisor+modulus:modulus}export function lerp(start,end,step){return step*end+(1-step)*start}
import vec4_scale from"gl-vec4/scale";import vec4_transformMat4 from"gl-vec4/transformMat4";export function createMat4(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}export function transformVector(matrix,vector){var result=vec4_transformMat4([],vector,matrix);return vec4_scale(result,result,1/result[3]),result}export function mod(value,divisor){var modulus=value%divisor;return 0>modulus?divisor+modulus:modulus}export function lerp(start,end,step){return step*end+(1-step)*start}
//# sourceMappingURL=math-utils.js.map

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

import WebMercatorViewport from'./web-mercator-viewport';import{mod}from'./math-utils';var MAX_LATITUDE=85.05113,MIN_LATITUDE=-85.05113;export default function normalizeViewportProps(_ref){var width=_ref.width,height=_ref.height,longitude=_ref.longitude,latitude=_ref.latitude,zoom=_ref.zoom,_ref$pitch=_ref.pitch,pitch=void 0===_ref$pitch?0:_ref$pitch,_ref$bearing=_ref.bearing,bearing=void 0===_ref$bearing?0:_ref$bearing;(-180>longitude||180<longitude)&&(longitude=mod(longitude+180,360)-180),(-180>bearing||180<bearing)&&(bearing=mod(bearing+180,360)-180);var flatViewport=new WebMercatorViewport({width:width,height:height,longitude:longitude,latitude:latitude,zoom:zoom}),topY=flatViewport.project([longitude,MAX_LATITUDE])[1],bottomY=flatViewport.project([longitude,MIN_LATITUDE])[1],shiftY=0;return bottomY-topY<height&&(zoom+=Math.log2(height/(bottomY-topY)),flatViewport=new WebMercatorViewport({width:width,height:height,longitude:longitude,latitude:latitude,zoom:zoom}),topY=flatViewport.project([longitude,MAX_LATITUDE])[1],bottomY=flatViewport.project([longitude,MIN_LATITUDE])[1]),0<topY?shiftY=topY:bottomY<height&&(shiftY=bottomY-height),shiftY&&(latitude=flatViewport.unproject([width/2,height/2+shiftY])[1]),{width:width,height:height,longitude:longitude,latitude:latitude,zoom:zoom,pitch:pitch,bearing:bearing}}
import WebMercatorViewport from"./web-mercator-viewport";import{mod}from"./math-utils";var MAX_LATITUDE=85.05113,MIN_LATITUDE=-85.05113;export default function normalizeViewportProps(_ref){var width=_ref.width,height=_ref.height,longitude=_ref.longitude,latitude=_ref.latitude,zoom=_ref.zoom,_ref$pitch=_ref.pitch,pitch=void 0===_ref$pitch?0:_ref$pitch,_ref$bearing=_ref.bearing,bearing=void 0===_ref$bearing?0:_ref$bearing;(-180>longitude||180<longitude)&&(longitude=mod(longitude+180,360)-180),(-180>bearing||180<bearing)&&(bearing=mod(bearing+180,360)-180);var flatViewport=new WebMercatorViewport({width:width,height:height,longitude:longitude,latitude:latitude,zoom:zoom}),topY=flatViewport.project([longitude,MAX_LATITUDE])[1],bottomY=flatViewport.project([longitude,MIN_LATITUDE])[1],shiftY=0;return bottomY-topY<height&&(zoom+=Math.log2(height/(bottomY-topY)),flatViewport=new WebMercatorViewport({width:width,height:height,longitude:longitude,latitude:latitude,zoom:zoom}),topY=flatViewport.project([longitude,MAX_LATITUDE])[1],bottomY=flatViewport.project([longitude,MIN_LATITUDE])[1]),0<topY?shiftY=topY:bottomY<height&&(shiftY=bottomY-height),shiftY&&(latitude=flatViewport.unproject([width/2,height/2+shiftY])[1]),{width:width,height:height,longitude:longitude,latitude:latitude,zoom:zoom,pitch:pitch,bearing:bearing}}
//# sourceMappingURL=normalize-viewport-props.js.map

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

var _slicedToArray=function(){function sliceIterator(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!(i&&_arr.length===i));_n=!0);}catch(err){_d=!0,_e=err}finally{try{!_n&&_i['return']&&_i['return']()}finally{if(_d)throw _e}}return _arr}return function(arr,i){if(Array.isArray(arr))return arr;if(Symbol.iterator in Object(arr))return sliceIterator(arr,i);throw new TypeError('Invalid attempt to destructure non-iterable instance')}}(),_createClass=function(){function defineProperties(target,props){for(var descriptor,i=0;i<props.length;i++)descriptor=props[i],descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,'value'in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}return function(Constructor,protoProps,staticProps){return protoProps&&defineProperties(Constructor.prototype,protoProps),staticProps&&defineProperties(Constructor,staticProps),Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError('Cannot call a class as a function')}import{equals as _equals}from'math.gl';import{createMat4}from'./math-utils';import{worldToPixels,pixelsToWorld}from'./web-mercator-utils';import mat4_scale from'gl-mat4/scale';import mat4_translate from'gl-mat4/translate';import mat4_multiply from'gl-mat4/multiply';import mat4_invert from'gl-mat4/invert';var IDENTITY=createMat4(),Viewport=function(){function Viewport(){var _ref=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},width=_ref.width,height=_ref.height,_ref$viewMatrix=_ref.viewMatrix,viewMatrix=void 0===_ref$viewMatrix?IDENTITY:_ref$viewMatrix,_ref$projectionMatrix=_ref.projectionMatrix,projectionMatrix=void 0===_ref$projectionMatrix?IDENTITY:_ref$projectionMatrix;_classCallCheck(this,Viewport),this.width=width||1,this.height=height||1,this.scale=1,this.viewMatrix=viewMatrix,this.projectionMatrix=projectionMatrix;var vpm=createMat4();mat4_multiply(vpm,vpm,this.projectionMatrix),mat4_multiply(vpm,vpm,this.viewMatrix),this.viewProjectionMatrix=vpm;var m=createMat4();mat4_scale(m,m,[this.width/2,-this.height/2,1]),mat4_translate(m,m,[1,-1,0]),mat4_multiply(m,m,this.viewProjectionMatrix);var mInverse=mat4_invert(createMat4(),m);if(!mInverse)throw new Error('Pixel project matrix not invertible');this.pixelProjectionMatrix=m,this.pixelUnprojectionMatrix=mInverse,this.equals=this.equals.bind(this),this.project=this.project.bind(this),this.unproject=this.unproject.bind(this),this.projectFlat=this.projectFlat.bind(this),this.unprojectFlat=this.unprojectFlat.bind(this)}return _createClass(Viewport,[{key:'equals',value:function equals(viewport){return!!(viewport instanceof Viewport)&&viewport.width===this.width&&viewport.height===this.height&&_equals(viewport.projectionMatrix,this.projectionMatrix)&&_equals(viewport.viewMatrix,this.viewMatrix)}},{key:'project',value:function project(xyz){var _ref2=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},_ref2$topLeft=_ref2.topLeft,_xyz=_slicedToArray(xyz,3),x0=_xyz[0],y0=_xyz[1],z0=_xyz[2],_projectFlat=this.projectFlat([x0,y0]),_projectFlat2=_slicedToArray(_projectFlat,2),X=_projectFlat2[0],Y=_projectFlat2[1],coord=worldToPixels([X,Y,z0],this.pixelProjectionMatrix),_coord=_slicedToArray(coord,2),x=_coord[0],y=_coord[1],y2=void 0===_ref2$topLeft||_ref2$topLeft?y:this.height-y;return 2===xyz.length?[x,y2]:[x,y2,coord[2]]}},{key:'unproject',value:function unproject(xyz){var _NumberisFinite=Number.isFinite,_ref3=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},_ref3$topLeft=_ref3.topLeft,targetZ=_ref3.targetZ,_xyz2=_slicedToArray(xyz,3),x=_xyz2[0],y=_xyz2[1],z=_xyz2[2],y2=void 0===_ref3$topLeft||_ref3$topLeft?y:this.height-y,coord=pixelsToWorld([x,y2,z],this.pixelUnprojectionMatrix,targetZ),_unprojectFlat=this.unprojectFlat(coord),_unprojectFlat2=_slicedToArray(_unprojectFlat,2),X=_unprojectFlat2[0],Y=_unprojectFlat2[1];return _NumberisFinite(z)?[X,Y,coord[2]]:_NumberisFinite(targetZ)?[X,Y,targetZ]:[X,Y]}},{key:'projectFlat',value:function projectFlat(xyz){1<arguments.length&&void 0!==arguments[1]?arguments[1]:this.scale;return xyz}},{key:'unprojectFlat',value:function unprojectFlat(xyz){1<arguments.length&&void 0!==arguments[1]?arguments[1]:this.scale;return xyz}}]),Viewport}();export default Viewport;
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!(i&&_arr.length===i));_n=!0);}catch(err){_d=!0,_e=err}finally{try{_n||null==_i["return"]||_i["return"]()}finally{if(_d)throw _e}}return _arr}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}function _instanceof(left,right){return null!=right&&"undefined"!=typeof Symbol&&right[Symbol.hasInstance]?right[Symbol.hasInstance](left):left instanceof right}function _classCallCheck(instance,Constructor){if(!_instanceof(instance,Constructor))throw new TypeError("Cannot call a class as a function")}function _defineProperties(target,props){for(var descriptor,i=0;i<props.length;i++)descriptor=props[i],descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}function _createClass(Constructor,protoProps,staticProps){return protoProps&&_defineProperties(Constructor.prototype,protoProps),staticProps&&_defineProperties(Constructor,staticProps),Constructor}import{equals as _equals}from"math.gl";import{createMat4}from"./math-utils";import{worldToPixels,pixelsToWorld}from"./web-mercator-utils";import mat4_scale from"gl-mat4/scale";import mat4_translate from"gl-mat4/translate";import mat4_multiply from"gl-mat4/multiply";import mat4_invert from"gl-mat4/invert";var IDENTITY=createMat4(),Viewport=function(){function Viewport(){var _ref=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},width=_ref.width,height=_ref.height,_ref$viewMatrix=_ref.viewMatrix,viewMatrix=void 0===_ref$viewMatrix?IDENTITY:_ref$viewMatrix,_ref$projectionMatrix=_ref.projectionMatrix,projectionMatrix=void 0===_ref$projectionMatrix?IDENTITY:_ref$projectionMatrix;_classCallCheck(this,Viewport),this.width=width||1,this.height=height||1,this.scale=1,this.viewMatrix=viewMatrix,this.projectionMatrix=projectionMatrix;var vpm=createMat4();mat4_multiply(vpm,vpm,this.projectionMatrix),mat4_multiply(vpm,vpm,this.viewMatrix),this.viewProjectionMatrix=vpm;var m=createMat4();mat4_scale(m,m,[this.width/2,-this.height/2,1]),mat4_translate(m,m,[1,-1,0]),mat4_multiply(m,m,this.viewProjectionMatrix);var mInverse=mat4_invert(createMat4(),m);if(!mInverse)throw new Error("Pixel project matrix not invertible");this.pixelProjectionMatrix=m,this.pixelUnprojectionMatrix=mInverse,this.equals=this.equals.bind(this),this.project=this.project.bind(this),this.unproject=this.unproject.bind(this),this.projectFlat=this.projectFlat.bind(this),this.unprojectFlat=this.unprojectFlat.bind(this)}return _createClass(Viewport,[{key:"equals",value:function equals(viewport){return!!_instanceof(viewport,Viewport)&&viewport.width===this.width&&viewport.height===this.height&&_equals(viewport.projectionMatrix,this.projectionMatrix)&&_equals(viewport.viewMatrix,this.viewMatrix)}},{key:"project",value:function project(xyz){var _ref2=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},_ref2$topLeft=_ref2.topLeft,_xyz=_slicedToArray(xyz,3),x0=_xyz[0],y0=_xyz[1],z0=_xyz[2],_projectFlat=this.projectFlat([x0,y0]),_projectFlat2=_slicedToArray(_projectFlat,2),X=_projectFlat2[0],Y=_projectFlat2[1],coord=worldToPixels([X,Y,z0],this.pixelProjectionMatrix),_coord=_slicedToArray(coord,2),x=_coord[0],y=_coord[1],y2=void 0===_ref2$topLeft||_ref2$topLeft?y:this.height-y;return 2===xyz.length?[x,y2]:[x,y2,coord[2]]}},{key:"unproject",value:function unproject(xyz){var _NumberisFinite=Number.isFinite,_ref3=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},_ref3$topLeft=_ref3.topLeft,targetZ=_ref3.targetZ,_xyz2=_slicedToArray(xyz,3),x=_xyz2[0],y=_xyz2[1],z=_xyz2[2],y2=void 0===_ref3$topLeft||_ref3$topLeft?y:this.height-y,coord=pixelsToWorld([x,y2,z],this.pixelUnprojectionMatrix,targetZ),_unprojectFlat=this.unprojectFlat(coord),_unprojectFlat2=_slicedToArray(_unprojectFlat,2),X=_unprojectFlat2[0],Y=_unprojectFlat2[1];return _NumberisFinite(z)?[X,Y,coord[2]]:_NumberisFinite(targetZ)?[X,Y,targetZ]:[X,Y]}},{key:"projectFlat",value:function projectFlat(xyz){1<arguments.length&&void 0!==arguments[1]?arguments[1]:this.scale;return xyz}},{key:"unprojectFlat",value:function unprojectFlat(xyz){1<arguments.length&&void 0!==arguments[1]?arguments[1]:this.scale;return xyz}}]),Viewport}();export{Viewport as default};
//# sourceMappingURL=viewport.js.map

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

var _slicedToArray=function(){function sliceIterator(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!(i&&_arr.length===i));_n=!0);}catch(err){_d=!0,_e=err}finally{try{!_n&&_i['return']&&_i['return']()}finally{if(_d)throw _e}}return _arr}return function(arr,i){if(Array.isArray(arr))return arr;if(Symbol.iterator in Object(arr))return sliceIterator(arr,i);throw new TypeError('Invalid attempt to destructure non-iterable instance')}}();import{Vector3}from'math.gl';import{createMat4,transformVector}from'./math-utils';import mat4_perspective from'gl-mat4/perspective';import mat4_scale from'gl-mat4/scale';import mat4_translate from'gl-mat4/translate';import mat4_rotateX from'gl-mat4/rotateX';import mat4_rotateZ from'gl-mat4/rotateZ';import vec2_lerp from'gl-vec2/lerp';import assert from'./assert';var PI=Math.PI,PI_4=PI/4,DEGREES_TO_RADIANS=PI/180,RADIANS_TO_DEGREES=180/PI,TILE_SIZE=512,EARTH_CIRCUMFERENCE=4003e4,DEFAULT_ALITITUDE=1.5;export function zoomToScale(zoom){return Math.pow(2,zoom)}export function scaleToZoom(scale){return Math.log2(scale)}export function lngLatToWorld(_ref,scale){var _ref2=_slicedToArray(_ref,2),lng=_ref2[0],lat=_ref2[1];scale*=TILE_SIZE;var x=scale*(lng*DEGREES_TO_RADIANS+PI)/(2*PI),y=scale*(PI-Math.log(Math.tan(PI_4+.5*(lat*DEGREES_TO_RADIANS))))/(2*PI);return[x,y]}export function worldToLngLat(_ref3,scale){var _ref4=_slicedToArray(_ref3,2),x=_ref4[0],y=_ref4[1];scale*=TILE_SIZE;var lambda2=x/scale*(2*PI)-PI,phi2=2*(Math.atan(Math.exp(PI-y/scale*(2*PI)))-PI_4);return[lambda2*RADIANS_TO_DEGREES,phi2*RADIANS_TO_DEGREES]}export function getMeterZoom(_ref5){var latitude=_ref5.latitude;assert(Number.isFinite(latitude));var latCosine=Math.cos(latitude*DEGREES_TO_RADIANS);return scaleToZoom(EARTH_CIRCUMFERENCE*latCosine)-8}export function getDistanceScales(_ref6){var _NumberisFinite=Number.isFinite,latitude=_ref6.latitude,longitude=_ref6.longitude,zoom=_ref6.zoom,scale=_ref6.scale,_ref6$highPrecision=_ref6.highPrecision;scale=void 0===scale?zoomToScale(zoom):scale,assert(_NumberisFinite(latitude)&&_NumberisFinite(longitude)&&_NumberisFinite(scale));var result={},worldSize=TILE_SIZE*scale,latCosine=Math.cos(latitude*DEGREES_TO_RADIANS),pixelsPerDegreeX=worldSize/360,pixelsPerDegreeY=pixelsPerDegreeX/latCosine,altPixelsPerMeter=worldSize/EARTH_CIRCUMFERENCE/latCosine;if(result.pixelsPerMeter=[altPixelsPerMeter,altPixelsPerMeter,altPixelsPerMeter],result.metersPerPixel=[1/altPixelsPerMeter,1/altPixelsPerMeter,1/altPixelsPerMeter],result.pixelsPerDegree=[pixelsPerDegreeX,pixelsPerDegreeY,altPixelsPerMeter],result.degreesPerPixel=[1/pixelsPerDegreeX,1/pixelsPerDegreeY,1/altPixelsPerMeter],void 0!==_ref6$highPrecision&&_ref6$highPrecision){var latCosine2=DEGREES_TO_RADIANS*Math.tan(latitude*DEGREES_TO_RADIANS)/latCosine,altPixelsPerDegree2=worldSize/EARTH_CIRCUMFERENCE*latCosine2,altPixelsPerMeter2=altPixelsPerDegree2/pixelsPerDegreeY*altPixelsPerMeter;result.pixelsPerDegree2=[0,pixelsPerDegreeX*latCosine2/2,altPixelsPerDegree2],result.pixelsPerMeter2=[altPixelsPerMeter2,0,altPixelsPerMeter2]}return result}export function getWorldPosition(_ref7){var longitude=_ref7.longitude,latitude=_ref7.latitude,zoom=_ref7.zoom,scale=_ref7.scale,meterOffset=_ref7.meterOffset,_ref7$distanceScales=_ref7.distanceScales,distanceScales=_ref7$distanceScales===void 0?null:_ref7$distanceScales;scale=scale===void 0?zoomToScale(zoom):scale;var center2d=lngLatToWorld([longitude,latitude],scale),center=new Vector3(center2d[0],center2d[1],0);if(meterOffset){distanceScales=distanceScales||getDistanceScales({latitude:latitude,longitude:longitude,scale:scale});var pixelPosition=new Vector3(meterOffset).scale(distanceScales.pixelsPerMeter).scale([1,-1,1]);center.add(pixelPosition)}return center}export function getViewMatrix(_ref8){var height=_ref8.height,pitch=_ref8.pitch,bearing=_ref8.bearing,altitude=_ref8.altitude,_ref8$center=_ref8.center,center=void 0===_ref8$center?null:_ref8$center,_ref8$flipY=_ref8.flipY,vm=createMat4();return mat4_translate(vm,vm,[0,0,-altitude]),mat4_scale(vm,vm,[1,1,1/height]),mat4_rotateX(vm,vm,-pitch*DEGREES_TO_RADIANS),mat4_rotateZ(vm,vm,bearing*DEGREES_TO_RADIANS),void 0!==_ref8$flipY&&_ref8$flipY&&mat4_scale(vm,vm,[1,-1,1]),center&&mat4_translate(vm,vm,new Vector3(center).negate()),vm}export function getProjectionParameters(_ref9){var _MathPI=Math.PI,_Mathsin=Math.sin,_Mathatan=Math.atan,width=_ref9.width,height=_ref9.height,_ref9$altitude=_ref9.altitude,altitude=void 0===_ref9$altitude?DEFAULT_ALITITUDE:_ref9$altitude,_ref9$pitch=_ref9.pitch,pitch=void 0===_ref9$pitch?0:_ref9$pitch,_ref9$farZMultiplier=_ref9.farZMultiplier,farZMultiplier=void 0===_ref9$farZMultiplier?1:_ref9$farZMultiplier,pitchRadians=pitch*DEGREES_TO_RADIANS,halfFov=_Mathatan(.5/altitude),topHalfSurfaceDistance=_Mathsin(halfFov)*altitude/_Mathsin(_MathPI/2-pitchRadians-halfFov),farZ=Math.cos(_MathPI/2-pitchRadians)*topHalfSurfaceDistance+altitude;return{fov:2*_Mathatan(height/2/altitude),aspect:width/height,focalDistance:altitude,near:.1,far:farZ*farZMultiplier}}export function getProjectionMatrix(_ref10){var width=_ref10.width,height=_ref10.height,pitch=_ref10.pitch,altitude=_ref10.altitude,_ref10$farZMultiplier=_ref10.farZMultiplier,farZMultiplier=_ref10$farZMultiplier===void 0?10:_ref10$farZMultiplier,_getProjectionParamet=getProjectionParameters({width:width,height:height,altitude:altitude,pitch:pitch,farZMultiplier:farZMultiplier}),fov=_getProjectionParamet.fov,aspect=_getProjectionParamet.aspect,near=_getProjectionParamet.near,far=_getProjectionParamet.far,projectionMatrix=mat4_perspective([],fov,aspect,near,far);return projectionMatrix}export function worldToPixels(xyz,pixelProjectionMatrix){var _NumberisFinite2=Number.isFinite,_xyz=_slicedToArray(xyz,3),x=_xyz[0],y=_xyz[1],_xyz$=_xyz[2],z=void 0===_xyz$?0:_xyz$;return assert(_NumberisFinite2(x)&&_NumberisFinite2(y)&&_NumberisFinite2(z)),transformVector(pixelProjectionMatrix,[x,y,z,1])}export function pixelsToWorld(xyz,pixelUnprojectionMatrix){var _NumberisFinite3=Number.isFinite,targetZ=2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,_xyz2=_slicedToArray(xyz,3),x=_xyz2[0],y=_xyz2[1],z=_xyz2[2];if(assert(_NumberisFinite3(x)&&_NumberisFinite3(y)),_NumberisFinite3(z)){var coord=transformVector(pixelUnprojectionMatrix,[x,y,z,1]);return coord}var coord0=transformVector(pixelUnprojectionMatrix,[x,y,0,1]),coord1=transformVector(pixelUnprojectionMatrix,[x,y,1,1]),z0=coord0[2],z1=coord1[2],t=z0===z1?0:((targetZ||0)-z0)/(z1-z0);return vec2_lerp([],coord0,coord1,t)}
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!(i&&_arr.length===i));_n=!0);}catch(err){_d=!0,_e=err}finally{try{_n||null==_i["return"]||_i["return"]()}finally{if(_d)throw _e}}return _arr}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}import{Vector3}from"math.gl";import{createMat4,transformVector}from"./math-utils";import mat4_perspective from"gl-mat4/perspective";import mat4_scale from"gl-mat4/scale";import mat4_translate from"gl-mat4/translate";import mat4_rotateX from"gl-mat4/rotateX";import mat4_rotateZ from"gl-mat4/rotateZ";import vec2_lerp from"gl-vec2/lerp";import assert from"./assert";var PI=Math.PI,PI_4=PI/4,DEGREES_TO_RADIANS=PI/180,RADIANS_TO_DEGREES=180/PI,TILE_SIZE=512,EARTH_CIRCUMFERENCE=4003e4,DEFAULT_ALTITUDE=1.5;export function zoomToScale(zoom){return Math.pow(2,zoom)}export function scaleToZoom(scale){return Math.log2(scale)}export function lngLatToWorld(_ref,scale){var _ref2=_slicedToArray(_ref,2),lng=_ref2[0],lat=_ref2[1];scale*=TILE_SIZE;var x=scale*(lng*DEGREES_TO_RADIANS+PI)/(2*PI),y=scale*(PI-Math.log(Math.tan(PI_4+.5*(lat*DEGREES_TO_RADIANS))))/(2*PI);return[x,y]}export function worldToLngLat(_ref3,scale){var _ref4=_slicedToArray(_ref3,2),x=_ref4[0],y=_ref4[1];scale*=TILE_SIZE;var lambda2=x/scale*(2*PI)-PI,phi2=2*(Math.atan(Math.exp(PI-y/scale*(2*PI)))-PI_4);return[lambda2*RADIANS_TO_DEGREES,phi2*RADIANS_TO_DEGREES]}export function getMeterZoom(_ref5){var latitude=_ref5.latitude;assert(Number.isFinite(latitude));var latCosine=Math.cos(latitude*DEGREES_TO_RADIANS);return scaleToZoom(EARTH_CIRCUMFERENCE*latCosine)-9}export function getDistanceScales(_ref6){var _NumberisFinite=Number.isFinite,latitude=_ref6.latitude,longitude=_ref6.longitude,zoom=_ref6.zoom,scale=_ref6.scale,_ref6$highPrecision=_ref6.highPrecision;scale=void 0===scale?zoomToScale(zoom):scale,assert(_NumberisFinite(latitude)&&_NumberisFinite(longitude)&&_NumberisFinite(scale));var result={},worldSize=TILE_SIZE*scale,latCosine=Math.cos(latitude*DEGREES_TO_RADIANS),pixelsPerDegreeX=worldSize/360,pixelsPerDegreeY=pixelsPerDegreeX/latCosine,altPixelsPerMeter=worldSize/EARTH_CIRCUMFERENCE/latCosine;if(result.pixelsPerMeter=[altPixelsPerMeter,altPixelsPerMeter,altPixelsPerMeter],result.metersPerPixel=[1/altPixelsPerMeter,1/altPixelsPerMeter,1/altPixelsPerMeter],result.pixelsPerDegree=[pixelsPerDegreeX,pixelsPerDegreeY,altPixelsPerMeter],result.degreesPerPixel=[1/pixelsPerDegreeX,1/pixelsPerDegreeY,1/altPixelsPerMeter],void 0!==_ref6$highPrecision&&_ref6$highPrecision){var latCosine2=DEGREES_TO_RADIANS*Math.tan(latitude*DEGREES_TO_RADIANS)/latCosine,altPixelsPerDegree2=worldSize/EARTH_CIRCUMFERENCE*latCosine2,altPixelsPerMeter2=altPixelsPerDegree2/pixelsPerDegreeY*altPixelsPerMeter;result.pixelsPerDegree2=[0,pixelsPerDegreeX*latCosine2/2,altPixelsPerDegree2],result.pixelsPerMeter2=[altPixelsPerMeter2,0,altPixelsPerMeter2]}return result}export function getWorldPosition(_ref7){var longitude=_ref7.longitude,latitude=_ref7.latitude,zoom=_ref7.zoom,scale=_ref7.scale,meterOffset=_ref7.meterOffset,_ref7$distanceScales=_ref7.distanceScales,distanceScales=void 0===_ref7$distanceScales?null:_ref7$distanceScales;scale=scale===void 0?zoomToScale(zoom):scale;var center2d=lngLatToWorld([longitude,latitude],scale),center=new Vector3(center2d[0],center2d[1],0);if(meterOffset){distanceScales=distanceScales||getDistanceScales({latitude:latitude,longitude:longitude,scale:scale});var pixelPosition=new Vector3(meterOffset).scale(distanceScales.pixelsPerMeter).scale([1,-1,1]);center.add(pixelPosition)}return center}export function getViewMatrix(_ref8){var height=_ref8.height,pitch=_ref8.pitch,bearing=_ref8.bearing,altitude=_ref8.altitude,_ref8$center=_ref8.center,center=void 0===_ref8$center?null:_ref8$center,_ref8$flipY=_ref8.flipY,vm=createMat4();return mat4_translate(vm,vm,[0,0,-altitude]),mat4_scale(vm,vm,[1,1,1/height]),mat4_rotateX(vm,vm,-pitch*DEGREES_TO_RADIANS),mat4_rotateZ(vm,vm,bearing*DEGREES_TO_RADIANS),void 0!==_ref8$flipY&&_ref8$flipY&&mat4_scale(vm,vm,[1,-1,1]),center&&mat4_translate(vm,vm,new Vector3(center).negate()),vm}export function getProjectionParameters(_ref9){var _MathPI=Math.PI,_Mathsin=Math.sin,_Mathatan=Math.atan,width=_ref9.width,height=_ref9.height,_ref9$altitude=_ref9.altitude,altitude=void 0===_ref9$altitude?DEFAULT_ALTITUDE:_ref9$altitude,_ref9$pitch=_ref9.pitch,pitch=void 0===_ref9$pitch?0:_ref9$pitch,_ref9$farZMultiplier=_ref9.farZMultiplier,farZMultiplier=void 0===_ref9$farZMultiplier?1:_ref9$farZMultiplier,pitchRadians=pitch*DEGREES_TO_RADIANS,halfFov=_Mathatan(.5/altitude),topHalfSurfaceDistance=_Mathsin(halfFov)*altitude/_Mathsin(_MathPI/2-pitchRadians-halfFov),farZ=Math.cos(_MathPI/2-pitchRadians)*topHalfSurfaceDistance+altitude;return{fov:2*_Mathatan(height/2/altitude),aspect:width/height,focalDistance:altitude,near:.1,far:farZ*farZMultiplier}}export function getProjectionMatrix(_ref10){var width=_ref10.width,height=_ref10.height,pitch=_ref10.pitch,altitude=_ref10.altitude,_ref10$farZMultiplier=_ref10.farZMultiplier,farZMultiplier=void 0===_ref10$farZMultiplier?10:_ref10$farZMultiplier,_getProjectionParamet=getProjectionParameters({width:width,height:height,altitude:altitude,pitch:pitch,farZMultiplier:farZMultiplier}),fov=_getProjectionParamet.fov,aspect=_getProjectionParamet.aspect,near=_getProjectionParamet.near,far=_getProjectionParamet.far,projectionMatrix=mat4_perspective([],fov,aspect,near,far);return projectionMatrix}export function worldToPixels(xyz,pixelProjectionMatrix){var _NumberisFinite2=Number.isFinite,_xyz=_slicedToArray(xyz,3),x=_xyz[0],y=_xyz[1],_xyz$=_xyz[2],z=void 0===_xyz$?0:_xyz$;return assert(_NumberisFinite2(x)&&_NumberisFinite2(y)&&_NumberisFinite2(z)),transformVector(pixelProjectionMatrix,[x,y,z,1])}export function pixelsToWorld(xyz,pixelUnprojectionMatrix){var _NumberisFinite3=Number.isFinite,targetZ=2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,_xyz2=_slicedToArray(xyz,3),x=_xyz2[0],y=_xyz2[1],z=_xyz2[2];if(assert(_NumberisFinite3(x)&&_NumberisFinite3(y)),_NumberisFinite3(z)){var coord=transformVector(pixelUnprojectionMatrix,[x,y,z,1]);return coord}var coord0=transformVector(pixelUnprojectionMatrix,[x,y,0,1]),coord1=transformVector(pixelUnprojectionMatrix,[x,y,1,1]),z0=coord0[2],z1=coord1[2],t=z0===z1?0:((targetZ||0)-z0)/(z1-z0);return vec2_lerp([],coord0,coord1,t)}
//# sourceMappingURL=web-mercator-utils.js.map

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

var _createClass=function(){function defineProperties(target,props){for(var descriptor,i=0;i<props.length;i++)descriptor=props[i],descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,'value'in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}return function(Constructor,protoProps,staticProps){return protoProps&&defineProperties(Constructor.prototype,protoProps),staticProps&&defineProperties(Constructor,staticProps),Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError('Cannot call a class as a function')}function _possibleConstructorReturn(self,call){if(!self)throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called');return call&&('object'==typeof call||'function'==typeof call)?call:self}function _inherits(subClass,superClass){if('function'!=typeof superClass&&null!==superClass)throw new TypeError('Super expression must either be null or a function, not '+typeof superClass);subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:!1,writable:!0,configurable:!0}}),superClass&&(Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass)}import Viewport from'./viewport';import{zoomToScale,getWorldPosition,pixelsToWorld,lngLatToWorld,worldToLngLat,getProjectionMatrix,getViewMatrix}from'./web-mercator-utils';import _fitBounds from'./fit-bounds';import vec2_add from'gl-vec2/add';import vec2_negate from'gl-vec2/negate';var WebMercatorViewport=function(_Viewport){function WebMercatorViewport(){var _ref=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},width=_ref.width,height=_ref.height,_ref$latitude=_ref.latitude,latitude=void 0===_ref$latitude?0:_ref$latitude,_ref$longitude=_ref.longitude,longitude=void 0===_ref$longitude?0:_ref$longitude,_ref$zoom=_ref.zoom,zoom=void 0===_ref$zoom?0:_ref$zoom,_ref$pitch=_ref.pitch,pitch=void 0===_ref$pitch?0:_ref$pitch,_ref$bearing=_ref.bearing,bearing=void 0===_ref$bearing?0:_ref$bearing,_ref$altitude=_ref.altitude,altitude=void 0===_ref$altitude?1.5:_ref$altitude,_ref$farZMultiplier=_ref.farZMultiplier,farZMultiplier=void 0===_ref$farZMultiplier?10:_ref$farZMultiplier;_classCallCheck(this,WebMercatorViewport),width=width||1,height=height||1;var scale=zoomToScale(zoom);altitude=Math.max(.75,altitude);var center=getWorldPosition({longitude:longitude,latitude:latitude,scale:scale}),projectionMatrix=getProjectionMatrix({width:width,height:height,pitch:pitch,bearing:bearing,altitude:altitude,farZMultiplier:farZMultiplier}),viewMatrix=getViewMatrix({height:height,center:center,pitch:pitch,bearing:bearing,altitude:altitude,flipY:!0}),_this=_possibleConstructorReturn(this,(WebMercatorViewport.__proto__||Object.getPrototypeOf(WebMercatorViewport)).call(this,{width:width,height:height,viewMatrix:viewMatrix,projectionMatrix:projectionMatrix}));return _this.latitude=latitude,_this.longitude=longitude,_this.zoom=zoom,_this.pitch=pitch,_this.bearing=bearing,_this.altitude=altitude,_this.scale=scale,_this.center=center,Object.freeze(_this),_this}return _inherits(WebMercatorViewport,_Viewport),_createClass(WebMercatorViewport,[{key:'projectFlat',value:function projectFlat(lngLat){var scale=1<arguments.length&&void 0!==arguments[1]?arguments[1]:this.scale;return lngLatToWorld(lngLat,scale)}},{key:'unprojectFlat',value:function unprojectFlat(xy){var scale=1<arguments.length&&void 0!==arguments[1]?arguments[1]:this.scale;return worldToLngLat(xy,scale)}},{key:'getMapCenterByLngLatPosition',value:function getMapCenterByLngLatPosition(_ref2){var lngLat=_ref2.lngLat,pos=_ref2.pos,fromLocation=pixelsToWorld(pos,this.pixelUnprojectionMatrix),toLocation=lngLatToWorld(lngLat,this.scale),translate=vec2_add([],toLocation,vec2_negate([],fromLocation)),newCenter=vec2_add([],this.center,translate);return worldToLngLat(newCenter,this.scale)}},{key:'getLocationAtPoint',value:function getLocationAtPoint(_ref3){var lngLat=_ref3.lngLat,pos=_ref3.pos;return this.getMapCenterByLngLatPosition({lngLat:lngLat,pos:pos})}},{key:'fitBounds',value:function fitBounds(bounds){var options=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},width=this.width,height=this.height,_fitBounds2=_fitBounds(Object.assign({width:width,height:height,bounds:bounds},options)),longitude=_fitBounds2.longitude,latitude=_fitBounds2.latitude,zoom=_fitBounds2.zoom;return new WebMercatorViewport({width:width,height:height,longitude:longitude,latitude:latitude,zoom:zoom})}}]),WebMercatorViewport}(Viewport);export default WebMercatorViewport;
function _instanceof(left,right){return null!=right&&"undefined"!=typeof Symbol&&right[Symbol.hasInstance]?right[Symbol.hasInstance](left):left instanceof right}function _typeof(obj){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj},_typeof(obj)}function _classCallCheck(instance,Constructor){if(!_instanceof(instance,Constructor))throw new TypeError("Cannot call a class as a function")}function _defineProperties(target,props){for(var descriptor,i=0;i<props.length;i++)descriptor=props[i],descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}function _createClass(Constructor,protoProps,staticProps){return protoProps&&_defineProperties(Constructor.prototype,protoProps),staticProps&&_defineProperties(Constructor,staticProps),Constructor}function _possibleConstructorReturn(self,call){return call&&("object"===_typeof(call)||"function"==typeof call)?call:_assertThisInitialized(self)}function _inherits(subClass,superClass){if("function"!=typeof superClass&&null!==superClass)throw new TypeError("Super expression must either be null or a function");subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:!1,writable:!0,configurable:!0}}),superClass&&(Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass)}function _assertThisInitialized(self){if(void 0===self)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return self}import Viewport from"./viewport";import{zoomToScale,getWorldPosition,pixelsToWorld,lngLatToWorld,worldToLngLat,getProjectionMatrix,getViewMatrix}from"./web-mercator-utils";import _fitBounds from"./fit-bounds";import vec2_add from"gl-vec2/add";import vec2_negate from"gl-vec2/negate";var WebMercatorViewport=function(_Viewport){function WebMercatorViewport(){var _this,_ref=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},width=_ref.width,height=_ref.height,_ref$latitude=_ref.latitude,latitude=void 0===_ref$latitude?0:_ref$latitude,_ref$longitude=_ref.longitude,longitude=void 0===_ref$longitude?0:_ref$longitude,_ref$zoom=_ref.zoom,zoom=void 0===_ref$zoom?0:_ref$zoom,_ref$pitch=_ref.pitch,pitch=void 0===_ref$pitch?0:_ref$pitch,_ref$bearing=_ref.bearing,bearing=void 0===_ref$bearing?0:_ref$bearing,_ref$altitude=_ref.altitude,altitude=void 0===_ref$altitude?1.5:_ref$altitude,_ref$farZMultiplier=_ref.farZMultiplier,farZMultiplier=void 0===_ref$farZMultiplier?10:_ref$farZMultiplier;_classCallCheck(this,WebMercatorViewport),width=width||1,height=height||1;var scale=zoomToScale(zoom);altitude=Math.max(.75,altitude);var center=getWorldPosition({longitude:longitude,latitude:latitude,scale:scale}),projectionMatrix=getProjectionMatrix({width:width,height:height,pitch:pitch,bearing:bearing,altitude:altitude,farZMultiplier:farZMultiplier}),viewMatrix=getViewMatrix({height:height,center:center,pitch:pitch,bearing:bearing,altitude:altitude,flipY:!0});return _this=_possibleConstructorReturn(this,(WebMercatorViewport.__proto__||Object.getPrototypeOf(WebMercatorViewport)).call(this,{width:width,height:height,viewMatrix:viewMatrix,projectionMatrix:projectionMatrix})),_this.latitude=latitude,_this.longitude=longitude,_this.zoom=zoom,_this.pitch=pitch,_this.bearing=bearing,_this.altitude=altitude,_this.scale=scale,_this.center=center,Object.freeze(_assertThisInitialized(_this)),_this}return _inherits(WebMercatorViewport,_Viewport),_createClass(WebMercatorViewport,[{key:"projectFlat",value:function projectFlat(lngLat){var scale=1<arguments.length&&void 0!==arguments[1]?arguments[1]:this.scale;return lngLatToWorld(lngLat,scale)}},{key:"unprojectFlat",value:function unprojectFlat(xy){var scale=1<arguments.length&&void 0!==arguments[1]?arguments[1]:this.scale;return worldToLngLat(xy,scale)}},{key:"getMapCenterByLngLatPosition",value:function getMapCenterByLngLatPosition(_ref2){var lngLat=_ref2.lngLat,pos=_ref2.pos,fromLocation=pixelsToWorld(pos,this.pixelUnprojectionMatrix),toLocation=lngLatToWorld(lngLat,this.scale),translate=vec2_add([],toLocation,vec2_negate([],fromLocation)),newCenter=vec2_add([],this.center,translate);return worldToLngLat(newCenter,this.scale)}},{key:"getLocationAtPoint",value:function getLocationAtPoint(_ref3){var lngLat=_ref3.lngLat,pos=_ref3.pos;return this.getMapCenterByLngLatPosition({lngLat:lngLat,pos:pos})}},{key:"fitBounds",value:function fitBounds(bounds){var options=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},width=this.width,height=this.height,_fitBounds2=_fitBounds(Object.assign({width:width,height:height,bounds:bounds},options)),longitude=_fitBounds2.longitude,latitude=_fitBounds2.latitude,zoom=_fitBounds2.zoom;return new WebMercatorViewport({width:width,height:height,longitude:longitude,latitude:latitude,zoom:zoom})}}]),WebMercatorViewport}(Viewport);export{WebMercatorViewport as default};
//# sourceMappingURL=web-mercator-viewport.js.map
{
"name": "viewport-mercator-project",
"version": "5.1.0-alpha.2",
"version": "5.1.0",
"description": "Utilities for perspective-enabled Web Mercator projections",

@@ -21,32 +21,29 @@ "author": "Uber Technologies, Inc.",

"start": "npm run test",
"clean": "rm -fr dist && mkdir -p dist/es5/packages dist/esm/packages dist/es6/packages",
"build-es6": "BABEL_ENV=es6 babel src --out-dir dist/es6 --source-maps",
"build-esm": "BABEL_ENV=esm babel src --out-dir dist/esm --source-maps",
"build-es5": "BABEL_ENV=es5 babel src --out-dir dist/es5 --source-maps",
"build-size": "(echo \"source size\" ; find src/ -name '*.js' | xargs cat | wc -c) && (echo \"dist/esm size\" ; find dist/esm -name '*.js' | xargs cat | wc -c) && (echo \"dist/es6 size\" ; find dist/es6 -name '*.js' | xargs cat | wc -c)",
"build": "npm run clean && npm run build-es6 && npm run build-esm && npm run build-es5 && npm run build-size",
"lint": "eslint src test",
"clean": "rm -fr dist && mkdir -p dist/es5 dist/esm dist/es6",
"build": "npm run clean && ./scripts/build.sh && ./scripts/collect-metrics.sh",
"lint": "eslint src test examples && npm run lint-yarn",
"lint-yarn": "!(grep -q unpm.u yarn.lock) || (echo 'Please rebuild yarn file using public npmrc' && false)",
"precommit": "npm test",
"publish-prod": "npm run build && npm run test && npm publish",
"publish-beta": "npm run build && npm run test && npm publish --tag beta",
"test": "npm run lint && npm run build && npm run test-node",
"test": "npm run lint && npm run test-node && ./scripts/build.sh",
"test-fast": "npm run test-node",
"test-node": "node test/node.js",
"test-browser": "webpack-dev-server --env.browser --progress --hot --open",
"test-size-es6": "npm run build-es6 && webpack --config test/webpack.config.js --env.import-nothing --env.es6",
"test-size-esm": "npm run build-esm && webpack --config test/webpack.config.js --env.import-nothing"
"test-bundle-size": "./scripts/build.sh && webpack --config test/webpack.config.js --env.analyze --env.es6"
},
"dependencies": {
"math.gl": ">=1.1.0-alpha.1"
"math.gl": "^1.1.0"
},
"devDependencies": {
"@babel/cli": "7.0.0-beta.44",
"@babel/core": "^7.0.0-beta.44",
"@babel/polyfill": "7.0.0-beta.44",
"@babel/preset-env": "7.0.0-beta.44",
"@babel/preset-es2015": "7.0.0-beta.44",
"@turf/destination": "^5.0.4",
"babel-cli": "^6.22.2",
"babel-core": "^6.22.1",
"babel-loader": "^8.0.0-beta.2",
"babel-preset-minify": "0.4.0-alpha.caaefb4c",
"babel-eslint": "^6.0.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.0",
"babel-plugin-version-inline": "^1.0.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.18",
"babel-preset-minify": "^0.3.0",
"eslint": "^3.0.0",

@@ -69,7 +66,7 @@ "eslint-config-uber-es2015": "^3.0.0",

"tape-catch": "^1.0.4",
"uglifyjs-webpack-plugin": "^1.2.4",
"webpack": "^2.2.1",
"webpack": "^4.3.0",
"webpack-bundle-analyzer": "^2.11.1",
"webpack-dev-server": "^2.4.2"
"webpack-cli": "^2.0.13",
"webpack-dev-server": "^3.1.1"
}
}
import WebMercatorViewport from './web-mercator-viewport';
import assert from './assert';
/**
* * An object describing the padding to add to the bounds.
* @typedef {Object} PaddingObject
* @property {Number} top - Padding from top in pixels to add to the given bounds
* @property {Number} bottom - Padding from bottom in pixels to add to the given bounds
* @property {Number} left - Padding from left in pixels to add to the given bounds
* @property {Number} right - Padding from right in pixels to add to the given bounds
*/
/**
* Returns map settings {latitude, longitude, zoom}

@@ -10,3 +20,5 @@ * that will contain the provided corners within the provided width.

* @param {Array} bounds - [[lon, lat], [lon, lat]]
* @param {Number} [padding] - The amount of padding in pixels to add to the given bounds.
* @param {Number|PaddingObject} [padding] - The amount of padding in pixels
* to add to the given bounds. Can also be an object with top, bottom, left and right
* properties defining the padding.
* @param {Array} [offset] - The center of the given bounds relative to the map's center,

@@ -26,2 +38,19 @@ * [x, y] measured in pixels.

if (Number.isFinite(padding)) {
const p = padding;
padding = {
top: p,
bottom: p,
left: p,
right: p
};
} else {
// Make sure all the required properties are set
assert(Number.isFinite(padding.top) &&
Number.isFinite(padding.bottom) &&
Number.isFinite(padding.left) &&
Number.isFinite(padding.right)
);
}
const viewport = new WebMercatorViewport({

@@ -37,2 +66,4 @@ width,

const se = viewport.project([east, south]);
// width/height on the Web Mercator plane
const size = [

@@ -42,10 +73,23 @@ Math.abs(se[0] - nw[0]),

];
const targetSize = [
width - padding.left - padding.right - Math.abs(offset[0]) * 2,
height - padding.top - padding.bottom - Math.abs(offset[1]) * 2
];
assert(targetSize[0] > 0 && targetSize[1] > 0);
// scale = screen pixels per unit on the Web Mercator plane
const scaleX = targetSize[0] / size[0];
const scaleY = targetSize[1] / size[1];
// Find how much we need to shift the center
const offsetX = (padding.right - padding.left) / 2 / scaleX;
const offsetY = (padding.bottom - padding.top) / 2 / scaleY;
const center = [
(se[0] + nw[0]) / 2,
(se[1] + nw[1]) / 2
(se[0] + nw[0]) / 2 + offsetX,
(se[1] + nw[1]) / 2 + offsetY
];
const scaleX = (width - padding * 2 - Math.abs(offset[0]) * 2) / size[0];
const scaleY = (height - padding * 2 - Math.abs(offset[1]) * 2) / size[1];
const centerLngLat = viewport.unproject(center);

@@ -52,0 +96,0 @@ const zoom = viewport.zoom + Math.log2(Math.abs(Math.min(scaleX, scaleY)));

@@ -24,3 +24,3 @@ // TODO - THE UTILITIES IN THIS FILE SHOULD BE IMPORTED FROM WEB-MERCATOR-VIEWPORT MODULE

// Mapbox default altitude
const DEFAULT_ALITITUDE = 1.5;
const DEFAULT_ALTITUDE = 1.5;

@@ -72,7 +72,7 @@ /** Util functions **/

// Returns the zoom level that gives a 1 meter pixel at a certain latitude
// S=C*cos(y)/2^(z+8)
// 1 = C*cos(y)/2^z/TILE_SIZE = C*cos(y)/2^(z+9)
export function getMeterZoom({latitude}) {
assert(Number.isFinite(latitude));
const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
return scaleToZoom(EARTH_CIRCUMFERENCE * latCosine) - 8;
return scaleToZoom(EARTH_CIRCUMFERENCE * latCosine) - 9;
}

@@ -224,3 +224,3 @@

height,
altitude = DEFAULT_ALITITUDE,
altitude = DEFAULT_ALTITUDE,
pitch = 0,

@@ -227,0 +227,0 @@ farZMultiplier = 1

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

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