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

viewport-mercator-project

Package Overview
Dependencies
Maintainers
8
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 6.0.0 to 6.1.0

5

CHANGELOG.md

@@ -5,2 +5,7 @@ # Change Log

### 6.1.0
- Replace gl packages with original gl-matrix (#85)
- Remove math.gl dependency (#86)
### 6.0.0

@@ -7,0 +12,0 @@

19

dist/es5/fly-to-viewport.js
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
Object.defineProperty(exports, "__esModule", {

@@ -8,4 +10,2 @@ value: true

var _math = require("math.gl");
var _mathUtils = require("./math-utils");

@@ -15,2 +15,4 @@

var vec2 = _interopRequireWildcard(require("gl-matrix/vec2"));
var EPSILON = 0.01;

@@ -28,8 +30,8 @@ var VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];

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 startCenterXY = (0, _webMercatorUtils.lngLatToWorld)(startCenter, startScale);
var endCenterXY = (0, _webMercatorUtils.lngLatToWorld)(endCenter, startScale);
var uDelta = vec2.sub([], endCenterXY, 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);
var u1 = vec2.length(uDelta);

@@ -58,3 +60,6 @@ if (Math.abs(u1) < EPSILON) {

var newZoom = startZoom + (0, _webMercatorUtils.scaleToZoom)(scaleIncrement);
var newCenter = (0, _webMercatorUtils.worldToLngLat)(startCenterXY.add(uDelta.scale(u)).scale(scaleIncrement), (0, _webMercatorUtils.zoomToScale)(newZoom));
var newCenterWorld = vec2.scale([], uDelta, u);
vec2.add(newCenterWorld, newCenterWorld, startCenterXY);
vec2.scale(newCenterWorld, newCenterWorld, scaleIncrement);
var newCenter = (0, _webMercatorUtils.worldToLngLat)(newCenterWorld, (0, _webMercatorUtils.zoomToScale)(newZoom));
viewport.longitude = newCenter[0];

@@ -61,0 +66,0 @@ viewport.latitude = newCenter[1];

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

var _scale = _interopRequireDefault(require("gl-vec4/scale"));
var vec4 = _interopRequireWildcard(require("gl-matrix/vec4"));
var _transformMat = _interopRequireDefault(require("gl-vec4/transformMat4"));
function createMat4() {

@@ -23,4 +21,4 @@ return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];

function transformVector(matrix, vector) {
var result = (0, _transformMat.default)([], vector, matrix);
(0, _scale.default)(result, result, 1 / result[3]);
var result = vec4.transformMat4([], vector, matrix);
vec4.scale(result, result, 1 / result[3]);
return result;

@@ -27,0 +25,0 @@ }

"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

@@ -16,4 +18,2 @@

var _math = require("math.gl");
var _mathUtils = require("./math-utils");

@@ -23,10 +23,4 @@

var _scale = _interopRequireDefault(require("gl-mat4/scale"));
var mat4 = _interopRequireWildcard(require("gl-matrix/mat4"));
var _translate = _interopRequireDefault(require("gl-mat4/translate"));
var _multiply = _interopRequireDefault(require("gl-mat4/multiply"));
var _invert = _interopRequireDefault(require("gl-mat4/invert"));
var IDENTITY = (0, _mathUtils.createMat4)();

@@ -52,10 +46,10 @@

var vpm = (0, _mathUtils.createMat4)();
(0, _multiply.default)(vpm, vpm, this.projectionMatrix);
(0, _multiply.default)(vpm, vpm, this.viewMatrix);
mat4.multiply(vpm, vpm, this.projectionMatrix);
mat4.multiply(vpm, vpm, this.viewMatrix);
this.viewProjectionMatrix = vpm;
var m = (0, _mathUtils.createMat4)();
(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);
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((0, _mathUtils.createMat4)(), m);

@@ -84,3 +78,3 @@ if (!mInverse) {

return viewport.width === this.width && viewport.height === this.height && (0, _math.equals)(viewport.projectionMatrix, this.projectionMatrix) && (0, _math.equals)(viewport.viewMatrix, this.viewMatrix);
return viewport.width === this.width && viewport.height === this.height && mat4.equals(viewport.projectionMatrix, this.projectionMatrix) && mat4.equals(viewport.viewMatrix, this.viewMatrix);
}

@@ -87,0 +81,0 @@ }, {

"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

@@ -23,18 +25,10 @@

var _math = require("math.gl");
var _mathUtils = require("./math-utils");
var _perspective = _interopRequireDefault(require("gl-mat4/perspective"));
var mat4 = _interopRequireWildcard(require("gl-matrix/mat4"));
var _scale = _interopRequireDefault(require("gl-mat4/scale"));
var vec2 = _interopRequireWildcard(require("gl-matrix/vec2"));
var _translate = _interopRequireDefault(require("gl-mat4/translate"));
var vec3 = _interopRequireWildcard(require("gl-matrix/vec3"));
var _rotateX = _interopRequireDefault(require("gl-mat4/rotateX"));
var _rotateZ = _interopRequireDefault(require("gl-mat4/rotateZ"));
var _lerp = _interopRequireDefault(require("gl-vec2/lerp"));
var _assert = _interopRequireDefault(require("./assert"));

@@ -161,13 +155,13 @@

var vm = (0, _mathUtils.createMat4)();
(0, _translate.default)(vm, vm, [0, 0, -altitude]);
(0, _scale.default)(vm, vm, [1, 1, 1 / height]);
(0, _rotateX.default)(vm, vm, -pitch * DEGREES_TO_RADIANS);
(0, _rotateZ.default)(vm, vm, bearing * DEGREES_TO_RADIANS);
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);
if (flipY) {
(0, _scale.default)(vm, vm, [1, -1, 1]);
mat4.scale(vm, vm, [1, -1, 1]);
}
if (center) {
(0, _translate.default)(vm, vm, new _math.Vector3(center).negate());
mat4.translate(vm, vm, vec3.negate([], center));
}

@@ -223,3 +217,3 @@

var projectionMatrix = (0, _perspective.default)([], fov, aspect, near, far);
var projectionMatrix = mat4.perspective([], fov, aspect, near, far);
return projectionMatrix;

@@ -259,4 +253,4 @@ }

var t = z0 === z1 ? 0 : ((targetZ || 0) - z0) / (z1 - z0);
return (0, _lerp.default)([], coord0, coord1, t);
return vec2.lerp([], coord0, coord1, t);
}
//# sourceMappingURL=web-mercator-utils.js.map
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

@@ -28,6 +30,4 @@

var _add = _interopRequireDefault(require("gl-vec2/add"));
var vec2 = _interopRequireWildcard(require("gl-matrix/vec2"));
var _negate = _interopRequireDefault(require("gl-vec2/negate"));
var WebMercatorViewport = function (_Viewport) {

@@ -119,4 +119,4 @@ (0, _inherits2.default)(WebMercatorViewport, _Viewport);

var toLocation = (0, _webMercatorUtils.lngLatToWorld)(lngLat, this.scale);
var translate = (0, _add.default)([], toLocation, (0, _negate.default)([], fromLocation));
var newCenter = (0, _add.default)([], this.center, translate);
var translate = vec2.add([], toLocation, vec2.negate([], fromLocation));
var newCenter = vec2.add([], this.center, translate);
return (0, _webMercatorUtils.worldToLngLat)(newCenter, this.scale);

@@ -123,0 +123,0 @@ }

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

import { Vector2 } from 'math.gl';
import { lerp } from './math-utils';
import { scaleToZoom, zoomToScale, lngLatToWorld, worldToLngLat } from './web-mercator-utils';
import * as vec2 from 'gl-matrix/vec2';
const EPSILON = 0.01;

@@ -15,8 +15,8 @@ const VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];

