/** @import {LatLngExpression} from './LatLng.js' */ /** * A geographical area: a `LatLngBounds`, or an array of geographical points (usually * two diagonally opposite corners), e.g. `[[40.712, -74.227], [40.774, -74.125]]`. * Accepted by all Maplair methods which accept `LatLngBounds` objects (unless noted * otherwise). * @typedef {LatLngBounds|LatLngExpression[]} LatLngBoundsExpression */ /** * Represents a rectangular geographical area on a map. * * @example * ```js * const corner1 = new LatLng(40.712, -74.227), * corner2 = new LatLng(40.774, -74.125), * bounds = new LatLngBounds(corner1, corner2); * ``` * * All Maplair methods that accept LatLngBounds objects also accept them in a simple * Array form (unless noted otherwise), so the bounds example above can be passed like * this: * * ```js * map.fitBounds([ * [40.712, -74.227], * [40.774, -74.125] * ]); * ``` * * Caution: if the area crosses the antimeridian (often confused with the International * Date Line), you must specify corners _outside_ the [-180, 180] degrees longitude range. * * Note that `LatLngBounds` does not inherit from Maplair'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. */ export class LatLngBounds { /** * Returns the given `LatLngBounds` object as it is, or else a new `LatLngBounds` * object created from the given arguments (the same as of the constructor) — unlike * the constructor, which always creates a new object. * @param {LatLngExpression|LatLngBoundsExpression} [corner1] The first corner, the * points or the bounds. * @param {LatLngExpression} [corner2] The opposite corner. * @returns {LatLngBounds} */ static from(corner1?: LatLngExpression | LatLngBoundsExpression, corner2?: LatLngExpression): LatLngBounds; /** * Creates a `LatLngBounds` object by defining two diagonally opposite corners of the * rectangle. Alternatively, creates a `LatLngBounds` object defined by the * geographical points it contains (very useful for zooming the map to fit a * particular set of locations with [`fitBounds`](#map-fitbounds)), or a copy of the * given `LatLngBounds` object. * @param {LatLngExpression|LatLngBoundsExpression} [corner1] The first corner, the * points or the bounds to copy. * @param {LatLngExpression} [corner2] The opposite corner. */ constructor(corner1?: LatLngExpression | LatLngBoundsExpression, corner2?: LatLngExpression); /** * Extend the bounds to contain the given point or bounds. * @param {LatLngExpression|LatLngBoundsExpression} obj * @returns {this} */ extend(obj: LatLngExpression | LatLngBoundsExpression): this; /** * Returns bounds created by extending or retracting the current bounds by a given * ratio in each direction. For example, a ratio of 0.5 extends the bounds by 50% in * each direction. Negative values will retract the bounds. * @param {number} bufferRatio * @returns {LatLngBounds} */ pad(bufferRatio: number): LatLngBounds; /** * Returns the center point of the bounds. * @returns {LatLng} */ getCenter(): LatLng; /** * Returns the south-west point of the bounds. * @returns {LatLng} */ getSouthWest(): LatLng; /** * Returns the north-east point of the bounds. * @returns {LatLng} */ getNorthEast(): LatLng; /** * Returns the north-west point of the bounds. * @returns {LatLng} */ getNorthWest(): LatLng; /** * Returns the south-east point of the bounds. * @returns {LatLng} */ getSouthEast(): LatLng; /** * Returns the west longitude of the bounds. * @returns {number} */ getWest(): number; /** * Returns the south latitude of the bounds. * @returns {number} */ getSouth(): number; /** * Returns the east longitude of the bounds. * @returns {number} */ getEast(): number; /** * Returns the north latitude of the bounds. * @returns {number} */ getNorth(): number; /** * Returns `true` if the rectangle contains the given bounds or point. * @param {LatLngBoundsExpression|LatLngExpression} obj * @returns {boolean} */ contains(obj: LatLngBoundsExpression | LatLngExpression): boolean; /** * Returns `true` if the rectangle intersects the given bounds. Two bounds intersect * if they have at least one point in common. * @param {LatLngBoundsExpression} bounds * @returns {boolean} */ intersects(bounds: LatLngBoundsExpression): boolean; /** * Returns `true` if the rectangle overlaps the given bounds. Two bounds overlap if * their intersection is an area. * @param {LatLngBoundsExpression} bounds * @returns {boolean} */ overlaps(bounds: LatLngBoundsExpression): boolean; /** * Returns a string with bounding box coordinates in a * 'southwest_lng,southwest_lat,northeast_lng,northeast_lat' format. Useful for * sending requests to web services that return geo data. * @returns {string} */ toBBoxString(): string; /** * Returns `true` if the rectangle is equivalent (within a small margin of error) to * the given bounds. The margin of error can be overridden by setting `maxMargin` to * a small number. * @param {LatLngBoundsExpression} bounds * @param {number} [maxMargin] * @returns {boolean} */ equals(bounds: LatLngBoundsExpression, maxMargin?: number): boolean; /** * Returns `true` if the bounds are properly initialized. * @returns {boolean} */ isValid(): boolean; } /** * A geographical area: a `LatLngBounds`, or an array of geographical points (usually * two diagonally opposite corners), e.g. `[[40.712, -74.227], [40.774, -74.125]]`. * Accepted by all Maplair methods which accept `LatLngBounds` objects (unless noted * otherwise). */ export type LatLngBoundsExpression = LatLngBounds | LatLngExpression[]; import { LatLng } from './LatLng.js'; import type { LatLngExpression } from './LatLng.js';