Point
The Point
object represents a set of x and y pixel coordinates within the map view.
Point
extends Base.
Usage example
const point = G.point(15, -100)
Creating the Point object
G.point(x: PointValue, y?: number): Point
There are a few ways to setup the Point
object.
No parameters.
G.point(): Point
const point = G.point();
Pass the x and y values.
G.point(x: number, y: number): Point
Parameter | Type | Required | Description |
---|---|---|---|
x | number | Yes | The "x" value. |
y | number | Yes | The "y" value. |
const point = G.point(15, -100);
Pass the x and y values as an array.
G.point([x: number, y: number]): Point
Parameter | Type | Required | Description |
---|---|---|---|
value | Array | Yes | An array containing the x and y values |
const point = G.point([15, -100]);
Pass the x and y values as an object.
G.point({x: x: number, y: y: number}): Point
Parameter | Type | Required | Description |
---|---|---|---|
value | object | Yes | An object containing the x and y values |
const point = G.point({x: 15, y: -100});
Pass an existing Point object.
G.point(pointObj: Point): Point
In this case the Point
object is simply returned.
Parameter | Type | Required | Description |
---|---|---|---|
pointObj | Point | Yes | A Point object. |
const point = G.point(pointObject);
PointValue type
The G.point()
function and other methods that accept the x/y point values accept a PointValue
as the x
value.
The PointValue
can be one of the following values:
- A number for the
x
value. In this case, they
value should also be set. For example:3
. - A string for the
x
value that is a number. In this case, they
value should also be set. For example:'3'
. - An array where the first value is the
x
value and the second value is they
value. For example:- Numbers:
[3, 10]
- Strings:
['3', '10']
- Mixed values:
[3, '10']
- Numbers:
- An object setting the
x
andy
values. For example:- Numbers:
{x: 3, y: 10}
- Strings:
{x: '3', y: '10'}
- Mixed:
{x: '3', y: 10}
- Numbers:
- A Point object.
Properties
Property | Type | Description |
---|---|---|
x | number | The x coordinate of the point |
y | number | The y coordinate of the point |
point.x = 30;
const x = point.x;
point.y = '45';
const y = point.y;
Methods
- Methods inherited from Base.
add
add(x: PointValue, y?: number): Point
Adds the x/y values to this point.
Parameter | Type | Required | Description |
---|---|---|---|
x | PointValue | Yes | The "x" value, array of x/y values, or an object containing the x/y value |
y | number | The "y" value. Only set if the "x" value is set as a number. |
point.add(2, 10);
point.add([2, 10]);
point.add({x: 2, y: 10});
point.add(anotherPointIbject);
const point2 = point.add(3, 2);
const point2 = point.add([3, 2]);
const point2 = point.add({x: 3, y: 2});
const point2 = point.add(anotherPointObject);
ceil
ceil(): Point
Rounds the x
and y
values up to the next integer.
point.ceil();
clone
clone(): Point
Clones the Point object and returns a new one.
const clone = point.clone();
distanceTo
distanceTo(value: PointValue): number
This returns the cartesian distance between the point and the given point.
Parameter | Type | Required | Description |
---|---|---|---|
value | PointValue | Yes | An array of x/y values, or an object containing the x/y value |
const distance = point.distanceTo(G.poing(56, 240));
divide
divide(num: number): Point
Divides the x/y values by a number.
Parameter | Type | Required | Description |
---|---|---|---|
num | number | Yes | The value to divide by. |
point.divide(3);
equals
equals(value: PointValue): boolean
Returns whether the current point is equal to the given point.
Parameter | Type | Required | Description |
---|---|---|---|
value | PointValue | Yes | An array of x/y values, or an object containing the x/y value |
if (point.equals(anotherPointObject)) {
// do something
}
floor
floor(): Point
Rounds the x/y values down to the nearest integer.
point.floor();
getX
getX(): number
Get the x value.
const x = point.getX();
getY
getY(): number
Get the y value.
const y = point.getY();
isValid
isValid(): boolean
Returns whether the x/y pair is a valid value.
if (point.isValid()) {
// Do something here
}
multiply
multiply(num: number): Point
Multiplies the x/y values by a number.
Parameter | Type | Required | Description |
---|---|---|---|
num | number | Yes | The value to multiply by. |
point.multiply(3);
round
round(): Point
Rounds the x/y values to the nearest integer.
point.round();
set
set(x: PointValue, y?: number): Point
Parameter | Type | Required | Description |
---|---|---|---|
x | PointValue | Yes | The "x" value, array of x/y values, or an object containing the x/y values |
y | number | The "y" value. Only set if the "x" value is set as a number. |
Set the x and y values. This accepts the values in the following ways:
point.set(x: number, y: number)
Parameter | Type | Required | Description |
---|---|---|---|
x | number | Yes | The "x" value. |
y | number | Yes | The "y" value. |
point.set(15, -100);
point.set([x: number, y: number])
Parameter | Type | Required | Description |
---|---|---|---|
value | Array | Yes | An array containing the x and y values |
point.set([15, -100]);
point.set({x: x: number, y: y: number})
Parameter | Type | Required | Description |
---|---|---|---|
value | object | Yes | An object containing the x and y values |
point.set({x: 15, y: -100});
point.set(pointObj: Point)
Parameter | Type | Required | Description |
---|---|---|---|
pointObj | Point | Yes | A Point object. In this case the x and y values from the object are used. |
point.set(pointObject);
setX
setX(x: number): Point
Set the x value. Use this if you want to change the x value after the object is created.
Parameter | Type | Required | Description |
---|---|---|---|
x | number | Yes | The "x" value". |
point.setX(15);
Or, you can use chain methods together to create the initial object.
const point = G.point().setX(15).setY(-100);
setY
setY(y: number): Point
Set the y value. Use this if you want to change the y value after the object is created.
Parameter | Type | Required | Description |
---|---|---|---|
y | number | Yes | The "y" value". |
point.setY(-100);
Or, you can use chain methods together to create the initial object.
const point = G.point().setX(15).setY(-100);
subtract
subtract(x: PointValue, y?: number): Point
Subtracts the x/y values from this point.
Parameter | Type | Required | Description |
---|---|---|---|
x | PointValue | Yes | The "x" value, array of x/y values, or an object containing the x/y value |
y | number | The "y" value. Only set if the "x" value is set as a number. |
const point2 = point.subtract(3, 2);
const point2 = point.subtract([3, 2]);
const point2 = point.subtract({x: 3, y: 2});
const point2 = point.subtract(anotherPointObject);
toGoogle
toGoogle(): google.maps.Point|null
Get the Google Maps Point object. null
is only returned if the Google maps library has not been loaded.
const gmPoint = point.toGoogle();
trunc
trunc(): Point
Change the x/y values to the integer part of a number by removing any fractional digits.
point.trunc();