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

@math.gl/web-mercator

Package Overview
Dependencies
Maintainers
4
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 3.1.3 to 3.2.0-alpha.1

src/fit-bounds.d.ts

6

dist/es5/index.js

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

});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function get() {
return _webMercatorViewport["default"];
}
});
Object.defineProperty(exports, "WebMercatorViewport", {

@@ -18,0 +12,0 @@ enumerable: true,

@@ -101,3 +101,4 @@ "use strict";

topLeft = _ref3$topLeft === void 0 ? true : _ref3$topLeft,
targetZ = _ref3.targetZ;
_ref3$targetZ = _ref3.targetZ,
targetZ = _ref3$targetZ === void 0 ? undefined : _ref3$targetZ;

@@ -150,3 +151,2 @@ var _xyz = (0, _slicedToArray2["default"])(xyz, 3),

value: function projectFlat(xyz) {
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.scale;
return xyz;

@@ -157,3 +157,2 @@ }

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

@@ -160,0 +159,0 @@ }

8

dist/es5/web-mercator-viewport.js

@@ -38,3 +38,6 @@ "use strict";

var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
width: 1,
height: 1
},
width = _ref.width,

@@ -70,3 +73,2 @@ height = _ref.height,

pitch: pitch,
bearing: bearing,
altitude: altitude,

@@ -122,3 +124,3 @@ nearZMultiplier: nearZMultiplier,

var newCenter = vec2.add([], this.center, translate);
return (0, _webMercatorUtils.worldToLngLat)(newCenter, this.scale);
return (0, _webMercatorUtils.worldToLngLat)(newCenter);
}

@@ -125,0 +127,0 @@ }, {

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

export { default } from './web-mercator-viewport';
export { default as WebMercatorViewport } from './web-mercator-viewport';

@@ -3,0 +2,0 @@ export { default as fitBounds } from './fit-bounds';

@@ -64,3 +64,3 @@ import { createMat4 } from './math-utils';

topLeft = true,
targetZ
targetZ = undefined
} = {}) {

@@ -92,7 +92,7 @@ const [x, y, z] = xyz;

projectFlat(xyz, scale = this.scale) {
projectFlat(xyz) {
return xyz;
}
unprojectFlat(xyz, scale = this.scale) {
unprojectFlat(xyz) {
return xyz;

@@ -99,0 +99,0 @@ }

@@ -17,3 +17,6 @@ import Viewport from './viewport';

farZMultiplier = 1.01
} = {}) {
} = {
width: 1,
height: 1
}) {
width = width || 1;

@@ -29,3 +32,2 @@ height = height || 1;

pitch,
bearing,
altitude,

@@ -77,3 +79,3 @@ nearZMultiplier,

const newCenter = vec2.add([], this.center, translate);
return worldToLngLat(newCenter, this.scale);
return worldToLngLat(newCenter);
}

@@ -80,0 +82,0 @@

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

export { default } from './web-mercator-viewport';
export { default as WebMercatorViewport } from './web-mercator-viewport';

@@ -3,0 +2,0 @@ export { default as fitBounds } from './fit-bounds';

@@ -85,3 +85,4 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";

topLeft = _ref3$topLeft === void 0 ? true : _ref3$topLeft,
targetZ = _ref3.targetZ;
_ref3$targetZ = _ref3.targetZ,
targetZ = _ref3$targetZ === void 0 ? undefined : _ref3$targetZ;

@@ -134,3 +135,2 @@ var _xyz = _slicedToArray(xyz, 3),

value: function projectFlat(xyz) {
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.scale;
return xyz;

@@ -141,3 +141,2 @@ }

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

@@ -144,0 +143,0 @@ }

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

var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
width: 1,
height: 1
},
width = _ref.width,

@@ -51,3 +54,2 @@ height = _ref.height,

pitch: pitch,
bearing: bearing,
altitude: altitude,

@@ -103,3 +105,3 @@ nearZMultiplier: nearZMultiplier,

var newCenter = vec2.add([], this.center, translate);
return worldToLngLat(newCenter, this.scale);
return worldToLngLat(newCenter);
}

