Skip to content

Commit d6c95af

Browse files
committed
【fix】修复LineRing在点串中间有和起始点一样的点时会被忽略掉的问题 review by xiongjj
1 parent 5f0d488 commit d6c95af

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/common/commontypes/geometry/LinearRing.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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.*/
44
import {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

test/common/commontypes/geometry/LinearRingSpec.js

+18
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,22 @@ describe('LinearRing', function () {
4747
expect(pointList2).not.toBeNull();
4848
expect(pointList2.length).toEqual(5);
4949
});
50+
51+
it('addComponent_duplicate_points', function () {
52+
// 第一个点和第4个点一样,但是应该正常渲染,不应该丢弃 ICL-1570
53+
var pointsRing = [
54+
new GeometryPoint(83.4923281624, 63.2826847261),// 1
55+
new GeometryPoint(86.2710459516, 66.4473355416),// 2
56+
new GeometryPoint(80.7522036759, 66.4473355416),// 3
57+
new GeometryPoint(83.4923281624, 63.2826847261),// 4
58+
new GeometryPoint(78.9383184524, 63.2826847261),// 5
59+
new GeometryPoint(78.9383184524, 69.9979193833),// 6
60+
new GeometryPoint(88.3936775961, 69.9979193833),// 7
61+
new GeometryPoint(88.3936775961, 63.4370579366),// 8
62+
new GeometryPoint(83.4923281624, 63.2826847261)
63+
];
64+
var ring = new GeometryLinearRing(pointsRing);
65+
expect(ring.components.length).toEqual(9);
66+
expect(ring.components[3].x).toEqual(83.4923281624);
67+
});
5068
});

0 commit comments

Comments
 (0)