1+ require ( '../../../src/common/commontypes/Bounds' ) ;
2+
3+ describe ( 'Bounds' , function ( ) {
4+ it ( 'constructor, clone, equals, toString, toArray' , function ( ) {
5+ var bounds = new SuperMap . Bounds ( [ - 180 , - 90 , 180 , 90 ] ) ;
6+ var bounds1 = bounds . clone ( ) ;
7+ expect ( bounds ) . not . toBeNull ( ) ;
8+ expect ( bounds . CLASS_NAME ) . toEqual ( "SuperMap.Bounds" ) ;
9+ expect ( bounds . bottom ) . toEqual ( - 90 ) ;
10+ expect ( bounds . left ) . toEqual ( - 180 ) ;
11+ expect ( bounds . right ) . toEqual ( 180 ) ;
12+ expect ( bounds . top ) . toEqual ( 90 ) ;
13+ expect ( bounds ) . toEqual ( bounds1 ) ;
14+ var isEqual = bounds1 . equals ( bounds ) ;
15+ expect ( isEqual ) . toBeTruthy ( ) ;
16+ var str = bounds . toString ( ) ;
17+ expect ( str ) . toEqual ( "-180,-90,180,90" ) ;
18+ var array = bounds . toArray ( true ) ;
19+ expect ( array . length ) . toEqual ( 4 ) ;
20+ expect ( array [ 0 ] ) . toEqual ( - 90 ) ;
21+ expect ( array [ 1 ] ) . toEqual ( - 180 ) ;
22+ expect ( array [ 2 ] ) . toEqual ( 90 ) ;
23+ expect ( array [ 3 ] ) . toEqual ( 180 ) ;
24+ var array1 = bounds . toArray ( false ) ;
25+ expect ( array1 . length ) . toEqual ( 4 ) ;
26+ expect ( array1 [ 0 ] ) . toEqual ( - 180 ) ;
27+ expect ( array1 [ 1 ] ) . toEqual ( - 90 ) ;
28+ expect ( array1 [ 2 ] ) . toEqual ( 180 ) ;
29+ expect ( array1 [ 3 ] ) . toEqual ( 90 ) ;
30+ bounds . destroy ( ) ;
31+ } ) ;
32+
33+ //取小数点后decimal位数字进行四舍五入再转换为BBOX字符串
34+ it ( 'toBBOX' , function ( ) {
35+ var bounds = new SuperMap . Bounds ( - 1.1234567 , - 1.7654321 , 1.4444444 , 1.5555555 ) ;
36+ var str1 = bounds . toBBOX ( ) ;
37+ expect ( str1 ) . toEqual ( "-1.123457,-1.765432,1.444444,1.555556" ) ;
38+ var str2 = bounds . toBBOX ( 1 ) ;
39+ expect ( str2 ) . toEqual ( "-1.1,-1.8,1.4,1.6" ) ;
40+ var str3 = bounds . toBBOX ( 1 , true ) ;
41+ expect ( str3 ) . toEqual ( "-1.8,-1.1,1.6,1.4" ) ;
42+ bounds . destroy ( ) ;
43+ } ) ;
44+
45+ //基于当前边界范围创建一个新的多边形对象
46+ it ( 'toGeometry' , function ( ) {
47+ var bounds = new SuperMap . Bounds ( - 180 , - 90 , 100 , 80 ) ;
48+ var geo = bounds . toGeometry ( ) ;
49+ expect ( geo ) . not . toBeNull ( ) ;
50+ expect ( geo . CLASS_NAME ) . toEqual ( "SuperMap.Geometry.Polygon" ) ;
51+ expect ( geo . id ) . toContain ( "SuperMap.Geometry" ) ;
52+ expect ( geo . componentTypes [ 0 ] ) . toEqual ( "SuperMap.Geometry.LinearRing" ) ;
53+ bounds . destroy ( ) ;
54+ } ) ;
55+
56+ it ( 'getSize, getCenterPixel' , function ( ) {
57+ var bounds = new SuperMap . Bounds ( - 180 , - 90 , 100 , 80 ) ;
58+ var size = bounds . getSize ( ) ;
59+ var pixel = bounds . getCenterPixel ( ) ;
60+ expect ( size . w ) . toEqual ( 280 ) ;
61+ expect ( size . h ) . toEqual ( 170 ) ;
62+ expect ( pixel . x ) . toEqual ( - 40 ) ;
63+ expect ( pixel . y ) . toEqual ( - 5 ) ;
64+ bounds . destroy ( ) ;
65+ } ) ;
66+
67+ it ( 'scale' , function ( ) {
68+ var bounds = new SuperMap . Bounds ( - 50 , - 50 , 40 , 40 ) ;
69+ var bounds1 = bounds . scale ( 2 ) ;
70+ expect ( bounds1 ) . not . toBeNull ( ) ;
71+ expect ( bounds1 . bottom ) . toEqual ( - 95 ) ;
72+ expect ( bounds1 . left ) . toEqual ( - 95 ) ;
73+ expect ( bounds1 . right ) . toEqual ( 85 ) ;
74+ expect ( bounds1 . top ) . toEqual ( 85 ) ;
75+ var origin = new SuperMap . Pixel ( 40 , 50 ) ;
76+ var bounds2 = bounds . scale ( 2 , origin ) ;
77+ expect ( bounds2 ) . not . toBeNull ( ) ;
78+ expect ( bounds2 . bottom ) . toEqual ( - 150 ) ;
79+ expect ( bounds2 . left ) . toEqual ( - 140 ) ;
80+ expect ( bounds2 . right ) . toEqual ( 40 ) ;
81+ expect ( bounds2 . top ) . toEqual ( 30 ) ;
82+ bounds . destroy ( ) ;
83+ } ) ;
84+
85+ it ( 'add' , function ( ) {
86+ var bounds = new SuperMap . Bounds ( - 50 , - 50 , 40 , 40 ) ;
87+ var newBounds = bounds . add ( 20 , 10 ) ;
88+ expect ( newBounds ) . not . toBeNull ( ) ;
89+ expect ( newBounds . bottom ) . toEqual ( - 40 ) ;
90+ expect ( newBounds . left ) . toEqual ( - 30 ) ;
91+ expect ( newBounds . right ) . toEqual ( 60 ) ;
92+ expect ( newBounds . top ) . toEqual ( 50 ) ;
93+ bounds . destroy ( ) ;
94+ } ) ;
95+
96+ //在当前bounds上扩展bounds
97+ it ( 'extend' , function ( ) {
98+ var bounds = new SuperMap . Bounds ( - 50 , - 50 , 40 , 40 ) ;
99+ spyOn ( bounds , 'extend' ) . and . callThrough ( ) ;
100+ bounds . extend ( new SuperMap . LonLat ( 50 , 60 ) ) ;
101+ expect ( bounds ) . not . toBeNull ( ) ;
102+ bounds . extend ( new SuperMap . Geometry . Point ( 50 , 60 ) ) ;
103+ expect ( bounds ) . not . toBeNull ( ) ;
104+ bounds . extend ( new SuperMap . Bounds ( 50 , 60 ) ) ;
105+ expect ( bounds ) . not . toBeNull ( ) ;
106+ expect ( bounds . bottom ) . toEqual ( - 50 ) ;
107+ expect ( bounds . left ) . toEqual ( - 50 ) ;
108+ expect ( bounds . right ) . toEqual ( 50 ) ;
109+ expect ( bounds . top ) . toEqual ( 60 ) ;
110+ bounds . destroy ( ) ;
111+ } ) ;
112+
113+ //判断传入的坐标是否在范围内
114+ it ( 'containsLonLat' , function ( ) {
115+ var bounds = new SuperMap . Bounds ( - 50 , - 50 , 40 , 40 ) ;
116+ var isContains1 = bounds . containsLonLat ( new SuperMap . LonLat ( 40 , 40 ) , true ) ;
117+ expect ( isContains1 ) . toBeTruthy ( ) ;
118+ var isContains2 = bounds . containsLonLat (
119+ new SuperMap . LonLat ( 400 , 40 ) ,
120+ {
121+ inclusive : true ,
122+ worldBounds : new SuperMap . Bounds ( - 180 , - 90 , 180 , 90 )
123+ }
124+ ) ;
125+ expect ( isContains2 ) . toBeTruthy ( ) ;
126+ bounds . destroy ( ) ;
127+ } ) ;
128+
129+ it ( 'containsPixel' , function ( ) {
130+ var bounds = new SuperMap . Bounds ( - 50 , - 50 , 40 , 40 ) ;
131+ var isContains = bounds . containsPixel ( new SuperMap . Pixel ( 40 , 40 ) , true ) ;
132+ expect ( isContains ) . toBeTruthy ( ) ;
133+ bounds . destroy ( ) ;
134+ } ) ;
135+
136+ it ( 'contains' , function ( ) {
137+ var bounds = new SuperMap . Bounds ( - 50 , - 50 , 40 , 40 ) ;
138+ var isContains1 = bounds . contains ( 40 , 40 ) ;
139+ var isContains2 = bounds . contains ( ) ;
140+ var isContains3 = bounds . contains ( 40 , 40 , false ) ;
141+ expect ( isContains1 ) . toBeTruthy ( ) ;
142+ expect ( isContains2 ) . toBeFalsy ( ) ;
143+ expect ( isContains3 ) . toBeFalsy ( ) ;
144+ bounds . destroy ( ) ;
145+ } ) ;
146+
147+ //判断目标边界范围是否与当前边界范围相交
148+ it ( 'intersectsBounds' , function ( ) {
149+ var bounds = new SuperMap . Bounds ( - 180 , - 90 , 100 , 80 ) ;
150+ var options1 = {
151+ inclusive : false ,
152+ worldBounds : new SuperMap . Bounds ( - 170 , - 90 , 120 , 80 )
153+ } ;
154+ var options2 = {
155+ inclusive : false ,
156+ worldBounds : new SuperMap . Bounds ( - 180 , - 90 , 100 , 80 )
157+ } ;
158+ var isIntersects1 = bounds . intersectsBounds (
159+ new SuperMap . Bounds ( 100 , - 90 , 120 , 80 ) ,
160+ options1
161+ ) ;
162+ var isIntersects2 = bounds . intersectsBounds (
163+ new SuperMap . Bounds ( 100 , - 90 , 100 , 80 ) ,
164+ options2
165+ ) ;
166+ expect ( isIntersects1 ) . toBeTruthy ( ) ;
167+ expect ( isIntersects2 ) . toBeFalsy ( ) ;
168+ bounds . destroy ( ) ;
169+ } ) ;
170+
171+ it ( 'determineQuadrant' , function ( ) {
172+ var bounds = new SuperMap . Bounds ( - 180 , - 90 , 100 , 80 ) ;
173+ var str = bounds . determineQuadrant ( new SuperMap . LonLat ( 20 , 20 ) ) ;
174+ expect ( str ) . toEqual ( "tr" ) ;
175+ bounds . destroy ( ) ;
176+ } ) ;
177+
178+ it ( 'toServerJSONObject' , function ( ) {
179+ var bounds = new SuperMap . Bounds ( - 180 , - 90 , 100 , 80 ) ;
180+ var obj = bounds . toServerJSONObject ( ) ;
181+ expect ( obj ) . not . toBeNull ( ) ;
182+ expect ( obj . bottom ) . toEqual ( - 90 ) ;
183+ expect ( obj . left ) . toEqual ( - 180 ) ;
184+ expect ( obj . right ) . toEqual ( 100 ) ;
185+ expect ( obj . top ) . toEqual ( 80 ) ;
186+ expect ( obj . leftBottom ) . not . toBeNull ( ) ;
187+ expect ( obj . rightTop ) . not . toBeNull ( ) ;
188+ bounds . destroy ( ) ;
189+ } ) ;
190+
191+ it ( 'fromString' , function ( ) {
192+ var bounds = SuperMap . Bounds . fromString ( "-180,-90,100,80" , false ) ;
193+ expect ( bounds ) . not . toBeNull ( ) ;
194+ expect ( bounds . bottom ) . toEqual ( - 90 ) ;
195+ expect ( bounds . left ) . toEqual ( - 180 ) ;
196+ expect ( bounds . right ) . toEqual ( 100 ) ;
197+ expect ( bounds . top ) . toEqual ( 80 ) ;
198+ } ) ;
199+
200+ it ( 'fromSize' , function ( ) {
201+ var bounds = SuperMap . Bounds . fromSize ( new SuperMap . Size ( 20 , 10 ) ) ;
202+ expect ( bounds ) . not . toBeNull ( ) ;
203+ expect ( bounds . bottom ) . toEqual ( 10 ) ;
204+ expect ( bounds . left ) . toEqual ( 0 ) ;
205+ expect ( bounds . right ) . toEqual ( 20 ) ;
206+ expect ( bounds . top ) . toEqual ( 0 ) ;
207+ } ) ;
208+
209+ it ( 'oppositeQuadrant' , function ( ) {
210+ var oppositeQuadrant = SuperMap . Bounds . oppositeQuadrant ( "tl" ) ;
211+ expect ( oppositeQuadrant ) . toEqual ( "br" ) ;
212+ } ) ;
213+ } ) ;
0 commit comments