Summary
Methods:
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 |
返回一个与原坐标序列中坐标顺序相反的坐标序列,可根据传入的参数为true或false控制是否改变原坐标序列中坐标的顺序。 |
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
-
addCoord(coord, index) → {module:basetype~CoordSeq}
-
在当前坐标序列指定索引位置,添加一个新的坐标对象。
Parameters:
Name Type Description coord
module:basetype~Coordinate 坐标对象
index
Number 索引。当index小于等于0,往前添加;当index大于等于坐标序列的长度或者为空时,往后添加。
Example
let newCoord = new hmap.basetype.Coordinate(122,32,0); let result = coordSeq.addCoord(newCoord,0);//result为坐标序列长度
-
clone() → {module:basetype~CoordSeq}
-
克隆坐标序列实例
Example
let newCoordSeq = coordSeq.clone();
-
concat(coordSeq) → {module:basetype~CoordSeq}
-
合并两个坐标序列,指定的坐标序列追加到当前坐标序列之后。合并操作不影响原来的坐标序列。
Parameters:
Name Type Description coordSeq
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个时,抛出异常
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>}
-
从指定索引处开始提取n个坐标,如果n大于坐标数量,返回从索引位置开始的所有坐标。
Parameters:
Name Type Default Description index
Number 0 指定的索引
n
Number 要提取的坐标个数。1、当n为0时,返回null;2.n为负时,从索引位置处向前,依次提取坐标个数为n的绝对值。3.n为正时,从索引位置处向后,依次提取n个坐标。
Throws:
当第一个参数不是数值类型或者第二个参数不是数值类型时,抛出异常
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}
-
获取坐标序列中指定索引值对应的坐标。
Parameters:
Name Type Description index
Number 索引
Throws:
TypeError -当索引参数不是数值类型时,抛出类型异常
{RangeError} 当索引参数超出坐标序列中坐标数组的边界时,抛出越界异常Example
let result = coordSeq.getCoordinate(0);//result=new hmap.basetype.Coordinate(120,30,0)
-
getExtent() → {module:basetype~Extent}
-
计算该坐标序列的外接矩形地理范围。
-
getFirstCoordinate() → {module:basetype~Coordinate}
-
获取第一个坐标对象。
Example
let firstCoordinate = coordSeq.getFirstCoordinate();
-
getLastCoordinate() → {module:basetype~Coordinate}
-
获取最后一个坐标
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 coord1 = new hmap.basetype.Coordinate(120,30,0); let coordSeq = new hmap.basetype.CoordSeq([coord1]); let result = coordSeq.isRing();//result=false
-
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 coord1 = new hmap.basetype.Coordinate(120,30,0); let coord2 = new hmap.basetype.Coordinate(120,30,0); let coord3 = new hmap.basetype.Coordinate(122,32,0); let coordSeq = new hmap.basetype.CoordSeq([coord1,coord2,coord3]); let result = coordSeq.removeRepeat();//result=1
-
reverse(originModified) → {module:basetype~CoordSeq}
-
返回一个与原坐标序列中坐标顺序相反的坐标序列,可根据传入的参数为true或false控制是否改变原坐标序列中坐标的顺序。
Parameters:
Name Type Default Description originModified
Boolean false 指定原坐标序列中坐标的顺序是否被反转,默认值是false,表示不改变原坐标序列中坐标的顺序。该值为true时,会改变原坐标序列中坐标的顺序。
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这个坐标序列中坐标的顺序 coordSeq.reverse(true);//反转coordSeq这个坐标序列中坐标的顺序
-
setOrdinate(coordIndex, ordinateIndex, val)
-
设置坐标序列中指定索引坐标的指定分量的值。
Parameters:
Name Type Default Description coordIndex
Number 坐标在当前坐标序列中的索引,索引从0开始计算。
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,单位和地图单位一致。容差值越大,坐标序列越精简。
isRing
Boolean false 是否闭合,默认是false。
Throws:
当参数不是数值类型或者参数小于0时,抛出异常
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,32,0); let coordSeq = new hmap.basetype.CoordSeq([coord1,coord2,coord3]); let result = coordSeq.simplify(10); //result=new hmap.basetype.CoordSeq([ // new hmap.basetype.Coordinate(120,30,0), // new hmap.basetype.Coordinate(122,32,0) //]);
-
sort(axis, order) → {module:basetype~CoordSeq}
-
在坐标序列中,坐标分量按大小重新排列坐标次序。
Parameters:
Name Type Default Description axis
String X 坐标轴。字符串,仅限于"X"、"Y"、"Z"。
order
String ASC 升序(ASC)或降序(DESC)
Example
let newCoordSeq = coordSeq.sort("X", "ASC");//将坐标序列中的坐标,按照x坐标分量进行升序排列。
-
swap(i, j) → {module:basetype~CoordSeq}
-
交换指定索引位置的坐标。
Parameters:
Name Type Description i
Number 坐标在当前序列中的索引。
j
Number 坐标在当前序列中的索引。
Throws:
当第一个参数或者第二个参数超出坐标序列数组的索引范围时,抛出异常
Example
let coord1 = new hmap.basetype.Coordinate(120,30,0); let coord2 = new hmap.basetype.Coordinate(120,30,0); let coord3 = new hmap.basetype.Coordinate(122,32,0); let coordSeq = new hmap.basetype.CoordSeq([coord1,coord2,coord3]); let result = coordSeq.swap(1,2); //result=new hmap.basetype.CoordSeq([ // new hmap.basetype.Coordinate(120,30,0), // new hmap.basetype.Coordinate(122,32,0), // new hmap.basetype.Coordinate(120,30,0) //]);