Options
All
  • Public
  • Public/Protected
  • All
Menu

"dwg" is short for "drawing", it is a file format saved by AutoCAD. And "dxf" is data exchange format, which can be converted from a dwg file. We cannot read dwg directly, and need to convert it to dxf first via ODA.

Supported dxf version: AutoCAD 2018. Both binary and ascii are supported.

Json Encoding: UTF-8 encoding without BOM

Coordinate system: right-handed, y-up

About units:

  • The unit of distance follows the master dxf file's unit
  • The unit of area follows the master dxf file's unit
  • The unit of angle is "degree", counterclockwise
  • The unit of time is "second"

Color: use rgb/rgba, values between 0-1

About Measurement in DxfViewer:

  • A measurement is generated by DxfViewer.
  • Measurements data should be stored by users, so users can restore measurements data into DxfViewer later.
  • DxfViewer manages measurements data, it can be created, removed, hidden, etc.
  • DxfViewer doesn't maintain the relationship between measurement and layout.

About Markup in DxfViewer: Markup is pretty similar to measurement.

About Hotpoint in DxfViewer:

  • A hotpoint is created and stored by user.
  • A hotpoint can be added to, and removed from DxfViewer.
  • Caller should set a hotpointId that is unique in the session of current DxfViewer.
  • DxfViewer doesn't hide a hotpoint, user is able to do it.
  • DxfViewer doesn't maintain the relationship between hotpoint and layout.

About layouts

  • Each layout has its own home view.
  • When switching to another layout, it clears all measurements, markups and hotpoints.
  • When switching to another layout, it deactivates any in-progress operation like measurement, markup, etc.

About overlay

  • It supports to add as many models as user want, as long as the browser has sufficient memory, cpu/gpu, etc.
  • The first model is called "master" model, others are called "overlay" models.
  • It ignores an overlay model's paper space.
  • An overlay model's unit should be converted to master model's unit if they are not the same.
  • We'll append modelId as prefix for getLayers()

About comparision

  • It compares just "Model" spaces.
  • It compares entities with the same handles and types.
  • It compares entities' geometries, positions, scales, etc.
  • It ignores a layer's visibility, freeze settings.
  • It ignores an entity's properties, like linetype, line width, fill pattern, font, color, etc.
  • It ignores spatial filters (xclip) of block references.
  • It ignores layer relative operations, like moving an entity to another layer, changing a layer color, etc.
  • By default, an "Added" entity is rendered in green, a "Removed" entity is in red, a "Modified" entity is composed by two parts, one "Removed" and another "Added".

About undo/redo

  • It supports undo/redo for measurement and markup operations. E.g., creating/deleting/moving a markup.
  • Setting/removing a batch of measurements or markups will be taken as one operation.
  • Switching to another layout clears all undo/redo history.

About OSnap

  • It supports snapping to the end points and middle point of a line.
  • It supports snapping to the intersection point of two lines.
  • It supports snapping to the foot of perpendicular against a line.
  • It supports snapping to any point along a line.
example
const viewerCfg = {
containerId: "myCanvas",
enableSpinner: true,
enableLayoutBar: true,
};
const modelCfg = {
modelId: "id_0",
name: "sample",
src: "http://www.abc.com/sample.dxf",
}
const fontFiles = ["http://www.abc.com/hztxt.shx", "http://www.abc.com/simplex.shx"];

const viewer = new DxfViewer(viewerCfg);
await viewer.setFont(fontFiles);
await viewer.loadModelAsync(modelCfg);

Hierarchy

Index

Constructors

Properties

container?: HTMLElement

