UNPKG

highcharts

Version:
90 lines (89 loc) 2.05 kB
/* * * * Web Mercator projection, used for most online map tile services * * (c) 2021-2026 Highsoft AS * * A commercial license may be required depending on use. * See www.highcharts.com/license * * Authors: * - Torstein Honsi * * */ 'use strict'; /* * * * Constants * * */ const r = 63.78137, deg2rad = Math.PI / 180; /* * * * Class * * */ /** * Web Mercator is a variant of the Mercator map projection and is the de facto * standard for Web mapping applications. * * Web Mercator is primarily created for tiled map services, as when zooming in * to smaller scales, the angle between lines on the surface is approximately * retained. * * The great disadvantage of Web Mercator is that areas inflate with distance * from the equator. For example, in the world map, Greenland appears roughly * the same size as Africa. In reality Africa is 14 times larger, as is apparent * from the Equal Earth or Orthographic projections. * * @class * @name Highcharts.WebMercator */ class WebMercator { constructor() { /* * * * Properties * * */ /** @internal */ this.bounds = { x1: -200.37508342789243, x2: 200.37508342789243, y1: -200.3750834278071, y2: 200.3750834278071 }; /** * The latitude that defines a square. * @internal */ this.maxLatitude = 85.0511287798; } /* * * * Functions * * */ forward(lonLat) { const sinLat = Math.sin(lonLat[1] * deg2rad), xy = [ r * lonLat[0] * deg2rad, r * Math.log((1 + sinLat) / (1 - sinLat)) / 2 ]; if (Math.abs(lonLat[1]) > this.maxLatitude) { xy.outside = true; } return xy; } inverse(xy) { return [ xy[0] / (r * deg2rad), (2 * Math.atan(Math.exp(xy[1] / r)) - (Math.PI / 2)) / deg2rad ]; } } /* * * * Default Export * * */ export default WebMercator;