Merge pull request #6686 from fredj/removeLastPoint

Update finishCoordinate in ol.interaction.Draw#removeLastPoint
This commit is contained in:
Frédéric Junod
2017-04-11 08:20:30 +02:00
committed by GitHub
2 changed files with 56 additions and 0 deletions

View File

@@ -603,12 +603,18 @@ ol.interaction.Draw.prototype.addToDrawing_ = function(event) {
* @api
*/
ol.interaction.Draw.prototype.removeLastPoint = function() {
if (!this.sketchFeature_) {
return;
}
var geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
var coordinates, sketchLineGeom;
if (this.mode_ === ol.interaction.Draw.Mode_.LINE_STRING) {
coordinates = this.sketchCoords_;
coordinates.splice(-2, 1);
this.geometryFunction_(coordinates, geometry);
if (coordinates.length >= 2) {
this.finishCoordinate_ = coordinates[coordinates.length - 2].slice();
}
} else if (this.mode_ === ol.interaction.Draw.Mode_.POLYGON) {
coordinates = this.sketchCoords_[0];
coordinates.splice(-2, 1);

View File

@@ -289,6 +289,31 @@ describe('ol.interaction.Draw', function() {
expect(geometry.getCoordinates()).to.eql([[10, -20], [30, -20]]);
});
it('supports removeLastPoint while drawing', function() {
draw.removeLastPoint();
// first point
simulateEvent('pointermove', 10, 20);
simulateEvent('pointerdown', 10, 20);
simulateEvent('pointerup', 10, 20);
// second point
simulateEvent('pointermove', 40, 30);
simulateEvent('pointerdown', 40, 30);
simulateEvent('pointerup', 40, 30);
simulateEvent('pointermove', 100, 100);
draw.removeLastPoint();
// click near the removed point
simulateEvent('pointermove', 39, 31);
simulateEvent('pointerdown', 38, 31);
simulateEvent('pointerup', 38, 31);
expect(source.getFeatures()).to.have.length(0);
});
it('supports freehand drawing for linestrings', function() {
// freehand sequence
simulateEvent('pointermove', 10, 20);
@@ -534,6 +559,31 @@ describe('ol.interaction.Draw', function() {
]);
});
it('supports removeLastPoint while drawing', function() {
draw.removeLastPoint();
// first point
simulateEvent('pointermove', 10, 20);
simulateEvent('pointerdown', 10, 20);
simulateEvent('pointerup', 10, 20);
// second point
simulateEvent('pointermove', 40, 30);
simulateEvent('pointerdown', 40, 30);
simulateEvent('pointerup', 40, 30);
simulateEvent('pointermove', 100, 100);
draw.removeLastPoint();
// click near the removed point
simulateEvent('pointermove', 39, 31);
simulateEvent('pointerdown', 39, 31);
simulateEvent('pointerup', 39, 31);
expect(source.getFeatures()).to.have.length(0);
});
it('draws polygon with clicks, finishing on last point', function() {
// first point
simulateEvent('pointermove', 10, 20);