Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
@math.gl/web-mercator
Advanced tools
Utilities for perspective-enabled Web Mercator projections
@math.gl/web-mercator is a JavaScript library that provides utilities for working with Web Mercator projections. It is part of the math.gl suite of libraries and is designed to facilitate geographic calculations and transformations, particularly for mapping and visualization applications.
Project geographic coordinates to Web Mercator
This feature allows you to project geographic coordinates (longitude and latitude) to Web Mercator coordinates. The code sample demonstrates how to create a WebMercatorViewport and project a specific geographic coordinate to Web Mercator coordinates.
const { WebMercatorViewport } = require('@math.gl/web-mercator');
const viewport = new WebMercatorViewport({
width: 800,
height: 600,
longitude: -122.45,
latitude: 37.78,
zoom: 12
});
const [x, y] = viewport.project([-122.45, 37.78]);
console.log(`Projected coordinates: (${x}, ${y})`);
Unproject Web Mercator coordinates to geographic coordinates
This feature allows you to unproject Web Mercator coordinates back to geographic coordinates (longitude and latitude). The code sample demonstrates how to create a WebMercatorViewport and unproject a specific Web Mercator coordinate to geographic coordinates.
const { WebMercatorViewport } = require('@math.gl/web-mercator');
const viewport = new WebMercatorViewport({
width: 800,
height: 600,
longitude: -122.45,
latitude: 37.78,
zoom: 12
});
const [longitude, latitude] = viewport.unproject([400, 300]);
console.log(`Geographic coordinates: (${longitude}, ${latitude})`);
Calculate the bounding box of a viewport
This feature allows you to calculate the geographic bounding box of a viewport. The code sample demonstrates how to create a WebMercatorViewport and get the bounding box of the viewport.
const { WebMercatorViewport } = require('@math.gl/web-mercator');
const viewport = new WebMercatorViewport({
width: 800,
height: 600,
longitude: -122.45,
latitude: 37.78,
zoom: 12
});
const bounds = viewport.getBounds();
console.log(`Bounding box: ${JSON.stringify(bounds)}`);
Proj4 is a JavaScript library for cartographic projections and coordinate transformations. It supports a wide range of projections and is highly configurable. Compared to @math.gl/web-mercator, proj4 offers more flexibility and a broader range of projections, but it may be more complex to use for simple Web Mercator transformations.
D3-geo is a module of the D3.js library that provides geographic projections and transformations. It is well-integrated with the D3 ecosystem and is suitable for creating complex visualizations. Compared to @math.gl/web-mercator, d3-geo offers more visualization capabilities but may require more setup for basic Web Mercator transformations.
Mapbox GL JS is a JavaScript library for interactive, customizable vector maps on the web. It includes built-in support for Web Mercator projections and provides a rich set of features for map rendering and interaction. Compared to @math.gl/web-mercator, Mapbox GL JS is more focused on map rendering and interaction, while @math.gl/web-mercator is more focused on the mathematical aspects of projections.
FAQs
Utilities for perspective-enabled Web Mercator projections
The npm package @math.gl/web-mercator receives a total of 167,957 weekly downloads. As such, @math.gl/web-mercator popularity was classified as popular.
We found that @math.gl/web-mercator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.