basetype~CoordSeq(coordArr)

坐标序列,用来管理一串坐标module:basetype~Coordinate对象。

Summary

Methods:
fromArray

根据二维数据生成坐标序列对象

addCoord

在当前坐标序列的指定索引位置,插入一个新的坐标对象。

clone

克隆坐标序列实例

concat

合并两个坐标序列,指定的坐标序列追加到当前坐标序列之后。合并操作不影响原来的坐标序列。

containsCoord

判断指定的坐标对象在坐标序列中的索引位置。

destroy

销毁对象

encloseRing

使坐标序列成为一个闭环。1.坐标序列中的点数量需大于等于3,否则抛异常;2.如果当前坐标序列已经是一个闭环,那么直接返回;3.如果当前坐标序列不是闭环,追加序列中的第一个点到末尾,使其成为闭环。

equals

检测两个坐标序列是否相等。

extractCoords

从指定索引处开始提取n个坐标,如果n大于坐标数量,返回从索引位置开始的所有坐标。

getCoordCount

获取坐标序列长度,即当前坐标序列中所包含的坐标个数。

getCoordinate

获取坐标序列中指定索引位置对应的坐标。

getExtent

计算该坐标序列的外包矩形的地理范围。

getFirstCoordinate

获取坐标序列中的第一个坐标对象。

getLastCoordinate

获取坐标序列中的最后一个坐标对象。

getOrdinate

获取指定索引处的坐标的某个分量值。

isRing

判断坐标序列是否闭合。闭合的依据是首尾坐标相等,且当前坐标序列中至少包含3个坐标。

remove

从坐标序列指定索引处删除指定个数的坐标。

removeRepeat

去除重复的坐标。假如坐标序列中相邻的两个坐标是相同的,则会删除后面的坐标,直到相邻的坐标没有相同的为止。

reverse

返回一个与原坐标序列中坐标顺序相反的新坐标序列,可根据传入的参数控制是否改变原坐标序列中的坐标顺序。

setOrdinate

设置指定索引处的坐标的某个分量值。

simplify

简化坐标序列。采用道格拉斯-普克算法,坐标序列中应至少包含三个坐标,若坐标个数小于3,则不做任何处理。

sort

根据某个坐标分量的大小,对坐标序列进行排序,并返回排序后的新坐标序列。注意:排序操作不影响原来的坐标序列。

swap

交换指定索引位置的坐标。此操作会改变原来的坐标序列。

Constructor

new CoordSeq(coordArr)

Parameters:
Name Type Description
coordArr Array.<module:basetype~Coordinate>

存放坐标对象的数组

Throws:

当参数不是数组类型或者数组元素不是地理坐标对象时,抛出异常

Example
let coord1 = new hmap.basetype.Coordinate(120, 30, 0);
let coord2 = new hmap.basetype.Coordinate(121, 31, 0);
let coordSeq = new hmap.basetype.CoordSeq([coord1, coord2]);

Methods

static fromArray(coords)

根据二维数据生成坐标序列对象

Parameters:
Name Type Description
coords *
Returns:
-

坐标序列对象

addCoord(coord, index) → {module:basetype~CoordSeq}

在当前坐标序列的指定索引位置,插入一个新的坐标对象。

Parameters:
Name Type Description
coord module:basetype~Coordinate

要插入的坐标对象。

index Number

索引。当index小于等于0,往前添加;当index大于等于坐标序列的长度或者为空时,往后添加。默认值为坐标序列的长度。

Returns:
module:basetype~CoordSeq -

返回修改后的坐标序列。

Example
let newCoord = new hmap.basetype.Coordinate(122, 32, 0);
let result = coordSeq.addCoord(newCoord, 0);

clone() → {module:basetype~CoordSeq}

克隆坐标序列实例

Returns:
module:basetype~CoordSeq -

返回复制的坐标序列

Example
let newCoordSeq = coordSeq.clone();

concat(coordSeq) → {module:basetype~CoordSeq}

合并两个坐标序列,指定的坐标序列追加到当前坐标序列之后。合并操作不影响原来的坐标序列。

Parameters:
Name Type Description
coordSeq module:basetype~CoordSeq

坐标序列

Returns:
module:basetype~CoordSeq -

新的坐标序列

containsCoord(coord) → {Number}

判断指定的坐标对象在坐标序列中的索引位置。

Parameters:
Name Type Description
coord module:basetype~Coordinate

坐标对象

Throws:

当参数不是坐标对象时,抛出异常

Returns:
Number -

若序列中包含指定坐标,则返回其在序列中的索引,否则返回-1。

