Module: ol/coordinate

ol/coordinate


import * as olCoordinate from 'ol/coordinate';

Functions

add(coordinate, delta){Coordinate}

import {add} from 'ol/coordinate';

Add delta to coordinate. coordinate is modified in place and returned by the function.

Example:

import {add} from 'ol/coordinate.js';

const coord = [7.85, 47.983333];
add(coord, [-2, 4]);
// coord is now [5.85, 51.983333]
Name Type Description
coordinate Coordinate

Coordinate.

delta Coordinate

Delta.

Returns:
The input coordinate adjusted by the given delta.

createStringXY(fractionDigits){CoordinateFormat}

import {createStringXY} from 'ol/coordinate';

Returns a CoordinateFormat function that can be used to format a {Coordinate} to a string.

Example without specifying the fractional digits:

import {createStringXY} from 'ol/coordinate.js';

const coord = [7.85, 47.983333];
const stringifyFunc = createStringXY();
const out = stringifyFunc(coord);
// out is now '8, 48'

Example with explicitly specifying 2 fractional digits:

import {createStringXY} from 'ol/coordinate.js';

const coord = [7.85, 47.983333];
const stringifyFunc = createStringXY(2);
const out = stringifyFunc(coord);
// out is now '7.85, 47.98'
Name Type Description
fractionDigits number | undefined

The number of digits to include after the decimal point. Default is 0.

Returns:
Coordinate format.

format(coordinate, template, fractionDigits){string}

import {format} from 'ol/coordinate';

Transforms the given Coordinate to a string using the given string template. The strings {x} and {y} in the template will be replaced with the first and second coordinate values respectively.

Example without specifying the fractional digits:

import {format} from 'ol/coordinate.js';

const coord = [7.85, 47.983333];
const template = 'Coordinate is ({x}|{y}).';
const out = format(coord, template);
// out is now 'Coordinate is (8|48).'

Example explicitly specifying the fractional digits:

import {format} from 'ol/coordinate.js';

const coord = [7.85, 47.983333];
const template = 'Coordinate is ({x}|{y}).';
const out = format(coord, template, 2);
// out is now 'Coordinate is (7.85|47.98).'
Name Type Description
coordinate Coordinate

Coordinate.

template string

A template string with {x} and {y} placeholders that will be replaced by first and second coordinate values.

fractionDigits number | undefined

The number of digits to include after the decimal point. Default is 0.

Returns:
Formatted coordinate.

rotate(coordinate, angle){Coordinate}

import {rotate} from 'ol/coordinate';

Rotate coordinate by angle. coordinate is modified in place and returned by the function.

Example:

import {rotate} from 'ol/coordinate.js';

const coord = [7.85, 47.983333];
const rotateRadians = Math.PI / 2; // 90 degrees
rotate(coord, rotateRadians);
// coord is now [-47.983333, 7.85]
Name Type Description
coordinate Coordinate

Coordinate.

angle number

Angle in radian.

Returns:
Coordinate.

toStringHDMS(coordinate, fractionDigits){string}

import {toStringHDMS} from 'ol/coordinate';

Format a geographic coordinate with the hemisphere, degrees, minutes, and seconds.

Example without specifying fractional digits:

import {toStringHDMS} from 'ol/coordinate.js';

const coord = [7.85, 47.983333];
const out = toStringHDMS(coord);
// out is now '47° 58′ 60″ N 7° 50′ 60″ E'

Example explicitly specifying 1 fractional digit:

import {toStringHDMS} from 'ol/coordinate.js';

const coord = [7.85, 47.983333];
const out = toStringHDMS(coord, 1);
// out is now '47° 58′ 60.0″ N 7° 50′ 60.0″ E'
Name Type Description
coordinate Coordinate

Coordinate.

fractionDigits number | undefined

The number of digits to include after the decimal point. Default is 0.

Returns:
Hemisphere, degrees, minutes and seconds.

toStringXY(coordinate, fractionDigits){string}

import {toStringXY} from 'ol/coordinate';

Format a coordinate as a comma delimited string.

Example without specifying fractional digits:

import {toStringXY} from 'ol/coordinate.js';

const coord = [7.85, 47.983333];
const out = toStringXY(coord);
// out is now '8, 48'

Example explicitly specifying 1 fractional digit:

import {toStringXY} from 'ol/coordinate.js';

const coord = [7.85, 47.983333];
const out = toStringXY(coord, 1);
// out is now '7.8, 48.0'
Name Type Description
coordinate Coordinate

Coordinate.

fractionDigits number | undefined

The number of digits to include after the decimal point. Default is 0.

Returns:
XY.

Type Definitions

Coordinate{Array.<number>}

An array of numbers representing an xy, xyz or xyzm coordinate. Example: [16, 48].

CoordinateFormat()

A function that takes a Coordinate and transforms it into a {string}.