Methods

  • activateLayout(layoutName: string): void
  • description

    {en} Activates a layout.

    description

    {zh} 激活布局。

    example
    viewer.activateLayout('Layout1');
    

    Parameters

    • layoutName: string
      • {en} The name of the layout to be activated.
      • {zh} 要激活的布局名称。

    Returns void

  • description

    {en} Activates markup feature.

    description

    {zh} 激活标注功能。

    example
    const markupType = MarkupType.Arrow;
    viewer.activateMarkup(markupType);
    deprecated

    Parameters

    • type: MarkupType
      • {en} markup type.
      • {zh} 标注类型。

    Returns void

  • description

    {en} Activates one of "Distance", "Area" or "Angle" measurement

    description

    {zh} 激活"距离", "面积" 或者 "角度"测量

    example
    viewer.activateMeasurement(MeasurementType.Distance);
    
    deprecated

    use MeasurePlugin instead

    Parameters

    Returns void

  • description

    Add model data to viewer.

    Parameters

    Returns void

  • addPlugin(plugin: Plugin<{}>): void
  • Installs a Plugin.

    Parameters

    Returns void

  • cancelMeasurement(): void
  • description

    {en} Cancels current measurement. This won't deactivate measurement, rather, you can start a new measurement.

    description

    {zh} 取消当前的测量绘制。这并不会退出测量,用户可以开始一个新的测量。

    deprecated

    use MeasurePlugin instead

    Returns void

  • clearMarkups(): void
  • description

    {en} Clears markups.

    description

    {zh} 清除所有标注。

    example
    viewer.clearMarkups();
    

    Returns void

  • clearMeasurements(): void
  • description

    {en} Clears measurement results.

    description

    {zh} 清除测量结果。

    example
    viewer.clearMeasurements();
    
    deprecated

    use MeasurePlugin instead

    Returns void

  • clearPlugins(): void
  • Clears all plugins. A plugin is not created by viewer, thus, won't be destroyed by viewer.

    Returns void

  • deactivateMarkup(): void
  • description

    {en} Deactivates markup feature.

    description

    {zh} 退出标注功能。

    example
    viewer.deactivateMarkup();
    

    Returns void

  • deactivateMeasurement(): void
  • description

    {en} Deactivates measurement.

    description

    {zh} 退出测量。

    example
    viewer.deactivateMeasurement();
    
    deprecated

    use MeasurePlugin instead

    Returns void

  • destroy(): void
  • description

    {en} Destroys DxfViewer.

    description

    {zh} 销毁 DxfViewer。

    example
    viewer.destroy();
    

    Returns void

  • findPlugin(id: string): undefined | Plugin<{}>
  • Finds a Plugin.

    Parameters

    • id: string

    Returns undefined | Plugin<{}>

  • getActiveLayoutName(): undefined | string
  • description

    {en} Gets active layout.

    description

    {zh} 获取当前布局。

    example
    const activeLayout = viewer.getActiveLayoutName();
    console.log(activeLayout);

    Returns undefined | string

    • {en} Active layout name or undefined.
    • {zh} 当前激活的布局名称或undefined。
  • description

    {en} Gets active markup type.

    description

    {zh} 获取激活的标注类型。

    example
    const markupType = viewer.getActiveMarkupType();
    console.log(markupType);

    Returns undefined | MarkupType

    • {en} markup type.
    • {zh} 标注类型。
  • description

    {en} Gets active measurement type.

    description

    {zh} 获取当前激活的测量类型。

    example
    const measurementType = viewer.getActiveMeasurementType();
    console.log(measurementType);
    deprecated

    use MeasurePlugin instead

    Returns undefined | MeasurementType

    • "Distance", "Area" or "Angle" or undefined
  • getCurrentViewExtent(): Box2
  • description

    {en} Gets current view extent. This is useful for user to save this value as a viewpoint, and jump to this viewpoint next time.

    description

    {zh} 获取当前视图范围。 用户可使用该接口获取当前视口范围,并在适当的场景下跳转到该视口范围。

    example
    const box = viewer.getCurrentViewExtent();
    console.log("Current view extent:", box);

    Returns Box2

  • getFont(): undefined | FontManager
  • Returns undefined | FontManager

  • description

    {en} Gets dxf layers.

    description

    {zh} 获取dxf图层。

    example
    const dxfLayers = viewer.getLayers();
    for (let i = 0; i < dxfLayers.length; ++i) {
    const layers = dxfLayers[i].layers;
    const layerNames = Object.keys(layers).sort();
    console.log(layerNames);
    }

    Returns (DxfLayers | PdfLayers)[]

    • {en} Dxf layers.
    • {zh} dxf图层。
  • getLayoutNames(): string[]
  • description

    {en} Gets layout names of the master model.

    description

    {zh} 获取主模型的布局名称。

    example
    const layoutNames = dxfViewer.getLayoutNames();
    console.log(layoutNames); // ['Model', 'Layout1', 'Layout2']

    Returns string[]

    • {en} Layout names of the master model.
    • {zh} 主模型的布局名称。
  • description

    {en} Gets all markups.

    description

    {zh} 获取所有标注数据。

    example
    const markupData = viewer.getMarkups();
    console.log(markupData);

    Returns DrawableData[]

    • {en} markup data array.
    • {zh} 标注数据数组。
  • description

    {en} Gets all measurements.

    description

    {zh} 获取所有测量数据。

    example
    const measurementData = viewer.getMeasurements();
    console.log(measurementData);
    deprecated

    use MeasurePlugin instead

    Returns DrawableData[]

    • {en} measurement data array.
    • {zh} 测量数据数组。
  • description

    {en} Gets screenshot of a rectangular area, or by box selecting an area. Returns an image in format of base64 string.

    description

    {zh} 获取矩形区域或者框选区域的截图。返回base64格式的图片。

    example
    // {en} Click on markup to take screenshot.
    // {zh} 点击批注截屏。
    const mode = ScreenshotMode.PickMarkup;
    viewer.getScreenshot(mode).then(data => console.log(data));
    // {en} Take screenshot by box selecting an area.
    // {zh} 根据用户的框选截屏。
    const mode = ScreenshotMode.BoxSelection;
    viewer.getScreenshot(mode).then(data => console.log(data));
    // {en} Take screenshot of the whole view.
    // {zh} 全屏截屏。
    const mode = ScreenshotMode.Default;
    viewer.getScreenshot(mode).then(data => console.log(data));
    deprecated

    use ScreenshotPlugin instead.

    Parameters

    • mode: ScreenshotMode = ScreenshotMode.BoxSelection
      • {en} screenshot mode("Default", "BoxSelection" and "PickMarkup").
      • {zh} 截图模式("全屏", "框选" 和 "选中批注")。

    Returns Promise<undefined | ScreenshotResult>

  • goToHomeView(): void
  • description

    {en} Moves camera to home view.

    description

    {zh} 移动相机到主视图.

    example
    viewer.goToHomeView();
    

    Returns void

  • loadModelAsync(modelCfg: DxfModelConfig, onProgress?: ((event: ProgressEvent<EventTarget>) => void)): Promise<void>
  • description

    {en} Loads a dxf file. The first loaded file will be taken as a "master" model. Any other files are non-master, we call "overlay" model. We'll load everything of a master model, including model and paper space. For an overlay model, we'll only load its model space. And its model space can only overly to master model's model space.

    description

    {zh} 加载 dxf 文件。 第一个加载的文件将被视为“主”模型。 任何其他文件都是非主文件,我们称之为“叠加”模型。 我们将加载主模型的所有内容,包括模型和图纸空间。 对于叠加模型,我们只会加载其模型空间。并且它的模型空间只能叠加到主模型的模型空间上。

    example
    const viewerCfg = {
    containerId: "myCanvas",
    };
    const modelCfg = {
    modelId: "id_0",
    name: "dxf 0",
    src: "http://www.abc.com/sample.dxf",
    }
    const viewer = new DxfViewer(viewerCfg);
    await viewer.loadModelAsync(modelCfg, (event) => {
    const progress = (event.loaded * 100) / event.total;
    console.log(`Loading progress: ${progress}%`);
    });
    console.log("Loaded");

    Parameters

    • modelCfg: DxfModelConfig
      • {en} The configuration of the model to be loaded.
      • {zh} 要加载的模型的配置。
    • Optional onProgress: ((event: ProgressEvent<EventTarget>) => void)
      • {en} A callback function to indicate the loading progress.
      • {zh} 用于指示加载进度的回调函数。
        • (event: ProgressEvent<EventTarget>): void
        • Parameters

          • event: ProgressEvent<EventTarget>

          Returns void

    Returns Promise<void>

  • removeMarkup(id: string): boolean
  • description

    {en} Removes a markup by markup id.

    description

    {zh} 根据标注id删除标注。

    example
    const markupId = "c6ea70a3-ddb0-4dd0-87c8-bd2491936428";
    viewer.removeMarkup(markupId);

    Parameters

    • id: string
      • {en} markup id.
      • {zh} 标注id。

    Returns boolean

    • {en} Whether remove successfully, true means success, false means failure.
    • {zh} 是否删除成功,true表示成功,false表示失败。
  • removeMeasurement(id: string): void
  • description

    {en} Removes a measurement by id.

    description

    {zh} 根据id删除测量数据。

    example
    const id = "c6ea70a3-ddb0-4dd0-87c8-bd2491936428";
    viewer.removeMeasurement(id);
    deprecated

    use MeasurePlugin instead

    Parameters

    • id: string
      • {en} Measurement data id.
      • {zh} 测量数据id。

    Returns void

  • removePlugin(plugin: Plugin<{}>): void
  • Uninstalls a Plugin, clearing content from it first.

    Parameters

    Returns void

  • setBackgroundColor(r: number, g: number, b: number): void
  • description

    {en} Sets background color.

    description

    {zh} 设置背景颜色。

    example
    // {en} Sets background to gray
    // {zh} 设置背景为灰色
    viewer.setBackgroundColor(0.5, 0.5, 0.5);

    Parameters

    • r: number
      • {en} Red channel value between 0 and 1.
      • {zh} 红色通道值,介于 0 和 1 之间。
    • g: number
      • {en} Green channel value between 0 and 1.
      • {zh} 绿色通道值,介于 0 和 1 之间。
    • b: number
      • {en} Blue channel value between 0 and 1. -{zh} 蓝色通道值,介于 0 和 1 之间。

    Returns void

  • setFont(urls: string[]): Promise<void>
  • description

    {en} Sets font. This needs to be called before loading a dxf, it won't affect any loaded text. It accepts shx or typeface formats. For typeface, it only support passing in 1 font file in the array for now.

    description

    {zh} 设置字体。 需要在加载dxf之前调用,不会影响已加载的文字。 支持shx或typeface格式。对于typeface,目前只支持传入1个字体文件。

    example
    viewer.setFont(["https://example.com/xxx.shx"]);
    

    Parameters

    • urls: string[]
      • {en} font file urls.
      • {zh} 字体文件链接。

    Returns Promise<void>

  • setLayerVisibility(layerName: string, visible: boolean, modelId?: string): void
  • description

    {en} Sets layer's visibility.

    description

    {zh} 设置图层的可见性。

    throws

    Error

    • {en}: Throws exception if given modelId doesn't exist.
    • {zh} 如果给定的modelId不存在,则抛出异常。
    example
    // Hides layer "0"
    viewer.setLayerVisibility("0", false);

    Parameters

    • layerName: string
      • {en} Layer's name to show or hide.
      • {zh} 要显示或隐藏的图层名称。
    • visible: boolean
      • {en} Layer's target visibility.
      • {zh} 图层的目标可见性。
    • Optional modelId: string
      • {en} Useful when more than one model is loaded, if not specified, will use the master model.
      • {zh} 当加载了多个模型时有用,如果未指定,将使用主模型。

    Returns void

  • description

    {en} Adds markups to active layout.

    description

    {zh} 添加标注到当前布局。

    example
    const markupData = [{
    type: "ArrowMarkup",
    id: "c6ea70a3-ddb0-4dd0-87c8-bd2491936428",
    lineWidth: 2,
    strokeStyle: "#ff0000",
    fillStyle: "#ff000030",
    points: [[0, 0], [1000, 1000]],
    }];
    viewer.setMarkups(markupData);

    Parameters

    • markupDataArray: DrawableData[]
      • {en} markup data array.
      • {zh} 标注数据数组。

    Returns void

  • description

    {en} Sets measurement data.

    description

    {zh} 设置测量数据。

    example
    const measurementData = [{
    type: "Distance",
    id: "c6ea70a3-ddb0-4dd0-87c8-bd2491936428",
    points: [[0, 1000], [5000, 1000]],
    }];
    viewer.setMeasurements(measurementData);
    deprecated

    use MeasurePlugin instead

    Parameters

    • measurementData: DrawableData[]
      • {en} measurement data array.
      • {zh} 测量数据数组。

    Returns void

  • description

    {en} Updates a markup.

    description

    {zh} 更新标注。

    example
    const markupData = {
    type: "ArrowMarkup",
    id: "c6ea70a3-ddb0-4dd0-87c8-bd2491936428",
    lineWidth: 3,
    strokeStyle: "#ff0000",
    fillStyle: "#ff000030",
    points: [[0, 0], [1000, 1000]],
    };
    viewer.updateMarkup(markupData);

    Parameters

    • markup: DrawableData
      • {en} markup data.
      • {zh} 标注数据。

    Returns boolean

    • {en} Whether update successfully, true means success, false means failure.
    • {zh} 是否更新成功,true表示成功,false表示失败。
  • zoomToBBox(bbox: Box2): void
  • description

    {en} Zooms to specific bounding box.

    description

    {zh} 缩放到指定的包围盒.

    example
    const box = { min: { x: 0, y: 0 }, max: { x: 10000, y: 10000} };
    viewer.zoomToBBox(box);

    Parameters

    • bbox: Box2
      • {en} 2d bounding box
      • {zh} 2d 包围盒。

    Returns void

  • zoomToExtent(): void
  • description

    {en} Zooms to view extent.

    description

    {zh} 缩放到视图范围.

    example
    viewer.zoomToExtent();
    

    Returns void

  • zoomToRect(): void
  • description

    {en} Asks user to select a box area, and zooms to it.

    description

    {zh} 询问用户选择一个框选区域,然后缩放到该区域。

    example
    viewer.zoomToRect();
    

    Returns void

Generated using TypeDoc