const scale = zoomToScale(endZoom - startZoom);
const startCenterXY = new Vector2(lngLatToWorld(startCenter, startScale));
const endCenterXY = new Vector2(lngLatToWorld(endCenter, startScale));
const uDelta = endCenterXY.subtract(startCenterXY);
const startCenterXY = lngLatToWorld(startCenter, startScale);
const endCenterXY = lngLatToWorld(endCenter, startScale);
const uDelta = vec2.sub([], endCenterXY, startCenterXY);
const w0 = Math.max(startProps.width, startProps.height);
const w1 = w0 / scale;
const u1 = Math.sqrt(uDelta.x * uDelta.x + uDelta.y * uDelta.y);
const u1 = vec2.length(uDelta);

@@ -44,3 +44,6 @@ if (Math.abs(u1) < EPSILON) {

const newZoom = startZoom + scaleToZoom(scaleIncrement);
const newCenter = worldToLngLat(startCenterXY.add(uDelta.scale(u)).scale(scaleIncrement), zoomToScale(newZoom));
const newCenterWorld = vec2.scale([], uDelta, u);
vec2.add(newCenterWorld, newCenterWorld, startCenterXY);
vec2.scale(newCenterWorld, newCenterWorld, scaleIncrement);
const newCenter = worldToLngLat(newCenterWorld, zoomToScale(newZoom));
viewport.longitude = newCenter[0];

@@ -47,0 +50,0 @@ viewport.latitude = newCenter[1];

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

import vec4_scale from 'gl-vec4/scale';
import vec4_transformMat4 from 'gl-vec4/transformMat4';
import * as vec4 from 'gl-matrix/vec4';
export function createMat4() {

@@ -7,4 +6,4 @@ 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);
vec4_scale(result, result, 1 / result[3]);
const result = vec4.transformMat4([], vector, matrix);
vec4.scale(result, result, 1 / result[3]);
return result;

@@ -11,0 +10,0 @@ }