Example
let coord = new hmap.basetype.Coordinate(120,30,0);
let flag = coordSeq.containsCoord(coord);

destroy()

销毁对象

Example
coordSeq.destroy();

encloseRing() → {Array.<module:basetype~Coordinate>}

使坐标序列成为一个闭环。1.坐标序列中的点数量需大于等于3,否则抛异常;2.如果当前坐标序列已经是一个闭环,那么直接返回;3.如果当前坐标序列不是闭环,追加序列中的第一个点到末尾,使其成为闭环。

Throws:

当组成坐标序列的点数量少于3个时,抛出异常

Returns:
Array.<module:basetype~Coordinate> -

新坐标数组

Example
let coord1 = new hmap.basetype.Coordinate(120,30,0);
let coord2 = new hmap.basetype.Coordinate(121,31,0);
let coord3 = new hmap.basetype.Coordinate(122,30,0);
let coordSeq = new hmap.basetype.CoordSeq([coord1,coord2,coord3]);
let result = coordSeq.encloseRing();

equals(coordSeq) → {Boolean}

检测两个坐标序列是否相等。

Parameters:
Name Type Description
coordSeq module:basetype~CoordSeq

另一个坐标序列对象。

Returns:
Boolean -

相等返回true,不相等返回false。

Example
let coord = new hmap.basetype.Coordinate(120,30,0);
let coordSeq1 = new hmap.basetype.CoordSeq([coord]);
let coordSeq2 = new hmap.basetype.CoordSeq([coord]);
let result = coordSeq1.equals(coordSeq2);//result=true

extractCoords(index, n) → {Array.<module:basetype~Coordinate>|null}

从指定索引处开始提取n个坐标,如果n大于坐标数量,返回从索引位置开始的所有坐标。

Parameters:
Name Type Default Description
index Number 0

指定的索引,默认值为0。

n Number

要提取的坐标个数,默认值为坐标序列的长度。1.当n为0时,返回null;2.n为负时,从索引位置处向前,依次提取n个坐标;3.n为正时,从索引位置处向后,依次提取n个坐标。

Throws:

当第一个参数不是数值类型或者第二个参数不是数值类型时,抛出异常

Returns:
Array.<module:basetype~Coordinate> | null -

提取的坐标序列的数组。当提取的坐标个数为0时,返回null。

Example
let result = coordSeq.extractCoords(0,1);
//result=[new hmap.basetype.Coordinate(120,30,0)];

getCoordCount() → {Number}

获取坐标序列长度,即当前坐标序列中所包含的坐标个数。

Returns:
Number -

坐标序列的长度。

Example
let coordCount = coordSeq.getCoordCount();

getCoordinate(index) → {module:basetype~Coordinate|null}

获取坐标序列中指定索引位置对应的坐标。

Parameters:
Name Type Description
index Number

指定的索引。

Throws:
TypeError -

当索引参数不是数值类型时,抛出类型异常
{RangeError} 当索引参数超出坐标序列中坐标数组的边界时,抛出越界异常

Returns:
module:basetype~Coordinate | null -

获取到的坐标。如果坐标序列中没有坐标,则返回null。

Example
let result = coordSeq.getCoordinate(0);//result=new hmap.basetype.Coordinate(120,30,0)

getExtent() → {module:basetype~Extent}

计算该坐标序列的外包矩形的地理范围。

Returns:
module:basetype~Extent -

该坐标序列的外包矩形的地理范围。

getFirstCoordinate() → {module:basetype~Coordinate}

获取坐标序列中的第一个坐标对象。

Returns:
module:basetype~Coordinate -

坐标序列中的第一个坐标对象。如果该坐标序列中没有坐标,则返回null。

Example
let firstCoordinate = coordSeq.getFirstCoordinate();

getLastCoordinate() → {module:basetype~Coordinate}

获取坐标序列中的最后一个坐标对象。

Returns:
module:basetype~Coordinate -

坐标序列中的最后一个坐标对象。如果该坐标序列中没有坐标,则返回null。

Example
let lastCoordinate = coordSeq.getLastCoordinate();

getOrdinate(coordIndex, ordinateIndex) → {Number}

获取指定索引处的坐标的某个分量值。

Parameters:
Name Type Default Description
coordIndex Number

坐标在序列中的索引。

ordinateIndex String X

坐标轴标识。取值必须为"X"、"Y"、或"Z",缺省值"X"。

Throws:

当第一个参数不是数值类型时抛出异常;当第二个参数不是"X"或"Y"或"Z"时,抛出异常。

Returns:
Number -

坐标分量值。

