Skip to content

Point

Defined in: leaflet/utils/point.ts:34

A typescript reimplementation of Leaflet's point merged with Mapbox' or MapLibre's Point API, from https://github.com/mapbox/point-geometry/

Can be used in place of both.


Represents a point with x and y coordinates in pixels.

Example

var point = L.point(200, 300);

All Leaflet methods and options that accept Point objects also accept them in a simple Array form (unless noted otherwise), so these lines are equivalent:

map.panBy([200, 300]);
map.panBy(L.point(200, 300));

Note that Point 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.

Methods

_mult()

_mult(num: number): this

Defined in: leaflet/utils/point.ts:316

Returns the result of multiplication of the current point by the given number.

Parameters

Parameter Type
num number

Returns

this


add()

add(point: PointExpression): Point

Defined in: leaflet/utils/point.ts:59

Returns the result of addition of the current and the given points, yielding a new point.

Parameters

Parameter Type
point PointExpression

Returns

Point


angle()

angle(): number

Defined in: leaflet/utils/point.ts:416

Get the angle from the 0, 0 coordinate to this point, in radians coordinates.

Returns

number


angleTo()

angleTo(b: Point): number

Defined in: leaflet/utils/point.ts:424

Get the angle from this point to another point, in radians

Parameters

Parameter Type Description
b Point the other point

Returns

number


angleWith()

angleWith(b: Point): number

Defined in: leaflet/utils/point.ts:432

Get the angle between this point and another point, in radians

Parameters

Parameter Type Description
b Point the other point

Returns

number


angleWithSep()

angleWithSep(x: number, y: number): number

Defined in: leaflet/utils/point.ts:442

Find the angle of the two vectors, solving the formula for the cross product a x b = |a||b|sin(θ) for θ.

Parameters

Parameter Type Description
x number the x-coordinate
y number the y-coordinate

Returns

number


ceil()

ceil(): Point

Defined in: leaflet/utils/point.ts:185

Returns a copy of the current point with ceiled coordinates (rounded up).

Returns

Point


clone()

clone(): Point

Defined in: leaflet/utils/point.ts:52

Returns a copy of the current point.

Returns

Point


contains()

contains(point: PointExpression): boolean

Defined in: leaflet/utils/point.ts:240

Returns true if both coordinates of the given point-like object are less than the corresponding current point coordinates (in absolute values).

Parameters

Parameter Type
point PointExpression

Returns

boolean


dist()

dist(p: Point): number

Defined in: leaflet/utils/point.ts:396

Calculate the distance from this point to another point

Parameters

Parameter Type Description
p Point the other point

Returns

number


distanceTo()

distanceTo(point: PointExpression): number

Defined in: leaflet/utils/point.ts:219

Returns the cartesian distance between the current and the given points.

Parameters

Parameter Type
point PointExpression

Returns

number


distSqr()

distSqr(p: Point): number

Defined in: leaflet/utils/point.ts:406

Calculate the distance from this point to another point, without the square root step. Useful if you're comparing relative distances.

Parameters

Parameter Type Description
p Point the other point

Returns

number


div()

div(num: number): Point

Defined in: leaflet/utils/point.ts:292

Returns the result of division of the current point by the given number, yielding a new point.

Parameters

Parameter Type
num number

Returns

Point


divByPoint()

divByPoint(p: PointExpression): Point

Defined in: leaflet/utils/point.ts:279

Divide this point's x & y coordinates by point, yielding a new point.

Parameters

Parameter Type
p PointExpression

Returns

Point


divideBy()

divideBy(num: number): Point

Defined in: leaflet/utils/point.ts:99

Returns the result of division of the current point by the given number, yielding a new point.

Parameters

Parameter Type
num number

Returns

Point


equals()

equals(point: PointExpression): boolean

Defined in: leaflet/utils/point.ts:231

Returns true if the given point-like object has the same coordinates.

Parameters

Parameter Type
point PointExpression

Returns

boolean


floor()

floor(): Point

Defined in: leaflet/utils/point.ts:168

Returns a copy of the current point with floored coordinates (rounded down).

Returns

Point


mag()

mag(): number

Defined in: leaflet/utils/point.ts:388

