leaflet
Version:
JavaScript library for mobile-friendly interactive maps
140 lines (139 loc) • 4.8 kB
TypeScript
import { LatLngBounds } from './LatLngBounds.js';
export type LatLngTuple = [number, number, number?];
export type LatLngLiteral = {
lat: number;
lng: number;
alt?: number;
};
export type LatLngExpression = LatLng | LatLngTuple | LatLngLiteral | {
lat: number;
lon: number;
alt?: number;
};
/** @typedef {[number, number, number?]} LatLngTuple */
/** @typedef {{lat: number, lng: number, alt?: number}} LatLngLiteral */
/**
* A `LatLng`, or its array (`[lat, lng]`, `[lat, lng, alt]`) or object (`{lat, lng}`, `{lat, lon}`) form.
* @typedef {LatLng | LatLngTuple | LatLngLiteral | {lat: number, lon: number, alt?: number}} LatLngExpression
*/
/**
* Represents a geographical point with a certain latitude and longitude.
*
* @example
* ```js
* const latlng = new LatLng(50.5, 30.5);
* ```
*
* All Leaflet methods that accept LatLng objects also accept them in a simple Array form and simple object form
* (unless noted otherwise), so these lines are equivalent:
*
* ```js
* map.panTo([50, 30]);
* map.panTo({lat: 50, lng: 30});
* map.panTo({lat: 50, lon: 30});
* map.panTo(new LatLng(50, 30));
* ```
*
* Note that `LatLng` does not inherit from Leaflet's `Class` object, which means new classes can't inherit from it,
* and new methods can't be added to it with the `include` function.
*
* @categoryDescription Functions
* There are several static functions which can be called without instantiating LatLng:
*/
export declare class LatLng {
/**
* Latitude in degrees
* @type {number}
*/
lat: number;
/**
* Longitude in degrees
* @type {number}
*/
lng: number;
/**
* Altitude in meters (optional)
* @type {number | undefined}
*/
alt: number | undefined;
constructor(lat: number, lng: number, alt?: number);
constructor(coords: LatLngExpression);
/**
* Returns `true` if the LatLng object can be properly initialized.
* @category Functions
* @overload
* @param {number} lat
* @param {number} [lng]
* @param {number} [alt]
* @returns {boolean}
*/
/**
* Expects an array of the form `[Number, Number]` or `[Number, Number, Number]`, or a plain object of the form
* `{lat: Number, lng: Number}`. Returns `true` if the LatLng object can be properly initialized.
* @overload
* @param {LatLngExpression} coords
* @returns {boolean}
*/
/**
* @param {unknown} lat
* @param {unknown} [lng]
* @param {unknown} [alt]
*/
static validate(lat: number, lng?: number, alt?: number): boolean;
/**
* Returns `true` if the LatLng object can be properly initialized.
* @category Functions
* @overload
* @param {number} lat
* @param {number} [lng]
* @param {number} [alt]
* @returns {boolean}
*/
/**
* Expects an array of the form `[Number, Number]` or `[Number, Number, Number]`, or a plain object of the form
* `{lat: Number, lng: Number}`. Returns `true` if the LatLng object can be properly initialized.
* @overload
* @param {LatLngExpression} coords
* @returns {boolean}
*/
/**
* @param {unknown} lat
* @param {unknown} [lng]
* @param {unknown} [alt]
*/
static validate(coords: LatLngExpression): boolean;
/**
* Returns `true` if the given `LatLng` point is at the same position (within a small margin of
* error). The margin of error can be overridden by setting `maxMargin` to a small number.
* @param {LatLngExpression} [obj]
* @param {number} [maxMargin]
*/
equals(obj?: LatLngExpression, maxMargin?: number): boolean;
/**
* Returns a string representation of the point (for debugging purposes).
* @param {number} [precision]
*/
toString(precision?: number): string;
/**
* Returns the distance (in meters) to the given `LatLng` calculated using the
* [Haversine formula](https://en.wikipedia.org/wiki/Haversine_formula).
* @param {LatLngExpression} other
*/
distanceTo(other: LatLngExpression): number;
/** Returns a new `LatLng` object with the longitude wrapped so it's always between -180 and +180 degrees. */
wrap(): LatLng;
/**
* Returns a new `LatLngBounds` object in which each boundary is `sizeInMeters/2` meters apart from the `LatLng`.
* @param {number} sizeInMeters
*/
toBounds(sizeInMeters: number): LatLngBounds;
/** Returns a copy of the current LatLng. */
clone(): LatLng;
}
/**
* Great-circle distance on a sphere of radius R, shared with `EarthCRS.distance`.
* @param {LatLng} latlng1
* @param {LatLng} latlng2
* @param {number} R
*/
export declare function haversineDistance(latlng1: LatLng, latlng2: LatLng, R: number): number;