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

Convert to and from lat/lng and pixels in web mercator at arbitrary floating point zoom levels.

  • 4.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
198K
increased by16.47%
Maintainers
4
Weekly downloads
 
Created

What is viewport-mercator-project?

The viewport-mercator-project npm package is a utility library for performing viewport-related calculations in web mapping applications. It is particularly useful for converting between geographic coordinates and screen coordinates, handling zoom levels, and managing map projections.

What are viewport-mercator-project's main functionalities?

Project geographic coordinates to screen coordinates

This feature allows you to project geographic coordinates (longitude, latitude) to screen coordinates (x, y) based on the current viewport settings.

const { WebMercatorViewport } = require('viewport-mercator-project');

const viewport = new WebMercatorViewport({
  width: 800,
  height: 600,
  longitude: -122.45,
  latitude: 37.78,
  zoom: 12
});

const screenCoords = viewport.project([-122.45, 37.78]);
console.log(screenCoords); // [400, 300]

Unproject screen coordinates to geographic coordinates

This feature allows you to convert screen coordinates (x, y) back to geographic coordinates (longitude, latitude) based on the current viewport settings.

const { WebMercatorViewport } = require('viewport-mercator-project');

const viewport = new WebMercatorViewport({
  width: 800,
  height: 600,
  longitude: -122.45,
  latitude: 37.78,
  zoom: 12
});

const geoCoords = viewport.unproject([400, 300]);
console.log(geoCoords); // [-122.45, 37.78]

Get bounding box of the viewport

This feature allows you to get the geographic bounding box of the current viewport, which can be useful for determining the area currently visible on the map.

const { WebMercatorViewport } = require('viewport-mercator-project');

const viewport = new WebMercatorViewport({
  width: 800,
  height: 600,
  longitude: -122.45,
  latitude: 37.78,
  zoom: 12
});

const bounds = viewport.getBounds();
console.log(bounds); // [[-122.519, 37.704], [-122.381, 37.856]]

Other packages similar to viewport-mercator-project

FAQs

Package last updated on 03 May 2017

Did you know?

Socket

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.

Install

Related posts

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