Merge pull request #11803 from MoonE/modify-fix-vertex-insertion

Modify fix vertex insertion
This commit is contained in:
MoonE
2020-12-06 16:47:41 +01:00
committed by GitHub
2 changed files with 39 additions and 6 deletions

View File

@@ -1097,14 +1097,16 @@ class Modify extends PointerInteraction {
for (let i = 1, ii = nodes.length; i < ii; ++i) {
const segment = nodes[i].segment;
if (
((coordinatesEqual(closestSegment[0], segment[0]) &&
(coordinatesEqual(closestSegment[0], segment[0]) &&
coordinatesEqual(closestSegment[1], segment[1])) ||
(coordinatesEqual(closestSegment[0], segment[1]) &&
coordinatesEqual(closestSegment[1], segment[0]))) &&
!(getUid(nodes[i].geometry) in geometries)
(coordinatesEqual(closestSegment[0], segment[1]) &&
coordinatesEqual(closestSegment[1], segment[0]))
) {
geometries[getUid(nodes[i].geometry)] = true;
vertexSegments[getUid(segment)] = true;
const geometryUid = getUid(nodes[i].geometry);
if (!(geometryUid in geometries)) {
geometries[geometryUid] = true;
vertexSegments[getUid(segment)] = true;
}
} else {
break;
}

View File

@@ -423,6 +423,37 @@ describe('ol.interaction.Modify', function () {
expect(lineFeature.getGeometry().getCoordinates().length).to.equal(5);
});
it('inserts one vertex into both linestrings with duplicate segments each', function () {
const lineFeature1 = new Feature(
new LineString([
[-10, -10],
[10, 10],
[-10, -10],
])
);
const lineFeature2 = new Feature(
new LineString([
[10, 10],
[-10, -10],
[10, 10],
])
);
features.length = 0;
features.push(lineFeature1, lineFeature2);
const modify = new Modify({
features: new Collection(features),
});
map.addInteraction(modify);
// Click on line
simulateEvent('pointermove', 0, 0, null, 0);
simulateEvent('pointerdown', 0, 0, null, 0);
simulateEvent('pointerup', 0, 0, null, 0);
expect(lineFeature1.getGeometry().getCoordinates().length).to.be(4);
expect(lineFeature2.getGeometry().getCoordinates().length).to.be(4);
});
});
describe('circle modification', function () {