Point 点
代表一个点,其 x 和 y 坐标为像素。
使用示例
var point = hnsdk.point(200, 300);
所有接受 Point 对象的Leaflet方法和选项也接受它们的简单数组形式(除非另有说明),所以这些行是等价的:
map.panBy([200, 300]);
map.panBy(hnsdk.point(200, 300));
注意, Point 不继承 hnsdk 的 Class 对象,这意味着新的类不能继承于它,新的方法也不能用 include 函数添加到它。
Creation
| 构造函数 | 说明 |
|---|---|
hnsdk.point( x, y, round?) | 用给定的 x 和 y 坐标创建一个点对象。如果可选的 round 被设置为true,则对 x 和 y 值进行舍入。 |
hnsdk.point(coords) | 期待一个形式为 [x, y] 的数组来代替。 |
hnsdk.point( coords) | 期待一个形式为 {x: Number, y: Number} 的普通对象来代替。 |
Methods 方法
| 方法名 | 返回值 | 说明 |
|---|---|---|
clone() | Point | 返回当前点的拷贝。 |
add(otherPoint) | Point | 返回当前点和给定点的相加结果。 |
subtract(otherPoint) | Point | 返回给定点与当前点相减的结果。 |
divideBy( num) | Point | 返回当前点除以给定数字的结果。 |
multiplyBy( num) | Point | 返回当前点与给定数字相乘的结果。 |
scaleBy(scale) | Point | 将当前点的每个坐标与 |
unscaleBy(scale) | Point |
|
round() | Point | 返回具有圆角坐标的当前点的拷贝。 |
floor() | Point | 返回具有浮动坐标的当前点的拷贝(向下舍入)。 |
ceil() | Point | 返回当前点的拷贝,坐标为最高值(四舍五入)。 |
trunc() | Point | 返回具有截断坐标的当前点的拷贝(四舍五入为零)。 |
distanceTo(otherPoint) | Number | 返回当前点和给定点之间的笛卡尔距离。 |
equals(otherPoint) | Boolean | 如果给定的点具有相同的坐标,则返回 |
contains(otherPoint) | Boolean | 如果给定点的两个坐标都小于相应的当前点坐标(绝对值),则返回 |
toString() | String | 返回点的字符串表示,用于调试目的。 |
Properties 属性
| 属性 | 类型 | 说明 |
|---|---|---|
x | Number | 点的 x 坐标 |
y | Number | 点的 y 坐标 |
