meta2d.js icon indicating copy to clipboard operation
meta2d.js copied to clipboard

[疑问] 自定义图形注册以后,当前画布销毁,在当前页面再次实列化topology并再次注册自定义图形发现图形背景色不显示了

Open hsbtr opened this issue 3 years ago • 1 comments

const baseBusBar = (pen, ctx) => {
  const path = !ctx ? new Path2D() : ctx;
  const { x, y, width, height } = pen.calculative.worldRect;
  path.moveTo(x, y);
  path.lineTo(x + width, y); // 上
  path.lineTo(x + width, y + height); // 右
  path.lineTo(x, y + height); // 下
  path.lineTo(x, y); //左
  path.closePath();
  if (path instanceof Path2D) return path;
}

因为业务中需要用tabs实现多个图纸,限定只实列化当前选中得tab其余得画布都会销毁,然后发现只有第一个tab才能显示这个自定义图形,其他tab里自定义图形背景色填充都失效了

image

hsbtr avatar Aug 23 '22 15:08 hsbtr

补上重现demo;创建第一个tab后在该图纸加入几个画笔;再创建第二个tab;并切换此时第二个tab上除了image类型画笔可显示其他画笔都失效了; 推测销毁画布后未将window上topology某些数据清空

hsbtr avatar Sep 06 '22 15:09 hsbtr

看了下你的 demo ,问题出现在旧版本中,推荐升级到最新的 1.2.16 。 并且在销毁时,参数传 true ,已测试 topologyRef.current?.destroy(true); image

SignDawn avatar Jan 08 '23 16:01 SignDawn

下回发 demo ,可以使用 codesandbox

SignDawn avatar Jan 08 '23 16:01 SignDawn