Close polygon sketch at all times

This commit is contained in:
Björn Harrtell
2016-10-25 21:57:38 +02:00
parent 767bec4dc7
commit 1bd11c1958

View File

@@ -152,7 +152,11 @@ ol.interaction.Draw = function(options) {
geometryFunction = function(coordinates, opt_geometry) {
var geometry = opt_geometry;
if (geometry) {
geometry.setCoordinates(coordinates);
if (mode === ol.interaction.Draw.Mode.POLYGON) {
geometry.setCoordinates([coordinates[0].concat([coordinates[0][0]])]);
} else {
geometry.setCoordinates(coordinates);
}
} else {
geometry = new Constructor(coordinates);
}
@@ -617,12 +621,10 @@ ol.interaction.Draw.prototype.finishDrawing = function() {
coordinates.pop();
this.geometryFunction_(coordinates, geometry);
} else if (this.mode_ === ol.interaction.Draw.Mode.POLYGON) {
// When we finish drawing a polygon on the last point,
// the last coordinate is duplicated as for LineString
// we force the replacement by the first point
// remove the redundant last point in ring
coordinates[0].pop();
coordinates[0].push(coordinates[0][0]);
this.geometryFunction_(coordinates, geometry);
coordinates = geometry.getCoordinates();
}
// cast multi-part geometries