Last updated

Export to CGM

The following tutorial shows how to export the HTML canvas of an Annotated Widget a CGM file using a Cross Plot as an example Widget. For more information on exporting please visit the Export to PDF .

Several object types (AbstractDocumentElement, Group, and Shape) can also be exported to a file with CGM formatting. The example below walks through how to create BinaryStream and CgmExport objects that are needed to export to a CGM file. Exporting to a CGM file will use the model's virtual limits.

import { CgmExport } from "@int/geotoolkit/cgm/CgmExport.ts";
import { BinaryStream } from "@int/geotoolkit/util/stream/BinaryStream.ts";
import { loadFont } from "@int/geotoolkit/util/fontloader.ts";
import { Plot } from "@int/geotoolkit/plot/Plot.ts";
import { createWidget } from "/src/code/Carnac/Export/common.ts";
function exportToCGM(plot) {
  new CgmExport().exportToCgmStream({
    "root": plot.getRoot(),
    "stream": new BinaryStream({
      "filename": "crossplot.cgm",
      "type": "cgm"
    })
  }).save();
}
function createScene(canvas) {
  const widget = createWidget(true);
  const plot = new Plot({
    "canvaselement": canvas,
    "root": widget
  });
  loadFont("src/assets/fonts", "roboto").then(() => {
    plot.update();
  });
  return plot;
}
export { createScene, exportToCGM };

createScene(document.querySelector('[ref="plot"]'));