Module: ol/coordinate

ol/coordinate


import * as olCoordinate from 'ol/coordinate';

函数s

add(coordinate, delta){Coordinate}

import {add} from 'ol/coordinate';

delta 加到 coordinate 上。coordinate 被原地修改并由函数返回。

示例:

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

坐标。

delta Coordinate

增量。

返回值:
由给定增量调整后的输入坐标。

createStringXY(fractionDigits){CoordinateFormat}

import {createStringXY} from 'ol/coordinate';

返回一个 CoordinateFormat 函数,可用于将 {Coordinate} 格式化为字符串。

不指定小数位数的示例:

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

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

显式指定 2 位小数的示例:

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

小数点后包含的位数。默认为 0

返回值:
坐标格式。

format(coordinate, template, fractionDigits){string}

import {format} from 'ol/coordinate';

使用给定的字符串模板将 Coordinate 转换为字符串。 模板中的 {x}{y} 字符串将分别替换为第一个和第二个坐标值。

不指定小数位数的示例:

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).'

显式指定小数位数的示例:

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

坐标。

template string

带有 {x}{y} 占位符的模板字符串, 将分别替换为第一个和第二个坐标值。

fractionDigits number | undefined

小数点后包含的位数。默认为 0

返回值:
格式化后的坐标。

rotate(coordinate, angle){Coordinate}

import {rotate} from 'ol/coordinate';

angle 旋转 coordinatecoordinate 被原地修改并由函数返回。

示例:

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

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

坐标。

angle number

旋转角度(弧度)。

返回值:
坐标。

toStringHDMS(coordinate, fractionDigits){string}

import {toStringHDMS} from 'ol/coordinate';

格式化地理坐标,包含半球、度、分和秒。

不指定小数位数的示例:

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'

显式指定 1 位小数的示例:

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

坐标。

fractionDigits number | undefined

小数点后包含的位数。默认为 0

返回值:
半球、度、分和秒。

toStringXY(coordinate, fractionDigits){string}

import {toStringXY} from 'ol/coordinate';

将坐标格式化为逗号分隔的字符串。

不指定小数位数的示例:

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

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

显式指定 1 位小数的示例:

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

坐标。

fractionDigits number | undefined

小数点后包含的位数。默认为 0

返回值:
XY 字符串。

Type Definitions

Coordinate{Array.<number>}

表示 xyxyzxyzm 坐标的数字数组。 示例:[16, 48]

CoordinateFormat()

接受 Coordinate 并将其转换为 {string} 的函数。