首页 > 解决方案 > `viewer.navigation.fitBounds` 没有边距

问题描述

我想创建特定图像部分的高分辨率屏幕截图。我的方法是从我的部分的每个四分之一(左上、右上、左下、右下)创建多个屏幕截图。为此,我正在使用viewer.navigation.fitBounds. 但是,似乎有一点我想摆脱的余量,因为我无法轻松地将四分之一屏幕截图拼接在一起。

viewer.navigation.fitBounds应该完全符合界限,因此,这是我这边的使用错误吗?

例子

黑色标记代表我在调用时使用的右上角屏幕截图的边界框Autodesk.Viewing.ScreenShot.getScreenShotWithBounds。但是,黑色标记与顶部和底部边框之间留有一些空间。 在 fitBounds 之后显示查看器

标签: autodesk-forgeautodesk-viewer

解决方案


该函数Navigation.fitBounds使用Navigation.computeFit以下边距设置,默认情况下每边增加 5%:

  // Change these constants to alter the margin ratios (think, percentages/100).
  // The margins are how much to add above and below. For example, setting the
  // margin to 25% (0.25) would give a margin of 25% above, 50% in the middle for
  // content, and 25% below. This value should never be >= 0.50, as that would
  // leave no area for the content to display.
  // The offsets are how much to shift the view. For example, shifting 50% (0.50)
  // vertically would move the displayed area such that only the bottom half of
  // the drawing area would be seen.
  this.FIT_TO_VIEW_VERTICAL_MARGIN = 0.05;
  this.FIT_TO_VIEW_VERTICAL_OFFSET = 0.00;
  this.FIT_TO_VIEW_HORIZONTAL_MARGIN = 0.05;
  this.FIT_TO_VIEW_HORIZONTAL_OFFSET = 0.00;

您可以在调用之前在任何地方设置这些变量viewer.navigation.fitBounds

const viewer = NOP_VIEWER; // your viewer instance
viewer.navigation.FIT_TO_VIEW_VERTICAL_MARGIN = 0.0;
viewer.navigation.FIT_TO_VIEW_HORIZONTAL_MARGIN = 0.0;

推荐阅读