Return the magnitude of this point: this is the Euclidean distance from the 0, 0 coordinate to this point's x and y coordinates.

Returns

number


matMult()

matMult(m: [number, number, number, number]): Point

Defined in: leaflet/utils/point.ts:358

Multiply this point by a 4x1 transformation matrix, yielding a new point.

Parameters

Parameter Type Description
m [number, number, number, number] transformation matrix

Returns

Point


mult()

mult(num: number): Point

Defined in: leaflet/utils/point.ts:309

Returns the result of multiplication of the current point by the given number, yielding a new point.

Parameters

Parameter Type
num number

Returns

Point


multByPoint()

multByPoint(p: PointExpression): Point

Defined in: leaflet/utils/point.ts:325

Multiply this point's x & y coordinates by point, yielding a new point.

Parameters

Parameter Type
p PointExpression

Returns

Point


multiplyBy()

multiplyBy(num: number): Point

Defined in: leaflet/utils/point.ts:116

Returns the result of multiplication of the current point by the given number, yielding a new point.

Parameters

Parameter Type
num number

Returns

Point


perp()

perp(): Point

Defined in: leaflet/utils/point.ts:379

Compute a perpendicular point, where the new y coordinate is the old x coordinate and the new x coordinate is the old y coordinate multiplied by -1. Yields a new point.

Returns

Point


rotate()

rotate(a: number): Point

Defined in: leaflet/utils/point.ts:340

Rotate this point around the 0, 0 origin by an angle a, given in radians, yielding a new point.

Parameters

Parameter Type Description
a number angle to rotate around, in radians

Returns

Point


rotateAround()

rotateAround(a: number, p: Point): Point

Defined in: leaflet/utils/point.ts:350

Rotate this point around p point by an angle a, given in radians, yielding a new point.

Parameters

Parameter Type Description
a number angle to rotate around, in radians
p Point Point to rotate around

Returns

Point


round()

round(): Point

Defined in: leaflet/utils/point.ts:151

Returns a copy of the current point with rounded coordinates.

Returns

Point


scaleBy()

scaleBy(point: Point): Point

Defined in: leaflet/utils/point.ts:136

Multiply each coordinate of the current point by each coordinate of scale. In linear algebra terms, multiply the point by the scaling matrix defined by scale.

Parameters

Parameter Type
point Point

Returns

Point


sub()

sub(point: PointExpression): Point

Defined in: leaflet/utils/point.ts:261

Returns the result of subtraction of the given point from the current, yielding a new point. The same as subtract.

Parameters

Parameter Type
point PointExpression

Returns

Point


subtract()

subtract(point: PointExpression): Point

Defined in: leaflet/utils/point.ts:81

Returns the result of subtraction of the given point from the current, yielding a new point. The same as sub.

Parameters

Parameter Type
point PointExpression

Returns

Point


toString()

toString(): string

Defined in: leaflet/utils/point.ts:249

Returns a string representation of the point for debugging purposes.

Returns

string


trunc()

trunc(): Point

Defined in: leaflet/utils/point.ts:202

Returns a copy of the current point with truncated coordinates (rounded towards zero).

Returns

Point


unit()

unit(): Point

Defined in: leaflet/utils/point.ts:369

Calculate this point but as a unit vector from 0, 0, meaning that the distance from the resulting point to the 0, 0 coordinate will be equal to 1 and the angle from the resulting point to the 0, 0 coordinate will be the same as before. Yields a new point.

Returns

Point


unscaleBy()

unscaleBy(point: Point): Point

Defined in: leaflet/utils/point.ts:144

Inverse of scaleBy. Divide each coordinate of the current point by each coordinate of scale.

Parameters

Parameter Type
point Point

Returns

Point


convert()

static convert(p: PointExpression): Point

Defined in: leaflet/utils/point.ts:490

Construct a point from an array if necessary, otherwise if the input is already a Point, return it unchanged.

Parameters

Parameter Type
p PointExpression

Returns

Point

Properties

x

x: number

Defined in: leaflet/utils/point.ts:38

The x coordinate of the point.


y

y: number

Defined in: leaflet/utils/point.ts:42

The y coordinate of the point.