import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
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';
import * as mat4 from 'gl-matrix/mat4';
const IDENTITY = createMat4();

@@ -24,10 +20,10 @@ export default class Viewport {

const vpm = createMat4();
mat4_multiply(vpm, vpm, this.projectionMatrix);
mat4_multiply(vpm, vpm, this.viewMatrix);
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);
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);

@@ -54,3 +50,3 @@ if (!mInverse) {

return viewport.width === this.width && viewport.height === this.height && equals(viewport.projectionMatrix, this.projectionMatrix) && equals(viewport.viewMatrix, this.viewMatrix);
return viewport.width === this.width && viewport.height === this.height && mat4.equals(viewport.projectionMatrix, this.projectionMatrix) && mat4.equals(viewport.viewMatrix, this.viewMatrix);
}

@@ -57,0 +53,0 @@

import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
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 * as mat4 from 'gl-matrix/mat4';
import * as vec2 from 'gl-matrix/vec2';
import * as vec3 from 'gl-matrix/vec3';
import assert from './assert';

@@ -114,13 +110,13 @@ const PI = Math.PI;

const vm = createMat4();
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);
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);
if (flipY) {
mat4_scale(vm, vm, [1, -1, 1]);
mat4.scale(vm, vm, [1, -1, 1]);
}
if (center) {
mat4_translate(vm, vm, new Vector3(center).negate());
mat4.translate(vm, vm, vec3.negate([], center));
}

@@ -171,3 +167,3 @@

const projectionMatrix = mat4_perspective([], fov, aspect, near, far);
const projectionMatrix = mat4.perspective([], fov, aspect, near, far);
return projectionMatrix;

@@ -203,4 +199,4 @@ }

