@@ -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 => {
0 commit comments