forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.js
More file actions
142 lines (123 loc) · 4.44 KB
/
Copy pathPoint.js
File metadata and controls
142 lines (123 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
* This program are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
import {SuperMap} from '../../SuperMap';
import {Geometry} from '../Geometry';
import {Bounds} from '../Bounds';
import {Util} from '../Util';
/**
* @class SuperMap.Geometry.Point
* @classdesc 点几何对象类。
* @category BaseTypes Geometry
* @extends {SuperMap.Geometry}
* @param {float} x - x 坐标。
* @param {float} y - y 坐标。
* @param {string} [type = 'Point'] - 用来存储点的类型。
* @param {float} [tag] - 用来存储额外的属性,比如差值分析中的 Z 值。
* @example
* var point = new SuperMap.Geometry.Point(-111.04, 45.68);
*/
export class Point extends Geometry {
constructor(x, y, type, tag) {
super(x, y, type, tag);
/**
* @member {float} SuperMap.Geometry.Point.prototype.x
* @description 横坐标。
*/
this.x = parseFloat(x);
/**
* @member {float} SuperMap.Geometry.Point.prototype.y
* @description 纵坐标。
*/
this.y = parseFloat(y);
/**
* @member {string} SuperMap.Geometry.Point.prototype.tag
* @description 用来存储额外的属性,比如差值分析中的 Z 值。
*/
this.tag = (tag || tag == 0) ? parseFloat(tag) : null;
/**
* @member {string} SuperMap.Geometry.Point.prototype.tag
* @description 用来存储点的类型
*/
this.type = type || "Point";
this.CLASS_NAME = "SuperMap.Geometry.Point";
this.geometryType = "Point";
}
/**
* @function SuperMap.Geometry.Point.prototype.clone
* @description 克隆点对象。
* @returns {SuperMap.Geometry.Point} 克隆后的点对象。
*/
clone(obj) {
if (obj == null) {
obj = new Point(this.x, this.y);
}
// catch any randomly tagged-on properties
Util.applyDefaults(obj, this);
return obj;
}
/**
* @function SuperMap.Geometry.Point.prototype.calculateBounds
* @description 计算点对象的范围。
*/
calculateBounds() {
this.bounds = new Bounds(this.x, this.y,
this.x, this.y);
}
/**
* @function SuperMap.Geometry.Point.prototype.equals
* @description 判断两个点对象是否相等。如果两个点对象具有相同的坐标,则认为是相等的。
* @example
* var point= new SuperMap.Geometry.Point(0,0);
* var point1={x:0,y:0};
* var result= point.equals(point1);
* @param {SuperMap.Geometry.Point} geom - 需要判断的点对象。
* @returns {boolean} 两个点对象是否相等(true 为相等,false 为不等)。
*/
equals(geom) {
var equals = false;
if (geom != null) {
equals = ((this.x === geom.x && this.y === geom.y) ||
(isNaN(this.x) && isNaN(this.y) && isNaN(geom.x) && isNaN(geom.y)));
}
return equals;
}
/**
* @function SuperMap.Geometry.Point.prototype.move
* @description 沿着 x、y 轴的正方向上按照给定的位移移动点对象,move 不仅改变了几何对象的位置并且清理了边界缓存。
* @param {float} x - x 轴正方向上的偏移量。
* @param {float} y - y 轴正方向上偏移量。
*/
move(x, y) {
this.x = this.x + x;
this.y = this.y + y;
this.clearBounds();
}
/**
* @function SuperMap.Geometry.Point.prototype.toShortString
* @returns {string} 字符串代表点对象。(ex. <i>"5, 42"</i>)
*/
toShortString() {
return (this.x + ", " + this.y);
}
/**
* @function SuperMap.Geometry.Point.prototype.destroy
* @description 释放点对象的资源。
*/
destroy() {
this.x = null;
this.y = null;
this.tag = null;
super.destroy();
}
/**
* @function SuperMap.Geometry.Point.prototype.getVertices
* @description 返回点对象的所有顶点的列表。
* @param {boolean} [nodes] - 对于点对象此参数不起作用,直接返回点。
* @returns {Array} 几何图形的顶点列表。
*/
getVertices(nodes) { // eslint-disable-line no-unused-vars
return [this];
}
}
SuperMap.Geometry.Point = Point;