22 * This program are made available under the terms of the Apache License, Version 2.0
33 * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
44import { LineString } from './LineString' ;
5+ import { Util } from '../Util' ;
56
67/**
78 * @class GeometryLinearRing
@@ -36,6 +37,20 @@ export class LinearRing extends LineString {
3637 this . geometryType = "LinearRing" ;
3738 }
3839
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+
3954 /**
4055 * @function GeometryLinearRing.prototype.addComponent
4156 * @description 添加一个点到几何图形数组中,如果这个点将要被添加到组件数组的末端,并且与数组中已经存在的最后一个点相同,
@@ -49,18 +64,17 @@ export class LinearRing extends LineString {
4964 var added = false ;
5065
5166 //remove last point
52- var lastPoint = this . components . pop ( ) ;
67+ this . components . pop ( ) ;
5368
5469 // given an index, add the point
5570 // 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 ] ) ) {
5772 added = super . addComponent . apply ( this , arguments ) ;
5873 }
5974
6075 //append copy of first point
6176 var firstPoint = this . components [ 0 ] ;
6277 super . addComponent . apply ( this , [ firstPoint ] ) ;
63-
6478 return added ;
6579 }
6680
0 commit comments