leaflet
Version:
JavaScript library for mobile-friendly interactive maps
96 lines (95 loc) • 3.52 kB
TypeScript
import { Point } from './Point.js';
import type { PointExpression, PointTuple } from './Point.js';
export type BoundsLiteral = PointTuple[];
export type BoundsExpression = Bounds | PointExpression[];
/** @import {PointExpression, PointTuple} from './Point.js' */
/** @typedef {PointTuple[]} BoundsLiteral */
/**
* A `Bounds`, or an array of the points it should contain (usually two opposite corners).
* @typedef {Bounds | PointExpression[]} BoundsExpression
*/
/**
* Represents a rectangular area in pixel coordinates.
*
* @example
* ```js
* const p1 = new Point(10, 10),
* p2 = new Point(40, 60),
* bounds = new Bounds(p1, p2);
* ```
*
* All Leaflet methods that accept `Bounds` objects also accept them in a simple Array form (unless noted
* otherwise), so the bounds example above can be passed like this:
*
* ```js
* otherBounds.intersects([[10, 10], [40, 60]]);
* ```
*
* Note that `Bounds` 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.
*/
export declare class Bounds {
/**
* The top left corner of the rectangle.
* @type {Point}
*/
min: Point;
/**
* The bottom right corner of the rectangle.
* @type {Point}
*/
max: Point;
constructor(corner1: PointExpression, corner2: PointExpression);
constructor(points: BoundsExpression);
constructor();
/**
* Extends the bounds to contain the given point or bounds.
* @param {PointExpression | BoundsExpression} obj
*/
extend(obj: PointExpression | BoundsExpression): this;
/**
* Returns the center point of the bounds.
* @param {boolean} [round]
*/
getCenter(round?: boolean): Point;
/** Returns the bottom-left point of the bounds. */
getBottomLeft(): Point;
/** Returns the top-right point of the bounds. */
getTopRight(): Point;
/** Returns the top-left point of the bounds (i.e. [`this.min`](#bounds-min)). */
getTopLeft(): Point;
/** Returns the bottom-right point of the bounds (i.e. [`this.max`](#bounds-max)). */
getBottomRight(): Point;
/** Returns the size of the given bounds */
getSize(): Point;
/**
* Returns `true` if the rectangle contains the given point or bounds.
* @param {PointExpression | BoundsExpression} obj
*/
contains(obj: PointExpression | BoundsExpression): boolean;
/**
* Returns `true` if the rectangle intersects the given bounds. Two
* bounds intersect if they have at least one point in common.
* @param {BoundsExpression} bounds
*/
intersects(bounds: BoundsExpression): boolean;
/**
* Returns `true` if the rectangle overlaps the given bounds.
* Two bounds overlap if their intersection is an area.
* @param {BoundsExpression} bounds
*/
overlaps(bounds: BoundsExpression): boolean;
/** Returns `true` if the bounds are properly initialized. */
isValid(): boolean;
/**
* 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
*/
pad(bufferRatio: number): Bounds;
/**
* Returns `true` if the rectangle is equivalent to the given bounds.
* @param {BoundsExpression} [bounds]
*/
equals(bounds?: BoundsExpression): boolean;
}