Edit

Share via


MercatorPoint class

A MercatorPoint object represents a projected three dimensional position. MercatorPoint uses the web mercator projection (EPSG:3857) with slightly different units:

  • the size of 1 unit is the width of the projected world instead of the "mercator meter"
  • the origin of the coordinate space is at the north-west corner instead of the middle.

For example, MercatorPoint(0, 0, 0) is the north-west corner of the mercator world and MercatorPoint(1, 1, 0) is the south-east corner. If you are familiar with vector tiles it may be helpful to think of the coordinate space as the 0/0/0 tile with an extent of 1.

The z dimension of MercatorPoint is conformal. A cube in the mercator coordinate space would be rendered as a cube.

Extends

Array<number>

Constructors

MercatorPoint(number, number, number)

Constructs a MercatorPoint.

Properties

Array

Inherited Properties

length

Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.

Methods

fromPosition(Position)

Converts a position into a mercator point.

fromPositions(Position[])

Converts an array of positions into an array of mercator points.

mercatorScale(number)

Determine the Mercator scale factor for a given latitude, see https://en.wikipedia.org/wiki/Mercator_projection#Scale_factor At the equator the scale factor will be 1, which increases at higher latitudes.

meterInMercatorUnits(number)

Returns the distance of 1 meter in MercatorPoint units at this latitude. For coordinates in real world units using meters, this naturally provides the scale to transform into MercatorPoints.

toFloat32Array(Position[])

Converts an array of positions into a Float32Array of mercator xyz values.

toPosition(MercatorPoint)

Converts a mercator point into a map position.

toPositions(MercatorPoint[])

Converts an array of mercator points into an array of map positions.

Inherited Methods

concat((T | ConcatArray<T>)[])

Combines two or more arrays.

concat(ConcatArray<number>[])

Combines two or more arrays.

every((value: number, index: number, array: number[]) => unknown, any)

Determines whether all the members of an array satisfy the specified test.

filter((value: number, index: number, array: number[]) => unknown, any)

Returns the elements of an array that meet the condition specified in a callback function.

filter<S>((value: number, index: number, array: number[]) => value, any)

Returns the elements of an array that meet the condition specified in a callback function.

forEach((value: number, index: number, array: number[]) => void, any)

Performs the specified action for each element in an array.

indexOf(number, number)

Returns the index of the first occurrence of a value in an array.

join(string)

Adds all the elements of an array separated by the specified separator string.

lastIndexOf(number, number)

Returns the index of the last occurrence of a specified value in an array.

map<U>((value: number, index: number, array: number[]) => U, any)

Calls a defined callback function on each element of an array, and returns an array that contains the results.

pop()

Removes the last element from an array and returns it.

push(number[])

Appends new elements to an array, and returns the new length of the array.

