forked from MapGIS/WebClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.js
More file actions
151 lines (140 loc) · 4.77 KB
/
Rectangle.js
File metadata and controls
151 lines (140 loc) · 4.77 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
143
144
145
146
147
148
149
150
151
import {
Tangram
} from "./Tangram";
/**
* 矩形几何对象
* @class Zondy.Object.Rectangle
* @classdesc 矩形几何对象
* @extends Zondy.Object.Tangram
* @param {Number} xmin x最小值
* @param {Number} xmax x最大值
* @param {Number} ymin y最小值
* @param {Number} ymax y最大值
* @param {Object} option 属性键值对,拓展属性
*/
class Rectangle extends Tangram {
/// <summary>矩形几何对象构造函数</summary>
/// <param name="m_arguments" type="String">矩形坐标("xmin,ymin,xmax,ymax")</param>
/// <param name="option" type="Object">属性键值对</param>
constructor(xmin, ymin, xmax, ymax, option) {
var options = option ? option : {};
super(options);
/**
* @member Zondy.Object.Rectangle.prototype.xmin
* @type {Number}
* @description xmin
*/
this.xmin = xmin;
/**
* @member Zondy.Object.Rectangle.prototype.xmax
* @type {Number}
* @description xmax
*/
this.xmax = xmax;
/**
* @member Zondy.Object.Rectangle.prototype.ymin
* @type {Number}
* @description ymin
*/
this.ymin = ymin;
/**
* @member Zondy.Object.Rectangle.prototype.ymax
* @type {Number}
* @description ymax
*/
this.ymax = ymax;
}
/**
* @function Zondy.Object.Rectangle.prototype.setByOL
* @description 使用一个由Openlayers定义的矩形来构造本对象
* @param {ol.extent} openlayersRect 由OpenLayers定义的矩形对象
*/
setByOL(openlayersRect) {
if (openlayersRect === undefined || openlayersRect === null) {
return;
}
this.xmin = openlayersRect[0];
this.ymin = openlayersRect[1];
this.xmax = openlayersRect[2];
this.ymax = openlayersRect[3];
}
/**
* @function Zondy.Object.Rectangle.prototype.toString
* @description 对象转化为字符串
* @returns {String} 返回一个字符串来表示此矩形
*/
toString() {
return "" + this.xmin + ',' + this.ymin + ',' + this.xmax + ',' + this.ymax;
}
/**
* @function Zondy.Object.Rectangle.prototype.getGeometryType
* @description 获取几何类型名称
* @returns {String} rect
*/
getGeometryType() {
return "rect";
}
/**
* @function Zondy.Object.Rectangle.prototype.convertToBound
* @description 将本对象转换为一个OpenLayers.Bound对象
* @returns {ol.extent} 返回一个字符串来表示此矩形
*/
convertToBound() {
var bounds = [this.xmin, this.ymin, this.xmax, this.ymax];
return bounds;
}
/**
* @function Zondy.Object.Rectangle.prototype.intersectsBounds
* @description 判断是否和另一个矩形相交
* @param {ol.extent} bounds
* @param {String} options 判断参数
* @param {Boolean} [options.inclusive = true] 是否精准计算
*/
intersectsBounds(bounds, options) {
if (typeof options === "boolean") {
options = {
inclusive: options
};
}
options = options || {};
if (options.inclusive === null) {
options.inclusive = true;
}
var self = this;
var intersects = false;
var mightTouch = (
self.xmin === bounds.xmax ||
self.xmax === bounds.xmin ||
self.ymax === bounds.ymin ||
self.ymin === bounds.ymax
);
// if the two bounds only touch at an edge, and inclusive is false,
// then the bounds don't *really* intersect.
if (options.inclusive || !mightTouch) {
// otherwise, if one of the boundaries even partially contains another,
// inclusive of the edges, then they do intersect.
var inBottom = (
((bounds.ymin >= self.ymin) && (bounds.ymin <= self.ymax)) ||
((self.ymin >= bounds.ymin) && (self.ymin <= bounds.ymax))
);
var inTop = (
((bounds.ymax >= self.ymin) && (bounds.ymax <= self.ymax)) ||
((self.ymax > bounds.ymin) && (self.ymax < bounds.ymax))
);
var inLeft = (
((bounds.xmin >= self.xmin) && (bounds.xmin <= self.xmax)) ||
((self.xmin >= bounds.xmin) && (self.xmin <= bounds.xmax))
);
var inRight = (
((bounds.xmax >= self.xmin) && (bounds.xmax <= self.xmax)) ||
((self.xmax >= bounds.xmin) && (self.xmax <= bounds.xmax))
);
intersects = ((inBottom || inTop) && (inLeft || inRight));
}
return intersects;
}
}
export {
Rectangle
};
Zondy.Object.Rectangle = Rectangle;