maplair
Version:
JavaScript library for mobile-friendly interactive maps
37 lines (33 loc) • 1.09 kB
JavaScript
import {CRS} from './CRS.js';
import {haversineDistance} from '../LatLng.js';
/** @import {LatLng} from '../LatLng.js' */
/**
* Serves as the base for CRS that are global such that they cover the earth.
* Can only be used as the base for other CRS and cannot be used directly,
* since it does not have a `code`, `projection` or `transformation`. `distance()` returns
* meters.
*/
export class EarthCRS extends CRS {
/**
* The range around which the longitude axis wraps (none if `undefined`).
* @type {[number, number]|undefined}
*/
static wrapLng = [-180, 180];
/**
* Mean Earth Radius in meters, as recommended for use by
* the International Union of Geodesy and Geophysics,
* see https://rosettacode.org/wiki/Haversine_formula
* @type {number}
*/
static R = 6371000;
/**
* Returns the distance in meters between two geographical points using the
* Haversine approximation.
* @param {LatLng} latlng1
* @param {LatLng} latlng2
* @returns {number}
*/
static distance(latlng1, latlng2) {
return haversineDistance(latlng1, latlng2, this.R);
}
}