@@ -106,0 +108,0 @@ }, {

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

"license": "MIT",
"version": "3.1.3",
"version": "3.2.0-alpha.1",
"keywords": [

@@ -22,2 +22,3 @@ "webgl",

},
"types": "src/index.d.ts",
"main": "dist/es5/index.js",

@@ -38,3 +39,3 @@ "module": "dist/esm/index.js",

},
"gitHead": "51993e1f66ea6ccff5977f2d1466e636917061c9"
"gitHead": "f342933ca13fa606bd60ac82bb24bb2959b13b32"
}

@@ -0,28 +1,9 @@

// @ts-nocheck TODO padding
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}
// that will contain the provided corners within the provided width.
// Only supports non-perspective mode.
/**
* Returns map settings {latitude, longitude, zoom}
* that will contain the provided corners within the provided width.
* Only supports non-perspective mode.
* @param {Number} width - viewport width
* @param {Number} height - viewport height
* @param {Array} bounds - [[lon, lat], [lon, lat]]
* @param {Array} minExtent - The width/height of the bounded area will never be smaller than this
* @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,
* [x, y] measured in pixels.
* @returns {Object} - latitude, longitude and zoom
*/
export default function fitBounds({

@@ -29,0 +10,0 @@ width,

// Classic web-mercator-project
export {default} from './web-mercator-viewport';
export {default as WebMercatorViewport} from './web-mercator-viewport';

@@ -4,0 +3,0 @@

@@ -9,3 +9,3 @@ import WebMercatorViewport from './web-mercator-viewport';

// Apply mathematical constraints to viewport props
/* eslint-disable complexity */
// eslint-disable-next-line complexity
export default function normalizeViewportProps({

@@ -12,0 +12,0 @@ width,

@@ -20,17 +20,2 @@ // View and Projection Matrix management

* @param {Object} opt - options
* @param {Boolean} mercator=true - Whether to use mercator projection
*
* @param {Number} opt.width=1 - Width of "viewport" or window
* @param {Number} opt.height=1 - Height of "viewport" or window
* @param {Array} opt.center=[0, 0] - Center of viewport
* [longitude, latitude] or [x, y]
* @param {Number} opt.scale=1 - Either use scale or zoom
* @param {Number} opt.pitch=0 - Camera angle in degrees (0 is straight down)
* @param {Number} opt.bearing=0 - Map rotation in degrees (0 means north is up)
* @param {Number} opt.altitude= - Altitude of camera in screen units
*
* Web mercator projection short-hand parameters
* @param {Number} opt.latitude - Center of viewport on map (alternative to opt.center)
* @param {Number} opt.longitude - Center of viewport on map (alternative to opt.center)
* @param {Number} opt.zoom - Scale = Math.pow(2,zoom) on map (alternative to opt.scale)
*/

@@ -98,3 +83,2 @@ // eslint-disable-next-line complexity, max-statements

}
/* eslint-enable complexity */

@@ -116,14 +100,4 @@ // Two viewports are equal if width and height are identical, and if

/**
* Projects xyz (possibly latitude and longitude) to pixel coordinates in window
* using viewport projection parameters
* - [longitude, latitude] to [x, y]
* - [longitude, latitude, Z] => [x, y, z]
* Note: By default, returns top-left coordinates for canvas/SVG type render
*
* @param {Array} lngLatZ - [lng, lat] or [lng, lat, Z]
* @param {Object} opts - options
* @param {Object} opts.topLeft=true - Whether projected coords are top left
* @return {Array} - screen coordinates [x, y] or [x, y, z], z as pixel depth
*/
// Projects xyz (possibly latitude and longitude) to pixel coordinates in window
// using viewport projection parameters
project(xyz, {topLeft = true} = {}) {

@@ -138,15 +112,5 @@ const worldPosition = this.projectPosition(xyz);

/**
* Unproject pixel coordinates on screen onto world coordinates,
* (possibly [lon, lat]) on map.
* - [x, y] => [lng, lat]
* - [x, y, z] => [lng, lat, Z]
* @param {Array} xyz - screen coordinates, z as pixel depth
* @param {Object} opts - options
* @param {Object} opts.topLeft=true - Whether projected coords are top left
* @param {Object} opts.targetZ=0 - If pixel depth is unknown, targetZ is used as
* the elevation plane to unproject onto
* @return {Array} - [lng, lat, Z] or [X, Y, Z]
*/
unproject(xyz, {topLeft = true, targetZ} = {}) {
// Unproject pixel coordinates on screen onto world coordinates,
// (possibly [lon, lat]) on map.
unproject(xyz, {topLeft = true, targetZ = undefined} = {}) {
const [x, y, z] = xyz;

@@ -184,6 +148,6 @@

* geographic projection.
* @param {Array} xyz - map coordinates
* @return {Array} [x,y,z] world coordinates.
* @param xyz - map coordinates
* @return [x,y,z] world coordinates.
*/
projectFlat(xyz, scale = this.scale) {
projectFlat(xyz) {
return xyz;

@@ -196,8 +160,8 @@ }

* geographic projection.
* @param {Array} xyz - world coordinates
* @return {Array} [x,y,z] map coordinates.
* @param xyz - world coordinates
* @return [x,y,z] map coordinates.
*/
unprojectFlat(xyz, scale = this.scale) {
unprojectFlat(xyz) {
return xyz;
}
}

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

*
* @param {Array} lngLat - [lng, lat] coordinates
* @param lngLat - [lng, lat] coordinates
* Specifies a point on the sphere to project onto the map.
* @return {Array} [x,y] coordinates.
* @return [x,y] coordinates.
*/

@@ -53,11 +53,3 @@ export function lngLatToWorld([lng, lat]) {

/**
* Unproject world point [x,y] on map onto {lat, lon} on sphere
*
* @param {object|Vector} xy - object with {x,y} members
* representing point on projected map plane
* @return {GeoCoordinates} - object with {lat,lon} of point on sphere.
* Has toArray method if you need a GeoJSON Array.
* Per cartographic tradition, lat and lon are specified as degrees.
*/
// Unproject world point [x,y] on map onto {lat, lon} on sphere
export function worldToLngLat([x, y]) {

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

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

@@ -263,9 +256,3 @@ const newZ = (z0 || 0) + (z || 0);

/**
* Project flat coordinates to pixels on screen.
*
* @param {Array} xyz - flat coordinate on 512*512 Mercator Zoom 0 tile
* @param {Matrix4} pixelProjectionMatrix - projection matrix
* @return {Array} [x, y, depth] pixel coordinate on screen.
*/
// Project flat coordinates to pixels on screen.
export function worldToPixels(xyz, pixelProjectionMatrix) {

@@ -278,11 +265,3 @@ const [x, y, z = 0] = xyz;

/**
* Unproject pixels on screen to flat coordinates.
*
* @param {Array} xyz - pixel coordinate on screen.
* @param {Matrix4} pixelUnprojectionMatrix - unprojection matrix
* @param {Number} targetZ - if pixel coordinate does not have a 3rd component (depth),
* targetZ is used as the elevation plane to unproject onto
* @return {Array} [x, y, Z] flat coordinates on 512*512 Mercator Zoom 0 tile.
*/
// Unproject pixels on screen to flat coordinates.
export function pixelsToWorld(xyz, pixelUnprojectionMatrix, targetZ = 0) {

@@ -289,0 +268,0 @@ const [x, y, z] = xyz;

@@ -18,45 +18,17 @@ // View and Projection Matrix calculations for mapbox-js style map view properties

export default class WebMercatorViewport extends Viewport {
/**
* @classdesc
* Creates view/projection matrices from mercator params
* Note: The Viewport is immutable in the sense that it only has accessors.
* A new viewport instance should be created if any parameters have changed.
*
* @class
* @param {Object} opt - options
*
* @param {Number} opt.width=1 - Width of "viewport" or window
* @param {Number} opt.height=1 - Height of "viewport" or window
* @param {Number} opt.scale=1 - Either use scale or zoom
* @param {Number} opt.pitch=0 - Camera angle in degrees (0 is straight down)
* @param {Number} opt.bearing=0 - Map rotation in degrees (0 means north is up)
* @param {Number} opt.altitude= - Altitude of camera in screen units
*
* Web mercator projection short-hand parameters
* @param {Number} opt.latitude - Center of viewport on map (alternative to opt.center)
* @param {Number} opt.longitude - Center of viewport on map (alternative to opt.center)
* @param {Number} opt.zoom - Scale = Math.pow(2,zoom) on map (alternative to opt.scale)
* Notes:
* - Only one of center or [latitude, longitude] can be specified
* - [latitude, longitude] can only be specified when "mercator" is true
* - Altitude has a default value that matches assumptions in mapbox-gl
* - width and height are forced to 1 if supplied as 0, to avoid
* division by zero. This is intended to reduce the burden of apps to
* to check values before instantiating a Viewport.
*/
/* eslint-disable complexity */
constructor({
// Map state
width,
height,
latitude = 0,
longitude = 0,
zoom = 0,
pitch = 0,
bearing = 0,
altitude = 1.5,
nearZMultiplier = 0.02,
farZMultiplier = 1.01
} = {}) {
constructor(
{
// Map state
width,
height,
latitude = 0,
longitude = 0,
zoom = 0,
pitch = 0,
bearing = 0,
altitude = 1.5,
nearZMultiplier = 0.02,
farZMultiplier = 1.01
} = {width: 1, height: 1}
) {
// Silently allow apps to send in 0,0 to facilitate isomorphic render etc

@@ -78,3 +50,2 @@ width = width || 1;

pitch,
bearing,
altitude,

@@ -109,14 +80,4 @@ nearZMultiplier,

}
/* eslint-enable complexity */
/**
* Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.
* Performs the nonlinear part of the web mercator projection.
* Remaining projection is done with 4x4 matrices which also handles
* perspective.
*
* @param {Array} lngLat - [lng, lat] coordinates
* Specifies a point on the sphere to project onto the map.
* @return {Array} [x,y] coordinates.
*/
// Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.
projectFlat(lngLat) {

@@ -126,11 +87,3 @@ return lngLatToWorld(lngLat);

/**
* Unproject world point [x,y] on map onto {lat, lon} on sphere
*
* @param {object|Vector} xy - object with {x,y} members
* representing point on projected map plane
* @return {GeoCoordinates} - object with {lat,lon} of point on sphere.
* Has toArray method if you need a GeoJSON Array.
* Per cartographic tradition, lat and lon are specified as degrees.
*/
// Unproject world point [x,y] on map onto {lat, lon} on sphere
unprojectFlat(xy) {

@@ -140,12 +93,3 @@ return worldToLngLat(xy);

/**
* Get the map center that place a given [lng, lat] coordinate at screen
* point [x, y]
*
* @param {Array} lngLat - [lng,lat] coordinates
* Specifies a point on the sphere.
* @param {Array} pos - [x,y] coordinates
* Specifies a point on the screen.
* @return {Array} [lng,lat] new map center.
*/
// Get the map center that place a given [lng, lat] coordinate at screen point [x, y]
getMapCenterByLngLatPosition({lngLat, pos}) {

@@ -158,3 +102,3 @@ const fromLocation = pixelsToWorld(pos, this.pixelUnprojectionMatrix);

return worldToLngLat(newCenter, this.scale);
return worldToLngLat(newCenter);
}

@@ -167,11 +111,3 @@

/**
* Returns a new viewport that fit around the given rectangle.
* Only supports non-perspective mode.
* @param {Array} bounds - [[lon, lat], [lon, lat]]
* @param {Number} [options.padding] - The amount of padding in pixels to add to the given bounds.
* @param {Array} [options.offset] - The center of the given bounds relative to the map's center,
* [x, y] measured in pixels.
* @returns {WebMercatorViewport}
*/
// Returns a new viewport that fit around the given rectangle.
fitBounds(bounds, options = {}) {

@@ -178,0 +114,0 @@ const {width, height} = this;

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