reduce((previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number)

Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

reduce((previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, number)
reduce<U>((previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, U)

Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

reduceRight((previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number)

Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

reduceRight((previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, number)
reduceRight<U>((previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, U)

Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

reverse()

Reverses the elements in an Array.

shift()

Removes the first element from an array and returns it.

slice(number, number)

Returns a section of an array.

some((value: number, index: number, array: number[]) => unknown, any)

Determines whether the specified callback function returns true for any element of an array.

sort((a: number, b: number) => number)

Sorts an array.

splice(number, number)

Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.

splice(number, number, number[])

Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.

toLocaleString()

Returns a string representation of an array. The elements are converted to string using their toLocalString methods.

toString()

Returns a string representation of an array.

unshift(number[])

Inserts new elements at the start of an array.

Constructor Details

MercatorPoint(number, number, number)

Constructs a MercatorPoint.

new MercatorPoint(x: number, y: number, z?: number)

Parameters

x

number

A points x position in mercator units.

y

number

A points y position in mercator units.

z

number

A points z position in mercator units.

Property Details

Array

static Array: ArrayConstructor

Property Value

ArrayConstructor

Inherited Property Details

length

Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.

length: number

Property Value

number

Inherited From Array.length

Method Details

fromPosition(Position)

Converts a position into a mercator point.

static function fromPosition(position: Position): MercatorPoint

Parameters

position
Position

Position to convert.

Returns

A mercator point.

fromPositions(Position[])

Converts an array of positions into an array of mercator points.

static function fromPositions(positions: Position[]): MercatorPoint[]

Parameters

positions

Position[]

Array of positions to convert.

Returns

An array of mercator points.

mercatorScale(number)

Determine the Mercator scale factor for a given latitude, see https://en.wikipedia.org/wiki/Mercator_projection#Scale_factor At the equator the scale factor will be 1, which increases at higher latitudes.

static function mercatorScale(latitude: number): number

Parameters

latitude

number

Latitude

Returns

number

The mercator scale factor.

meterInMercatorUnits(number)

Returns the distance of 1 meter in MercatorPoint units at this latitude. For coordinates in real world units using meters, this naturally provides the scale to transform into MercatorPoints.

static function meterInMercatorUnits(latitude: number): number

Parameters

latitude

number

Returns

number

Distance of 1 meter in MercatorPoint units.

toFloat32Array(Position[])

Converts an array of positions into a Float32Array of mercator xyz values.

static function toFloat32Array(positions: Position[]): Float32Array

Parameters

positions

Position[]

Array of positions to convert.

Returns

Float32Array

A Float32Array of mercator xyz values.

toPosition(MercatorPoint)

Converts a mercator point into a map position.

static function toPosition(mercator: MercatorPoint): Position

Parameters

mercator
MercatorPoint

Mercator point to convert.

Returns

A map position.

toPositions(MercatorPoint[])

Converts an array of mercator points into an array of map positions.

static function toPositions(mercators: MercatorPoint[]): Position[]

Parameters

mercators

MercatorPoint[]

Mercator points to convert.

Returns

An array of map positions.

Inherited Method Details

concat((T | ConcatArray<T>)[])

Combines two or more arrays.

function concat(items: (T | ConcatArray<T>)[]): number[]

Parameters

items

(T | ConcatArray<T>)[]

Additional items to add to the end of array1.

Returns

number[]

Inherited From Array.concat

concat(ConcatArray<number>[])

Combines two or more arrays.

function concat(items: ConcatArray<number>[]): number[]

Parameters

items

ConcatArray<number>[]

Additional items to add to the end of array1.

Returns

number[]

Inherited From Array.concat

every((value: number, index: number, array: number[]) => unknown, any)

Determines whether all the members of an array satisfy the specified test.

function every(callbackfn: (value: number, index: number, array: number[]) => unknown, thisArg?: any): boolean

Parameters

callbackfn

(value: number, index: number, array: number[]) => unknown

A function that accepts up to three arguments. The every method calls the callbackfn function for each element in the array until the callbackfn returns a value which is coercible to the Boolean value false, or until the end of the array.

thisArg

any

An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

Returns

boolean

Inherited From Array.every

filter((value: number, index: number, array: number[]) => unknown, any)

Returns the elements of an array that meet the condition specified in a callback function.

function filter(callbackfn: (value: number, index: number, array: number[]) => unknown, thisArg?: any): number[]

Parameters

callbackfn

(value: number, index: number, array: number[]) => unknown

A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.

thisArg

any

An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

Returns

number[]

Inherited From Array.filter

filter<S>((value: number, index: number, array: number[]) => value, any)

Returns the elements of an array that meet the condition specified in a callback function.

function filter<S>(callbackfn: (value: number, index: number, array: number[]) => value, thisArg?: any): S[]

Parameters

callbackfn

(value: number, index: number, array: number[]) => value

A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.

thisArg

any

An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

Returns

S[]

Inherited From Array.filter

forEach((value: number, index: number, array: number[]) => void, any)

Performs the specified action for each element in an array.

function forEach(callbackfn: (value: number, index: number, array: number[]) => void, thisArg?: any)

Parameters

callbackfn

(value: number, index: number, array: number[]) => void

A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.

thisArg

any

An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

Inherited From Array.forEach

indexOf(number, number)

Returns the index of the first occurrence of a value in an array.

function indexOf(searchElement: number, fromIndex?: number): number

Parameters

searchElement

number

The value to locate in the array.

fromIndex

number

The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.

Returns

number

Inherited From Array.indexOf

join(string)

Adds all the elements of an array separated by the specified separator string.

function join(separator?: string): string

Parameters

separator

string

A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.

Returns

string

Inherited From Array.join

lastIndexOf(number, number)

Returns the index of the last occurrence of a specified value in an array.

function lastIndexOf(searchElement: number, fromIndex?: number): number

Parameters

searchElement

number

The value to locate in the array.

fromIndex

number

The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.

Returns

number

Inherited From Array.lastIndexOf

map<U>((value: number, index: number, array: number[]) => U, any)

Calls a defined callback function on each element of an array, and returns an array that contains the results.

function map<U>(callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any): U[]

Parameters

callbackfn

(value: number, index: number, array: number[]) => U

A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

thisArg

any

An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

Returns

U[]

Inherited From Array.map

pop()

Removes the last element from an array and returns it.

function pop(): number | undefined

Returns

number | undefined

Inherited From Array.pop

push(number[])

Appends new elements to an array, and returns the new length of the array.

function push(items: number[]): number

Parameters

items

number[]

New elements of the Array.

Returns

number

Inherited From Array.push

reduce((previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number)

Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

function reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number

Parameters

callbackfn

(previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number

A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.

Returns

number

Inherited From Array.reduce

reduce((previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, number)

function reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number

Parameters

callbackfn

(previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number

initialValue

number

Returns

number

Inherited From Array.reduce

reduce<U>((previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, U)

Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

function reduce<U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U

Parameters

callbackfn

(previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U

A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.

initialValue

U

If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

Returns

U

Inherited From Array.reduce

reduceRight((previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number)

Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

function reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number

Parameters

callbackfn

(previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number

A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.

Returns

number

Inherited From Array.reduceRight

reduceRight((previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, number)

function reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number

Parameters

callbackfn

(previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number

initialValue

number

Returns

number

Inherited From Array.reduceRight

reduceRight<U>((previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, U)

Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

function reduceRight<U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U

Parameters

callbackfn

(previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U

A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.

initialValue

U

If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

Returns

U

Inherited From Array.reduceRight

reverse()

Reverses the elements in an Array.

function reverse(): number[]

Returns

number[]

Inherited From Array.reverse

shift()

Removes the first element from an array and returns it.

function shift(): number | undefined

Returns

number | undefined

Inherited From Array.shift

slice(number, number)

Returns a section of an array.

function slice(start?: number, end?: number): number[]

Parameters

start

number

The beginning of the specified portion of the array.

end

number

The end of the specified portion of the array. This is exclusive of the element at the index 'end'.

Returns

number[]

Inherited From Array.slice

some((value: number, index: number, array: number[]) => unknown, any)

Determines whether the specified callback function returns true for any element of an array.

function some(callbackfn: (value: number, index: number, array: number[]) => unknown, thisArg?: any): boolean

Parameters

callbackfn

(value: number, index: number, array: number[]) => unknown

A function that accepts up to three arguments. The some method calls the callbackfn function for each element in the array until the callbackfn returns a value which is coercible to the Boolean value true, or until the end of the array.

thisArg

any

An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

Returns

boolean

Inherited From Array.some

sort((a: number, b: number) => number)

Sorts an array.

function sort(compareFn?: (a: number, b: number) => number): this

Parameters

compareFn

(a: number, b: number) => number

Function used to determine the order of the elements. It is expected to return a negative value if first argument is less than second argument, zero if they're equal and a positive value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.

[11,2,22,1].sort((a, b) => a - b)

Returns

this

Inherited From Array.sort

splice(number, number)

Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.

function splice(start: number, deleteCount?: number): number[]

Parameters

start

number

The zero-based location in the array from which to start removing elements.

deleteCount

number

The number of elements to remove.

Returns

number[]

Inherited From Array.splice

splice(number, number, number[])

Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.

function splice(start: number, deleteCount: number, items: number[]): number[]

Parameters

start

number

The zero-based location in the array from which to start removing elements.

deleteCount

number

The number of elements to remove.

items

number[]

Elements to insert into the array in place of the deleted elements.

Returns

number[]

Inherited From Array.splice

toLocaleString()

Returns a string representation of an array. The elements are converted to string using their toLocalString methods.

function toLocaleString(): string

Returns

string

Inherited From Array.toLocaleString

toString()

Returns a string representation of an array.

function toString(): string

Returns

string

Inherited From Array.toString

unshift(number[])

Inserts new elements at the start of an array.

function unshift(items: number[]): number

Parameters

items

number[]

Elements to insert at the start of the Array.

Returns

number

Inherited From Array.unshift