Skip to content

Commit c18e82c

Browse files
ChangeSugerDymoneLewis
authored andcommitted
feat: 修改小地图 lf 实例的创建与销毁时机(#2261)
- 在 show 时创建 lf 实例,在 hide 时销毁 lf 实例
1 parent 34f2fcd commit c18e82c

File tree

1 file changed

+12
-3
lines changed
  • packages/extension/src/components/mini-map

1 file changed

+12
-3
lines changed

packages/extension/src/components/mini-map/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@ export class MiniMap {
198198
this.bounds = boundsInit
199199
this.elementAreaBounds = boundsInit
200200
this.viewPortBounds = boundsInit
201-
this.initMiniMap()
202-
lf.on('graph:resize', this.onGraphResize)
203201
}
204202

205203
onGraphResize = () => {
@@ -230,8 +228,10 @@ export class MiniMap {
230228
*/
231229
public show = (left?: number, top?: number) => {
232230
if (!this.isShow) {
231+
this.initMiniMap()
232+
this.lf.on('graph:resize', this.onGraphResize)
233233
this.createMiniMap(left, top)
234-
this.setView()
234+
this.setView(true)
235235
}
236236
this.isShow = true
237237
}
@@ -240,6 +240,14 @@ export class MiniMap {
240240
*/
241241
public hide = () => {
242242
if (this.isShow) {
243+
// 隐藏小地图时摧毁实例
244+
destroyTeleportContainer(this.lfMap.graphModel.flowId)
245+
this.lf.off('graph:resize', this.onGraphResize)
246+
this.lfMap.destroy()
247+
// 保证重新创建实例时,小地图中内容偏移正确
248+
this.translateX = 0
249+
this.translateY = 0
250+
243251
this.removeMiniMap()
244252
this.lf.emit('miniMap:close', {})
245253
}
@@ -677,6 +685,7 @@ export class MiniMap {
677685
},
678686
})
679687
}
688+
680689
destroy() {
681690
destroyTeleportContainer(this.lfMap.graphModel.flowId)
682691
this.lf.off('graph:resize', this.onGraphResize)

0 commit comments

Comments
 (0)