const t = z0 === z1 ? 0 : ((targetZ || 0) - z0) / (z1 - z0);
return vec2_lerp([], coord0, coord1, t);
return vec2.lerp([], coord0, coord1, t);
}
//# sourceMappingURL=web-mercator-utils.js.map
import Viewport from './viewport';
import { zoomToScale, pixelsToWorld, lngLatToWorld, worldToLngLat, getProjectionMatrix, getDistanceScales, getViewMatrix } from './web-mercator-utils';
import fitBounds from './fit-bounds';
import vec2_add from 'gl-vec2/add';
import vec2_negate from 'gl-vec2/negate';
import * as vec2 from 'gl-matrix/vec2';
export default class WebMercatorViewport extends Viewport {

@@ -74,4 +73,4 @@ constructor({

const toLocation = lngLatToWorld(lngLat, this.scale);
const translate = vec2_add([], toLocation, vec2_negate([], fromLocation));
const newCenter = vec2_add([], this.center, translate);
const translate = vec2.add([], toLocation, vec2.negate([], fromLocation));
const newCenter = vec2.add([], this.center, translate);
return worldToLngLat(newCenter, this.scale);

@@ -78,0 +77,0 @@ }

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

import { Vector2 } from 'math.gl';
import { lerp } from './math-utils';
import { scaleToZoom, zoomToScale, lngLatToWorld, worldToLngLat } from './web-mercator-utils';
import * as vec2 from 'gl-matrix/vec2';
var EPSILON = 0.01;

@@ -15,8 +15,8 @@ var VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];

var scale = zoomToScale(endZoom - startZoom);
var startCenterXY = new Vector2(lngLatToWorld(startCenter, startScale));
var endCenterXY = new Vector2(lngLatToWorld(endCenter, startScale));
var uDelta = endCenterXY.subtract(startCenterXY);
var startCenterXY = lngLatToWorld(startCenter, startScale);
var endCenterXY = lngLatToWorld(endCenter, startScale);
var uDelta = vec2.sub([], endCenterXY, 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);
var u1 = vec2.length(uDelta);

@@ -45,3 +45,6 @@ if (Math.abs(u1) < EPSILON) {

var newZoom = startZoom + scaleToZoom(scaleIncrement);
var newCenter = worldToLngLat(startCenterXY.add(uDelta.scale(u)).scale(scaleIncrement), zoomToScale(newZoom));
var newCenterWorld = vec2.scale([], uDelta, u);
vec2.add(newCenterWorld, newCenterWorld, startCenterXY);
vec2.scale(newCenterWorld, newCenterWorld, scaleIncrement);
var newCenter = worldToLngLat(newCenterWorld, zoomToScale(newZoom));
viewport.longitude = newCenter[0];

@@ -48,0 +51,0 @@ viewport.latitude = newCenter[1];

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

import vec4_scale from 'gl-vec4/scale';
import vec4_transformMat4 from 'gl-vec4/transformMat4';
import * as vec4 from 'gl-matrix/vec4';
export function createMat4() {

@@ -7,4 +6,4 @@ 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);
vec4_scale(result, result, 1 / result[3]);
var result = vec4.transformMat4([], vector, matrix);
vec4.scale(result, result, 1 / result[3]);
return result;

@@ -11,0 +10,0 @@ }

import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
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';
import * as mat4 from 'gl-matrix/mat4';
var IDENTITY = createMat4();

@@ -32,10 +28,10 @@

var vpm = createMat4();
mat4_multiply(vpm, vpm, this.projectionMatrix);
mat4_multiply(vpm, vpm, this.viewMatrix);
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);
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);

@@ -64,3 +60,3 @@ if (!mInverse) {

return viewport.width === this.width && viewport.height === this.height && _equals(viewport.projectionMatrix, this.projectionMatrix) && _equals(viewport.viewMatrix, this.viewMatrix);
return viewport.width === this.width && viewport.height === this.height && mat4.equals(viewport.projectionMatrix, this.projectionMatrix) && mat4.equals(viewport.viewMatrix, this.viewMatrix);
}

@@ -67,0 +63,0 @@ }, {

import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
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 * as mat4 from 'gl-matrix/mat4';
import * as vec2 from 'gl-matrix/vec2';
import * as vec3 from 'gl-matrix/vec3';
import assert from './assert';

@@ -122,13 +118,13 @@ var PI = Math.PI;

var vm = createMat4();
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);
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);
if (flipY) {
mat4_scale(vm, vm, [1, -1, 1]);
mat4.scale(vm, vm, [1, -1, 1]);
}
if (center) {
mat4_translate(vm, vm, new Vector3(center).negate());
mat4.translate(vm, vm, vec3.negate([], center));
}

