UNPKG

maplair

Version:

JavaScript library for mobile-friendly interactive maps

27 lines (26 loc) • 961 B
import { Point } from "../../geometry/Point.js"; import { Bounds } from "../../geometry/Bounds.js"; import { LatLng } from "../LatLng.js"; //#region src/geo/projection/Projection.SphericalMercator.js const earthRadius = 6378137; const SphericalMercator = { R: earthRadius, MAX_LATITUDE: 85.0511287798, project(latlng) { latlng = new LatLng(latlng); const d = Math.PI / 180, max = this.MAX_LATITUDE, lat = Math.max(Math.min(max, latlng.lat), -max), sin = Math.sin(lat * d); return new Point(this.R * latlng.lng * d, this.R * Math.log((1 + sin) / (1 - sin)) / 2); }, unproject(point) { point = new Point(point); const d = 180 / Math.PI; return new LatLng((2 * Math.atan(Math.exp(point.y / this.R)) - Math.PI / 2) * d, point.x * d / this.R); }, bounds: (() => { const d = earthRadius * Math.PI; return new Bounds([-d, -d], [d, d]); })() }; //#endregion export { SphericalMercator }; //# sourceMappingURL=Projection.SphericalMercator.js.map