Skip to content

Commit 2fa6268

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents bd01c08 + 1323bd9 commit 2fa6268

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

packages/map/src/geometry/GeometryCollection.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class GeometryCollection extends Geometry {
3939
_draggbleBeforeEdit: any
4040
//@internal
4141
_editing: boolean
42+
_lastUndoEditIndex: number
43+
_lastRedoEditIndex: number
4244

4345
/**
4446
* @param {Geometry[]} geometries - GeometryCollection's geometries
@@ -47,6 +49,8 @@ class GeometryCollection extends Geometry {
4749
constructor(geometries?: Geometry[], opts?: GeometryOptionsType) {
4850
super(opts);
4951
this.type = 'GeometryCollection';
52+
this._lastUndoEditIndex = 0; // 添加一个属性来跟踪上次编辑的索引
53+
this._lastRedoEditIndex = 0; // 添加一个属性来跟踪上次编辑的索引
5054
this.setGeometries(geometries);
5155
}
5256

@@ -642,6 +646,73 @@ class GeometryCollection extends Geometry {
642646
}
643647
return true;
644648
}
649+
undoEdit(): this {
650+
if (this.isEmpty()) {
651+
return this;
652+
}
653+
this._recoveryVisible();
654+
const geometries = this.getGeometries();
655+
let i = this._lastUndoEditIndex; // 从上次停止的地方开始
656+
657+
for (; i < geometries.length; i++) {
658+
if (!geometries[i].undoEditcheck()) {
659+
geometries[i].undoEdit();
660+
this._lastUndoEditIndex = i; // 更新索引为当前元素
661+
break; // 执行一次后停止
662+
}
663+
}
664+
665+
// 如果所有元素的undoEditCheck都为true,重置lastUndoEditIndex
666+
if (i === geometries.length) {
667+
this._lastUndoEditIndex = 0;
668+
}
669+
670+
this.fire('undoedit');
671+
return this;
672+
}
673+
674+
redoEdit(): this {
675+
if (this.isEmpty()) {
676+
return this;
677+
}
678+
this._recoveryVisible();
679+
const geometries = this.getGeometries();
680+
let i = this._lastRedoEditIndex; // 从上次停止的地方开始
681+
682+
for (; i < geometries.length; i++) {
683+
if (!geometries[i].redoEditcheck()) {
684+
geometries[i].redoEdit();
685+
this._lastRedoEditIndex = i; // 更新索引为当前元素
686+
break; // 执行一次后停止
687+
}
688+
}
689+
690+
// 如果所有元素的undoEditCheck都为true,重置lastUndoEditIndex
691+
if (i === geometries.length) {
692+
this._lastRedoEditIndex = 0;
693+
}
694+
695+
this.fire('redoedit');
696+
return this;
697+
}
698+
undoEditcheck(): boolean {
699+
const geometries = this.getGeometries();
700+
for (let i = 0; i < geometries.length; i++) {
701+
if (!geometries[i].undoEditcheck()) {
702+
return false; // 如果任何一个元素的undoEditcheck返回false,则整体返回false
703+
}
704+
}
705+
return true; // 所有元素的undoEditcheck都返回true,则整体返回true
706+
}
707+
redoEditcheck(): boolean {
708+
const geometries = this.getGeometries();
709+
for (let i = 0; i < geometries.length; i++) {
710+
if (!geometries[i].redoEditcheck()) {
711+
return false; // 如果任何一个元素的redoEditcheck返回false,则整体返回false
712+
}
713+
}
714+
return true; // 所有元素的redoEditcheck都返回true,则整体返回true
715+
}
645716

646717
// copy() {
647718
// const geometries = this.getGeometries().map(geo => {

packages/map/src/geometry/ext/Geometry.Edit.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ declare module "../Geometry" {
3333
undoEdit(): this;
3434
cancelEdit(): this;
3535
isEditing(): boolean;
36+
undoEditcheck(): boolean;
37+
redoEditcheck(): boolean;
3638
}
3739
}
3840

0 commit comments

Comments
 (0)