@@ -3,7 +3,7 @@ describe('DistanceTool and AreaTool', function () {
3
3
var map ;
4
4
var center = new maptalks . Coordinate ( 118.846825 , 32.046534 ) ;
5
5
6
- function measure ( tool ) {
6
+ function measure ( tool , noDblClick ) {
7
7
var center = map . getCenter ( ) ;
8
8
9
9
var domPosition = GET_PAGE_POSITION ( container ) ;
@@ -76,10 +76,13 @@ describe('DistanceTool and AreaTool', function () {
76
76
'clientX' :point . x - 1 ,
77
77
'clientY' :point . y + 5
78
78
} ) ;
79
- happen . dblclick ( eventContainer , {
80
- 'clientX' :point . x - 1 ,
81
- 'clientY' :point . y + 5
82
- } ) ;
79
+ if ( ! noDblClick ) {
80
+ happen . dblclick ( eventContainer , {
81
+ 'clientX' :point . x - 1 ,
82
+ 'clientY' :point . y + 5
83
+ } ) ;
84
+ }
85
+
83
86
if ( tool . isEnabled ( ) ) {
84
87
expect ( tool . getLastMeasure ( ) ) . to . be . above ( measure ) ;
85
88
measure = tool . getLastMeasure ( ) ;
@@ -148,6 +151,38 @@ describe('DistanceTool and AreaTool', function () {
148
151
result = tool . getLastMeasure ( ) ;
149
152
expect ( result ) . to . be . above ( 0 ) ;
150
153
} ) ;
154
+
155
+ it ( 'endDraw' , function ( ) {
156
+ var distanceTool = new maptalks . DistanceTool ( {
157
+ metric : true ,
158
+ imperial :true
159
+ } ) . addTo ( map ) ;
160
+ expect ( distanceTool . getLastMeasure ( ) ) . to . be . eql ( 0 ) ;
161
+ measure ( distanceTool , true ) ;
162
+ distanceTool . endDraw ( ) ;
163
+ expect ( distanceTool . getLastMeasure ( ) ) . to . be . above ( 0 ) ;
164
+ } ) ;
165
+
166
+ it ( 'endDraw with 1 click' , function ( ) {
167
+ var tool = new maptalks . DistanceTool ( ) . addTo ( map ) ;
168
+ var center = map . getCenter ( ) ;
169
+
170
+ var domPosition = GET_PAGE_POSITION ( container ) ;
171
+ var point = map . coordinateToContainerPoint ( center ) . add ( domPosition ) ;
172
+
173
+ var measure = 0 ;
174
+ happen . mousedown ( eventContainer , {
175
+ 'clientX' :point . x ,
176
+ 'clientY' :point . y
177
+ } ) ;
178
+ happen . click ( eventContainer , {
179
+ 'clientX' :point . x ,
180
+ 'clientY' :point . y
181
+ } ) ;
182
+ var i ;
183
+ tool . endDraw ( ) ;
184
+ expect ( tool . getLastMeasure ( ) ) . to . be . eql ( 0 ) ;
185
+ } ) ;
151
186
} ) ;
152
187
153
188
describe ( 'test areaTool' , function ( ) {
@@ -221,6 +256,53 @@ describe('DistanceTool and AreaTool', function () {
221
256
result = tool . getLastMeasure ( ) ;
222
257
expect ( result ) . to . be . above ( 0 ) ;
223
258
} ) ;
259
+
260
+ it ( 'endDraw with 2 clicks' , function ( ) {
261
+ var tool = new maptalks . AreaTool ( ) . addTo ( map ) ;
262
+ var center = map . getCenter ( ) ;
263
+
264
+ var domPosition = GET_PAGE_POSITION ( container ) ;
265
+ var point = map . coordinateToContainerPoint ( center ) . add ( domPosition ) ;
266
+
267
+ var measure = 0 ;
268
+ happen . mousedown ( eventContainer , {
269
+ 'clientX' :point . x ,
270
+ 'clientY' :point . y
271
+ } ) ;
272
+ happen . click ( eventContainer , {
273
+ 'clientX' :point . x ,
274
+ 'clientY' :point . y
275
+ } ) ;
276
+ var i ;
277
+ for ( i = 1 ; i < 10 ; i ++ ) {
278
+ happen . mousemove ( eventContainer , {
279
+ 'clientX' :point . x + i ,
280
+ 'clientY' :point . y
281
+ } ) ;
282
+ }
283
+
284
+ happen . mousedown ( eventContainer , {
285
+ 'clientX' :point . x + 10 ,
286
+ 'clientY' :point . y
287
+ } ) ;
288
+ happen . click ( eventContainer , {
289
+ 'clientX' :point . x + 10 ,
290
+ 'clientY' :point . y
291
+ } ) ;
292
+ tool . endDraw ( ) ;
293
+ expect ( tool . getLastMeasure ( ) ) . to . be . eql ( 0 ) ;
294
+ } ) ;
295
+
296
+ it ( 'endDraw' , function ( ) {
297
+ var tool = new maptalks . AreaTool ( ) . addTo ( map ) . disable ( ) ;
298
+ measure ( tool ) ;
299
+ var result = tool . getLastMeasure ( ) ;
300
+ expect ( result ) . to . be ( 0 ) ;
301
+ tool . enable ( ) ;
302
+ measure ( tool , true ) ;
303
+ tool . endDraw ( ) ;
304
+ expect ( tool . getLastMeasure ( ) ) . to . be . above ( 0 ) ;
305
+ } ) ;
224
306
} ) ;
225
307
226
308
0 commit comments