Example
let xValue = coordSeq.getOrdinate(0, "X");

isRing() → {Boolean}

判断坐标序列是否闭合。闭合的依据是首尾坐标相等,且当前坐标序列中至少包含3个坐标。

Returns:
Boolean -

闭合返回true,不闭合返回false。

Example
let result = coordSeq.isRing();

remove(index, num) → {Number}

从坐标序列指定索引处删除指定个数的坐标。

Parameters:
Name Type Description
index Number

要删除的起始位置处的索引

num Number

要删除的坐标个数

Throws:

当参数index不在坐标序列数组的索引值范围内时,抛出异常

Returns:
Number -

返回删除坐标的个数

Example
coordSeq.remove(0, 1);//只删除了索引值为0的一个坐标

removeRepeat() → {Number}

去除重复的坐标。假如坐标序列中相邻的两个坐标是相同的,则会删除后面的坐标,直到相邻的坐标没有相同的为止。

Returns:
Number -

返回删除坐标的个数。

Example
let result = coordSeq.removeRepeat();

reverse(originModified) → {module:basetype~CoordSeq}

返回一个与原坐标序列中坐标顺序相反的新坐标序列,可根据传入的参数控制是否改变原坐标序列中的坐标顺序。

Parameters:
Name Type Default Description
originModified Boolean false

原坐标序列中的坐标顺序是否被反转。默认值是false,表示不改变原坐标序列中的坐标顺序;该值为true时,会改变原坐标序列中的坐标顺序。

Returns:
module:basetype~CoordSeq -

反转后的新坐标序列

Example
const coord1 = new hmap.basetype.Coordinate(120,30,0);
const coord2 = new hmap.basetype.Coordinate(120,30,0);
const coord3 = new hmap.basetype.Coordinate(122,32,0);
let coordSeq = new hmap.basetype.CoordSeq([coord1,coord2,coord3]);
let result = coordSeq.reverse();//不改变coordSeq这个坐标序列中坐标的顺序
let result1 = coordSeq.reverse(true);//coordSeq这个坐标序列中坐标的顺序也被反转

setOrdinate(coordIndex, ordinateIndex, val)

设置指定索引处的坐标的某个分量值。

Parameters:
Name Type Default Description
coordIndex Number

坐标在序列中的索引。

ordinateIndex String X

坐标轴标识。取值必须为"X"、"Y"、或"Z",缺省值"X"。

val Number

坐标分量。

Throws:

当第一个和第三个参数不是数值类型时抛出异常;当第二个参数不是"X"或"Y"或"Z"时,抛出异常。

Example
coordSeq.setOrdinate(0, "X", 124);//设置坐标序列中第一个坐标的x轴值为124.

simplify(tolerance, isRing) → {module:basetype~CoordSeq}

简化坐标序列。采用道格拉斯-普克算法,坐标序列中应至少包含三个坐标,若坐标个数小于3,则不做任何处理。

Parameters:
Name Type Default Description
tolerance Number 0.00001

简化所用容差值,大于等于0,单位和地图单位一致,可以通过地图对象上的getDegreePerMeter和getMeterPerDegree方法,对地图单位进行度和米的转换。容差值越大,坐标序列越精简。默认值0.00001。

isRing Boolean false

是否闭合,默认是false。

Throws:

当参数不是数值类型或者参数小于0时,抛出异常

Returns:
module:basetype~CoordSeq -

返回简化后的坐标序列。

Example
let result = coordSeq.simplify(10);

sort(axis, order) → {module:basetype~CoordSeq}

根据某个坐标分量的大小,对坐标序列进行排序,并返回排序后的新坐标序列。注意:排序操作不影响原来的坐标序列。

Parameters:
Name Type Default Description
axis String X

坐标轴标识。取值必须为"X"、"Y"、或"Z"。缺省值"X"。

order String ASC

排序方式。升序:"ASC",降序:"DESC"。缺省值"ASC"。

Returns:
module:basetype~CoordSeq -

经过排序的新坐标序列。

Example
let newCoordSeq = coordSeq.sort("X", "ASC");//将坐标序列中的坐标,按照x坐标分量进行升序排列。

swap(i, j) → {module:basetype~CoordSeq}

交换指定索引位置的坐标。此操作会改变原来的坐标序列。

Parameters:
Name Type Description
i Number

坐标在当前序列中的索引。

j Number

坐标在当前序列中的索引。

Throws:

当第一个参数或者第二个参数超出坐标序列数组的索引范围时,抛出异常

Returns:
module:basetype~CoordSeq -

交换坐标后的坐标序列

Example
let result = coordSeq.swap(1,2);