@@ -182,3 +178,3 @@

var projectionMatrix = mat4_perspective([], fov, aspect, near, far);
var projectionMatrix = mat4.perspective([], fov, aspect, near, far);
return projectionMatrix;

@@ -216,4 +212,4 @@ }

var t = z0 === z1 ? 0 : ((targetZ || 0) - z0) / (z1 - z0);
return vec2_lerp([], coord0, coord1, t);
return vec2.lerp([], coord0, coord1, t);
}
//# sourceMappingURL=web-mercator-utils.js.map

@@ -10,4 +10,3 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";

import _fitBounds from './fit-bounds';
import vec2_add from 'gl-vec2/add';
import vec2_negate from 'gl-vec2/negate';
import * as vec2 from 'gl-matrix/vec2';

@@ -101,4 +100,4 @@ var WebMercatorViewport = function (_Viewport) {

var toLocation = lngLatToWorld(lngLat, this.scale);
var translate = vec2_add([], toLocation, vec2_negate([], fromLocation));
var newCenter = vec2_add([], this.center, translate);
var translate = vec2.add([], toLocation, vec2.negate([], fromLocation));
var newCenter = vec2.add([], this.center, translate);
return worldToLngLat(newCenter, this.scale);

@@ -105,0 +104,0 @@ }

{
"name": "viewport-mercator-project",
"version": "6.0.0",
"version": "6.1.0",
"description": "Utilities for perspective-enabled Web Mercator projections",

@@ -37,3 +37,3 @@ "author": "Uber Technologies, Inc.",

"@babel/runtime": "^7.0.0",
"math.gl": "^2.1.0"
"gl-matrix": "^3.0.0-0"
},

