Merge pull request #7749 from fredj/f7035
Check if the sketch feature is defined in finishDrawing
This commit is contained in:
@@ -714,6 +714,9 @@ Draw.prototype.removeLastPoint = function() {
|
||||
*/
|
||||
Draw.prototype.finishDrawing = function() {
|
||||
const sketchFeature = this.abortDrawing_();
|
||||
if (!sketchFeature) {
|
||||
return;
|
||||
}
|
||||
let coordinates = this.sketchCoords_;
|
||||
const geometry = /** @type {ol.geom.SimpleGeometry} */ (sketchFeature.getGeometry());
|
||||
if (this.mode_ === Draw.Mode_.LINE_STRING) {
|
||||
|
||||
@@ -240,15 +240,24 @@ describe('ol.interaction.Draw', function() {
|
||||
expect(receivedEvents.end).to.be(1);
|
||||
expect(receivedEvents.addfeature).to.be(1);
|
||||
});
|
||||
|
||||
it('works if finishDrawing is called when the sketch feature is not defined', function() {
|
||||
expect(function() {
|
||||
draw.finishDrawing();
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('drawing multipoints', function() {
|
||||
let draw;
|
||||
|
||||
beforeEach(function() {
|
||||
map.addInteraction(new Draw({
|
||||
draw = new Draw({
|
||||
source: source,
|
||||
type: 'MultiPoint'
|
||||
}));
|
||||
});
|
||||
map.addInteraction(draw);
|
||||
});
|
||||
|
||||
it('draws multipoint on click', function() {
|
||||
@@ -262,6 +271,12 @@ describe('ol.interaction.Draw', function() {
|
||||
expect(geometry.getCoordinates()).to.eql([[30, -15]]);
|
||||
});
|
||||
|
||||
it('works if finishDrawing is called when the sketch feature is not defined', function() {
|
||||
expect(function() {
|
||||
draw.finishDrawing();
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('drawing linestrings', function() {
|
||||
@@ -463,6 +478,12 @@ describe('ol.interaction.Draw', function() {
|
||||
expect(de.callCount).to.be(1);
|
||||
});
|
||||
|
||||
it('works if finishDrawing is called when the sketch feature is not defined', function() {
|
||||
expect(function() {
|
||||
draw.finishDrawing();
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('drawing with a finishCondition', function() {
|
||||
@@ -515,12 +536,14 @@ describe('ol.interaction.Draw', function() {
|
||||
});
|
||||
|
||||
describe('drawing multi-linestrings', function() {
|
||||
let draw;
|
||||
|
||||
beforeEach(function() {
|
||||
map.addInteraction(new Draw({
|
||||
draw = new Draw({
|
||||
source: source,
|
||||
type: 'MultiLineString'
|
||||
}));
|
||||
});
|
||||
map.addInteraction(draw);
|
||||
});
|
||||
|
||||
it('draws multi with clicks, finishing on last point', function() {
|
||||
@@ -545,6 +568,12 @@ describe('ol.interaction.Draw', function() {
|
||||
expect(geometry.getCoordinates()).to.eql([[[10, -20], [30, -20]]]);
|
||||
});
|
||||
|
||||
it('works if finishDrawing is called when the sketch feature is not defined', function() {
|
||||
expect(function() {
|
||||
draw.finishDrawing();
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('drawing polygons', function() {
|
||||
@@ -645,7 +674,6 @@ describe('ol.interaction.Draw', function() {
|
||||
|
||||
});
|
||||
|
||||
|
||||
it('draws polygon with clicks, finishing on last point', function() {
|
||||
// first point
|
||||
simulateEvent('pointermove', 10, 20);
|
||||
@@ -732,15 +760,23 @@ describe('ol.interaction.Draw', function() {
|
||||
expect(de.callCount).to.be(1);
|
||||
});
|
||||
|
||||
it('works if finishDrawing is called when the sketch feature is not defined', function() {
|
||||
expect(function() {
|
||||
draw.finishDrawing();
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('drawing multi-polygons', function() {
|
||||
let draw;
|
||||
|
||||
beforeEach(function() {
|
||||
map.addInteraction(new Draw({
|
||||
draw = new Draw({
|
||||
source: source,
|
||||
type: 'MultiPolygon'
|
||||
}));
|
||||
});
|
||||
map.addInteraction(draw);
|
||||
});
|
||||
|
||||
it('draws multi with clicks, finishing on first point', function() {
|
||||
@@ -808,6 +844,12 @@ describe('ol.interaction.Draw', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('works if finishDrawing is called when the sketch feature is not defined', function() {
|
||||
expect(function() {
|
||||
draw.finishDrawing();
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('drawing circles', function() {
|
||||
@@ -880,6 +922,12 @@ describe('ol.interaction.Draw', function() {
|
||||
expect(de.callCount).to.be(1);
|
||||
});
|
||||
|
||||
it('works if finishDrawing is called when the sketch feature is not defined', function() {
|
||||
expect(function() {
|
||||
draw.finishDrawing();
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setActive()', function() {
|
||||
|
||||
Reference in New Issue
Block a user