隐藏多边形时,标签保留

发布于 2025-01-22 23:18:17 字数 1495 浏览 0 评论 0原文

我正在使用Edit2D扩展程序和标签上使用Autodesk Viewer。奇怪的是,当多边形隐藏时,标签似乎留下了“残留”。

我的层上有几个多边形,并且用户可以隐藏它们。当他们这样做时,此代码会隐藏着:

export function setRegionVisibility(
  editor: Autodesk.Extensions.Edit2D,
  region: RegionData,
  geometry: SpaceGeometry,
  visible: boolean
): void {
  const shape = editor.defaultContext.layer.shapes.find(
    (s) => s.id === region.itemIds[0]
  );
  if (shape == null) {
    return;
  }
  // @ts-ignore
  shape.visible = visible;
  editor.defaultContext.layer.update();
  return;
}

但是,当隐藏多边形时,它的标签仍在视图上。当我重新展示形状时,它会有一个新的标签,它可以随它移动,但是无论视图的缩放或平移如何,旧的标签都保留在静态位置。

我试图手动将其隐藏或删除它,但似乎无效。这就是我尝试这样做的方式:

export function setRegionVisibility(
  editor: Autodesk.Extensions.Edit2D,
  region: RegionData,
  geometry: SpaceGeometry,
  // @ts-ignore
  tagRule: Autodesk.Edit2D.ShapeLabelRule | undefined,
  visible: boolean
): void {
  const shape = editor.defaultContext.layer.shapes.find(
    (s) => s.id === region.itemIds[0]
  );
  if (shape == null) {
    return;
  }
  // @ts-ignore
  shape.visible = visible;
  let label: any;
  for (let labelsKey in tagRule.labels) {
    if (labelsKey === shape.id.toString()) {
      label = tagRule.labels[labelsKey];
    }
    console.log(tagRule.labels);
  }
  if (label != null) {
    label.visible = visible;
    console.log(label);
    label.dtor();
    label.update();
    label.layer.update();
  }
  editor.defaultContext.layer.update();
  return;
}

任何想法如何使鬼魂消失?

I am using the Autodesk Viewer with the Edit2D extension and working on labels. The strange thing is that labels seem to leave a 'residue' when the polygon is hidden.

I have several polygons on the layer and the ability for the user to hide them. When they do that, this code does the hiding:

export function setRegionVisibility(
  editor: Autodesk.Extensions.Edit2D,
  region: RegionData,
  geometry: SpaceGeometry,
  visible: boolean
): void {
  const shape = editor.defaultContext.layer.shapes.find(
    (s) => s.id === region.itemIds[0]
  );
  if (shape == null) {
    return;
  }
  // @ts-ignore
  shape.visible = visible;
  editor.defaultContext.layer.update();
  return;
}

However, when a polygon is hidden, the label that was for it remains on the view. When I re-show the shape it gets a NEW label which moves with it, but the old one remains on the view and just stays in a static location regardless of the zooming or panning of the view.

I tried to manually hide it or remove it but nothing seems to work. This is how I tried to do that:

export function setRegionVisibility(
  editor: Autodesk.Extensions.Edit2D,
  region: RegionData,
  geometry: SpaceGeometry,
  // @ts-ignore
  tagRule: Autodesk.Edit2D.ShapeLabelRule | undefined,
  visible: boolean
): void {
  const shape = editor.defaultContext.layer.shapes.find(
    (s) => s.id === region.itemIds[0]
  );
  if (shape == null) {
    return;
  }
  // @ts-ignore
  shape.visible = visible;
  let label: any;
  for (let labelsKey in tagRule.labels) {
    if (labelsKey === shape.id.toString()) {
      label = tagRule.labels[labelsKey];
    }
    console.log(tagRule.labels);
  }
  if (label != null) {
    label.visible = visible;
    console.log(label);
    label.dtor();
    label.update();
    label.layer.update();
  }
  editor.defaultContext.layer.update();
  return;
}

Any idea how to make that ghost go away?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文