Methods
-
import {add} from 'ol/coordinate';
Add
delta
tocoordinate
.coordinate
is modified in place and returned by the function.Example:
import {add} from 'ol/coordinate'; var coord = [7.85, 47.983333]; add(coord, [-2, 4]); // coord is now [5.85, 51.983333]
Name Type Description coordinate
module:ol/coordinate~Coordinate Coordinate.
delta
module:ol/coordinate~Coordinate Delta.
Returns:
The input coordinate adjusted by the given delta.
-
module:ol/coordinate.createStringXY(opt_fractionDigits){module:ol/coordinate~CoordinateFormat}
-
import {createStringXY} from 'ol/coordinate';
Returns a
module:ol/coordinate~CoordinateFormat
function that can be used to format a {Coordinate} to a string.Example without specifying the fractional digits:
import {createStringXY} from 'ol/coordinate'; var coord = [7.85, 47.983333]; var stringifyFunc = createStringXY(); var out = stringifyFunc(coord); // out is now '8, 48'
Example with explicitly specifying 2 fractional digits:
import {createStringXY} from 'ol/coordinate'; var coord = [7.85, 47.983333]; var stringifyFunc = createStringXY(2); var 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.
-
module:ol/coordinate.format(coordinate, template, opt_fractionDigits){string}
-
import {format} from 'ol/coordinate';
Transforms the given
module:ol/coordinate~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'; var coord = [7.85, 47.983333]; var template = 'Coordinate is ({x}|{y}).'; var out = format(coord, template); // out is now 'Coordinate is (8|48).'
Example explicitly specifying the fractional digits:
import {format} from 'ol/coordinate'; var coord = [7.85, 47.983333]; var template = 'Coordinate is ({x}|{y}).'; var out = format(coord, template, 2); // out is now 'Coordinate is (7.85|47.98).'
Name Type Description coordinate
module:ol/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.
-
module:ol/coordinate.rotate(coordinate, angle){module:ol/coordinate~Coordinate}
-
import {rotate} from 'ol/coordinate';
Rotate
coordinate
byangle
.coordinate
is modified in place and returned by the function.Example:
import {rotate} from 'ol/coordinate'; var coord = [7.85, 47.983333]; var rotateRadians = Math.PI / 2; // 90 degrees rotate(coord, rotateRadians); // coord is now [-47.983333, 7.85]
Name Type Description coordinate
module:ol/coordinate~Coordinate Coordinate.
angle
number Angle in radian.
Returns:
Coordinate.
-
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'; var coord = [7.85, 47.983333]; var 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'; var coord = [7.85, 47.983333]; var out = toStringHDMS(coord, 1); // out is now '47° 58′ 60.0″ N 7° 50′ 60.0″ E'
Name Type Description coordinate
module:ol/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.
-
import {toStringXY} from 'ol/coordinate';
Format a coordinate as a comma delimited string.
Example without specifying fractional digits:
import {toStringXY} from 'ol/coordinate'; var coord = [7.85, 47.983333]; var out = toStringXY(coord); // out is now '8, 48'
Example explicitly specifying 1 fractional digit:
import {toStringXY} from 'ol/coordinate'; var coord = [7.85, 47.983333]; var out = toStringXY(coord, 1); // out is now '7.8, 48.0'
Name Type Description coordinate
module:ol/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 coordinate. Example:
[16, 48]
. -
A function that takes a
module:ol/coordinate~Coordinate
and transforms it into a{string}
.