@@ -56,2 +56,3 @@ "devDependencies": {

"mapbox-gl": "~0.49.0",
"math.gl": "^2.1.0",
"mock-browser": "^0.92.14",

@@ -58,0 +59,0 @@ "module-alias": "^2.0.0",

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

import {Vector2} from 'math.gl';
import {lerp} from './math-utils';

@@ -9,2 +8,3 @@ import {

} from './web-mercator-utils';
import * as vec2 from 'gl-matrix/vec2';

@@ -35,9 +35,9 @@ const EPSILON = 0.01;

const startCenterXY = new Vector2(lngLatToWorld(startCenter, startScale));
const endCenterXY = new Vector2(lngLatToWorld(endCenter, startScale));
const uDelta = endCenterXY.subtract(startCenterXY);
const startCenterXY = lngLatToWorld(startCenter, startScale);
const endCenterXY = lngLatToWorld(endCenter, startScale);
const uDelta = vec2.sub([], endCenterXY, startCenterXY);
const w0 = Math.max(startProps.width, startProps.height);
const w1 = w0 / scale;
const u1 = Math.sqrt((uDelta.x * uDelta.x) + (uDelta.y * uDelta.y));
const u1 = vec2.length(uDelta);
// u0 is treated as '0' in Eq (9).

@@ -70,4 +70,8 @@

const newCenterWorld = vec2.scale([], uDelta, u);
vec2.add(newCenterWorld, newCenterWorld, startCenterXY);
vec2.scale(newCenterWorld, newCenterWorld, scaleIncrement);
const newCenter = worldToLngLat(
(startCenterXY.add(uDelta.scale(u))).scale(scaleIncrement),
newCenterWorld,
zoomToScale(newZoom));

@@ -74,0 +78,0 @@ viewport.longitude = newCenter[0];

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

import vec4_scale from 'gl-vec4/scale';
import vec4_transformMat4 from 'gl-vec4/transformMat4';
import * as vec4 from 'gl-matrix/vec4';

@@ -11,4 +10,4 @@ // Helper, avoids low-precision 32 bit matrices from gl-matrix mat4.create()

export function transformVector(matrix, vector) {
const result = vec4_transformMat4([], vector, matrix);
vec4_scale(result, result, 1 / result[3]);
const result = vec4.transformMat4([], vector, matrix);
vec4.scale(result, result, 1 / result[3]);
return result;

@@ -15,0 +14,0 @@ }

// View and Projection Matrix management
/* eslint-disable camelcase */
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';
import * as mat4 from 'gl-matrix/mat4';

@@ -62,4 +57,4 @@ const IDENTITY = createMat4();

const vpm = createMat4();
mat4_multiply(vpm, vpm, this.projectionMatrix);
mat4_multiply(vpm, vpm, this.viewMatrix);
mat4.multiply(vpm, vpm, this.projectionMatrix);
mat4.multiply(vpm, vpm, this.viewMatrix);
this.viewProjectionMatrix = vpm;

@@ -80,8 +75,8 @@

// matrix for conversion from location to screen coordinates
mat4_scale(m, m, [this.width / 2, -this.height / 2, 1]);
mat4_translate(m, m, [1, -1, 0]);
mat4.scale(m, m, [this.width / 2, -this.height / 2, 1]);
mat4.translate(m, m, [1, -1, 0]);
mat4_multiply(m, m, this.viewProjectionMatrix);
mat4.multiply(m, m, this.viewProjectionMatrix);
const mInverse = mat4_invert(createMat4(), m);
const mInverse = mat4.invert(createMat4(), m);
if (!mInverse) {

@@ -114,4 +109,4 @@ throw new Error('Pixel project matrix not invertible');

viewport.height === this.height &&
equals(viewport.projectionMatrix, this.projectionMatrix) &&
equals(viewport.viewMatrix, this.viewMatrix);
mat4.equals(viewport.projectionMatrix, this.projectionMatrix) &&
mat4.equals(viewport.viewMatrix, this.viewMatrix);
}

@@ -118,0 +113,0 @@

// TODO - THE UTILITIES IN THIS FILE SHOULD BE IMPORTED FROM WEB-MERCATOR-VIEWPORT MODULE
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 * as mat4 from 'gl-matrix/mat4';
import * as vec2 from 'gl-matrix/vec2';
import * as vec3 from 'gl-matrix/vec3';
import assert from './assert';

@@ -192,18 +188,18 @@

// Move camera to altitude (along the pitch & bearing direction)
mat4_translate(vm, vm, [0, 0, -altitude]);
mat4.translate(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.
mat4_scale(vm, vm, [1, 1, 1 / height]);
mat4.scale(vm, vm, [1, 1, 1 / height]);
// Rotate by bearing, and then by pitch (which tilts the view)
mat4_rotateX(vm, vm, -pitch * DEGREES_TO_RADIANS);
mat4_rotateZ(vm, vm, bearing * DEGREES_TO_RADIANS);
mat4.rotateX(vm, vm, -pitch * DEGREES_TO_RADIANS);
mat4.rotateZ(vm, vm, bearing * DEGREES_TO_RADIANS);
if (flipY) {
mat4_scale(vm, vm, [1, -1, 1]);
mat4.scale(vm, vm, [1, -1, 1]);
}
if (center) {
mat4_translate(vm, vm, new Vector3(center).negate());
mat4.translate(vm, vm, vec3.negate([], center));
}

@@ -258,3 +254,3 @@

const projectionMatrix = mat4_perspective(
const projectionMatrix = mat4.perspective(
[],

@@ -312,3 +308,3 @@ fov, // fov in radians

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

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

import vec2_add from 'gl-vec2/add';
import vec2_negate from 'gl-vec2/negate';
import * as vec2 from 'gl-matrix/vec2';

@@ -153,4 +152,4 @@ export default class WebMercatorViewport extends Viewport {

const translate = vec2_add([], toLocation, vec2_negate([], fromLocation));
const newCenter = vec2_add([], this.center, translate);
const translate = vec2.add([], toLocation, vec2.negate([], fromLocation));
const newCenter = vec2.add([], this.center, translate);

@@ -157,0 +156,0 @@ return worldToLngLat(newCenter, this.scale);

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