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

@math.gl/web-mercator

Package Overview
Dependencies
Maintainers
3
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 3.5.4 to 3.5.5

51

dist/es5/normalize-viewport-props.js
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -10,8 +8,7 @@ value: true

var _webMercatorViewport = _interopRequireDefault(require("./web-mercator-viewport"));
var _webMercatorUtils = require("./web-mercator-utils");
var _mathUtils = require("./math-utils");
var MAX_LATITUDE = 85.05113;
var MIN_LATITUDE = -85.05113;
var TILE_SIZE = 512;

@@ -37,34 +34,20 @@ function normalizeViewportProps(_ref) {

var flatViewport = new _webMercatorViewport.default({
width: width,
height: height,
longitude: longitude,
latitude: latitude,
zoom: zoom
});
var topY = flatViewport.project([longitude, MAX_LATITUDE])[1];
var bottomY = flatViewport.project([longitude, MIN_LATITUDE])[1];
var shiftY = 0;
var minZoom = (0, _mathUtils.log2)(height / TILE_SIZE);
if (bottomY - topY < height) {
zoom += (0, _mathUtils.log2)(height / (bottomY - topY));
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 (zoom <= minZoom) {
zoom = minZoom;
latitude = 0;
} else {
var halfHeightPixels = height / 2 / Math.pow(2, zoom);
var minLatitude = (0, _webMercatorUtils.worldToLngLat)([0, halfHeightPixels])[1];
if (topY > 0) {
shiftY = topY;
} else if (bottomY < height) {
shiftY = bottomY - height;
}
if (latitude < minLatitude) {
latitude = minLatitude;
} else {
var maxLatitude = (0, _webMercatorUtils.worldToLngLat)([0, TILE_SIZE - halfHeightPixels])[1];
if (shiftY) {
latitude = flatViewport.unproject([width / 2, height / 2 + shiftY])[1];
if (latitude > maxLatitude) {
latitude = maxLatitude;
}
}
}

@@ -71,0 +54,0 @@

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

import WebMercatorViewport from './web-mercator-viewport';
import { worldToLngLat } from './web-mercator-utils';
import { mod, log2 } from './math-utils';
const MAX_LATITUDE = 85.05113;
const MIN_LATITUDE = -85.05113;
const TILE_SIZE = 512;
export default function normalizeViewportProps({

@@ -22,34 +21,20 @@ width,

let flatViewport = new WebMercatorViewport({
width,
height,
longitude,
latitude,
zoom
});
let topY = flatViewport.project([longitude, MAX_LATITUDE])[1];
let bottomY = flatViewport.project([longitude, MIN_LATITUDE])[1];
let shiftY = 0;
const minZoom = log2(height / TILE_SIZE);
if (bottomY - topY < height) {
zoom += 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];
}
if (zoom <= minZoom) {
zoom = minZoom;
latitude = 0;
} else {
const halfHeightPixels = height / 2 / Math.pow(2, zoom);
const minLatitude = worldToLngLat([0, halfHeightPixels])[1];
if (topY > 0) {
shiftY = topY;
} else if (bottomY < height) {
shiftY = bottomY - height;
}
if (latitude < minLatitude) {
latitude = minLatitude;
} else {
const maxLatitude = worldToLngLat([0, TILE_SIZE - halfHeightPixels])[1];
if (shiftY) {
latitude = flatViewport.unproject([width / 2, height / 2 + shiftY])[1];
if (latitude > maxLatitude) {
latitude = maxLatitude;
}
}
}

@@ -56,0 +41,0 @@

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

"license": "MIT",
"version": "3.5.4",
"version": "3.5.5",
"keywords": [

@@ -37,3 +37,3 @@ "webgl",

},
"gitHead": "e181bb48f3513e443abb2e7dc792c65db42eefe4"
"gitHead": "07734006e0647c311fef9faa2e1f23f801cfe553"
}

@@ -1,7 +0,6 @@

import WebMercatorViewport from './web-mercator-viewport';
import {worldToLngLat} from './web-mercator-utils';
import {mod, log2} from './math-utils';
// defined by mapbox-gl
const MAX_LATITUDE = 85.05113;
const MIN_LATITUDE = -85.05113;
const TILE_SIZE = 512;

@@ -28,29 +27,21 @@ // Apply mathematical constraints to viewport props

// Constrain zoom and shift center at low zoom levels
let flatViewport = new WebMercatorViewport({width, height, longitude, latitude, zoom});
let topY = flatViewport.project([longitude, MAX_LATITUDE])[1];
let bottomY = flatViewport.project([longitude, MIN_LATITUDE])[1];
let shiftY = 0;
if (bottomY - topY < height) {
// Map height must not be smaller than viewport height
// Zoom out map to fit map height into viewport
zoom += log2(height / (bottomY - topY));
// Calculate top and bottom using new zoom
flatViewport = new WebMercatorViewport({width, height, longitude, latitude, zoom});
topY = flatViewport.project([longitude, MAX_LATITUDE])[1];
bottomY = flatViewport.project([longitude, MIN_LATITUDE])[1];
const minZoom = log2(height / TILE_SIZE);
if (zoom <= minZoom) {
zoom = minZoom;
latitude = 0;
} else {
// Eliminate white space above and below the map
const halfHeightPixels = height / 2 / Math.pow(2, zoom);
const minLatitude = worldToLngLat([0, halfHeightPixels])[1];
if (latitude < minLatitude) {
latitude = minLatitude;
} else {
const maxLatitude = worldToLngLat([0, TILE_SIZE - halfHeightPixels])[1];
if (latitude > maxLatitude) {
latitude = maxLatitude;
}
}
}
if (topY > 0) {
// Compensate for white gap on top
shiftY = topY;
} else if (bottomY < height) {
// Compensate for white gap on bottom
shiftY = bottomY - height;
}
if (shiftY) {
latitude = flatViewport.unproject([width / 2, height / 2 + shiftY])[1];
}
return {width, height, longitude, latitude, zoom, pitch, bearing};
}

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