exportImage

exportImage Method

Description

Exports the current drawing as an image. The resulting image is passed into the onSuccess function as a Base64 encoded string.

.exportImage(/* Object */ options, /* Function */ onSuccess, /* Function */ onError)

Parameters

options Object

An object containing properties that control the image export operation. These properties are:

onSuccess Function

This function will be called when diagram export completes successfully. It will be passed two parameters:

  1. A base 64 encoded image of the diagram as specified in options.
  2. An object containing information related to the diagram and exported image as specified in the options parameter. The object may contain these properties:
    • fieldMeasurements

      An object containing the measurement data. This is present when the option includeFieldMeasurements is true.

      Note: the measurement layer data includes formatted and numeric versions of length and distance values.

      Here is an example of measurement data:

    {
        units: "feetAndInches",
            stationLines: [
            {
                stationLineIncrement: 0,
                formattedStationLineIncrement: "0'",
                markers: [
                    {
                        id: "1",
                        description: "Station Line One",
                        station: 10,
                        formattedStation: "10'",
                        distance: 10,
                        formattedDistance: "10'",
                        direction: "R"
                    }
                ]
            }
        ],
            triangulationMeasurements: {
            markerPoints: [
                {
                    id: "1",
                    description: "Measurement Point One",
                    refPt1: "A",
                    refPt2: "B",
                    distance1: 20,
                    formattedDistance1: "20'",
                    distance2: 20,
                    formattedDistance2: "20'",
                    direction: "L"
                }
            ]
        }
    }

onError Function

A function that accepts one parameter, an Error object. This function will be called if the export fails. The passed Error object indicates the nature of the failure. This function may return true to indicate that the error has been handled. If the function does not return true, the error will be passed on to the built-in error handler.

Example 1 — Export a PNG Image

/*
    This example assumes editor is an initialized
    ESDWeb object and that a diagram is loaded
*/
 
function onExport (image) {
    // The export was successful...
    // The parameter "image" contains a 500 x 500 base 64
    // encoded PNG image of the diagram.
    // Any operations that depend on the exported image must
    // be done within the body of this callback function.
}
 
function onError (error) {
    alert('Export failed: ' + error.message);
}
 
// Export the diagram as a png image.
editor.exportImage({
    format: 'image/png',
    margin: 10,
    width: 500,
    height: 500
}, onExport, onError);

Example 2 — Export and Display a JPG Image

/*
    This example assumes editor is an initialized
    ESDWeb object and that a diagram is loaded
*/
 
function onExport (image) {
    // 'image' is the id of an existing <img> element in the DOM.
    var img = document.getElementById('image');
 
    // Set the image to be shown by the element.
    img.src = image;
}
 
function onError (error) {
    alert('Export failed: ' + error.message);
}
 
// Export the diagram as a jpeg image, ignoring map update errors.
editor.exportImage({
    format: 'image/jpeg',
    imageQuality: 0.9,
    margin: 10,
    width: 600,
    height: 400,
    includePrefix: true
}, onExport, onError);