Skip to content

Commit

Permalink
add cancelEdit, fix #1047
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhenn committed Feb 18, 2020
1 parent 8bc492e commit 843d67b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/geometry/editor/GeometryEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,16 @@ class GeometryEditor extends Eventable(Class) {
this._geometry.fire('editrecord');
}

cancel() {
if (!this._history || this._historyPointer === 0) {
return this;
}
this._historyPointer = 0;
const record = this._history[0];
this._exeAndReset(record);
return this;
}

/**
* Get previous map view in view history
* @return {Object} map view
Expand All @@ -1063,7 +1073,7 @@ class GeometryEditor extends Eventable(Class) {
*/
redo() {
if (!this._history || this._historyPointer === this._history.length - 1) {
return null;
return this;
}
const record = this._history[++this._historyPointer];
this._exeAndReset(record);
Expand Down
21 changes: 21 additions & 0 deletions src/geometry/ext/Geometry.Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,27 @@ Geometry.include(/** @lends Geometry.prototype */ {
return this;
},

/**
* cancel the edit
* @return {Geometry} this
*/
cancelEdit() {
if (!this.isEditing()) {
return this;
}
this._editor.cancel();
/**
* cancel edit event
*
* @event Geometry#canceledit
* @type {Object}
* @property {String} type - canceledit
* @property {Geometry} target - the geometry fires the event
*/
this.fire('canceledit');
return this;
},

/**
* Whether the geometry is being edited.
* @return {Boolean}
Expand Down
4 changes: 4 additions & 0 deletions test/geometry/edit/GeometryEditSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ describe('Geometry.Edit', function () {
expect(c.y).to.be.approx(center.y, 1E-4);
geo.redoEdit();
expect(geo.getCenter()).to.closeTo(newCenter);
geo.cancelEdit();
var c = geo.getCenter();
expect(c.x).to.be.approx(center.x, 1E-4);
expect(c.y).to.be.approx(center.y, 1E-4);
}
geo.endEdit();
};
Expand Down

0 comments on commit 843d67b

Please sign in to comment.