2
2
* This program are made available under the terms of the Apache License, Version 2.0
3
3
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4
4
import { LineString } from './LineString' ;
5
+ import { Util } from '../Util' ;
5
6
6
7
/**
7
8
* @class GeometryLinearRing
@@ -36,6 +37,20 @@ export class LinearRing extends LineString {
36
37
this . geometryType = "LinearRing" ;
37
38
}
38
39
40
+
41
+ addComponents ( components ) {
42
+ if ( ! ( Util . isArray ( components ) ) ) {
43
+ components = [ components ] ;
44
+ }
45
+ let len = components . length ;
46
+ if ( components [ 0 ] . equals ( components [ components . length - 1 ] ) ) {
47
+ len = components . length - 1 ;
48
+ }
49
+ for ( var i = 0 ; i < len ; i ++ ) {
50
+ this . addComponent ( components [ i ] ) ;
51
+ }
52
+ }
53
+
39
54
/**
40
55
* @function GeometryLinearRing.prototype.addComponent
41
56
* @description 添加一个点到几何图形数组中,如果这个点将要被添加到组件数组的末端,并且与数组中已经存在的最后一个点相同,
@@ -49,18 +64,17 @@ export class LinearRing extends LineString {
49
64
var added = false ;
50
65
51
66
//remove last point
52
- var lastPoint = this . components . pop ( ) ;
67
+ this . components . pop ( ) ;
53
68
54
69
// given an index, add the point
55
70
// without an index only add non-duplicate points
56
- if ( index != null || ! point . equals ( lastPoint ) ) {
71
+ if ( index != null || ! point . equals ( this . components [ this . components . length - 1 ] ) ) {
57
72
added = super . addComponent . apply ( this , arguments ) ;
58
73
}
59
74
60
75
//append copy of first point
61
76
var firstPoint = this . components [ 0 ] ;
62
77
super . addComponent . apply ( this , [ firstPoint ] ) ;
63
-
64
78
return added ;
65
79
}
66
80
0 commit comments