getAttachmentPositionsInExpImage Method

Description

Returns the positions of attachment symbols in the current diagram within the bounds of an exported image.

Syntax

.getAttachmentPositionsInExpImage(/* Object */ options)

Parameters

options: Object

A hash of the option values that were used to create the exported image. For more information, see the exportImage() method.

Returns

Array

A array of objects that each contain the location of an attachment symbol within an exported image generated with the specified options.

Each of these objects is a hash of the form:

id — The unique string id of an attachment referenced by the attachment symbol.

label — The text label of the attachment referenced by the attachment symbol.

top — Top coordinate (Y) of the attachment symbol.

left — Left coordinate (X) of the attachment symbol.

bottom — Bottom coordinate (Y) of the attachment symbol.

right — Right coordinate (X) of the attachment symbol.

Note that all coordinates are in pixels relative to the top left corner of the image with positive values down and right.

Example 1 — Export a PNG Image and Get Attachment Locations

/*
    This example assumes esdEditor is an initialized
    ESDWeb object and that a diagram is loaded
*/

// Export the diagram as a png image.
var exportOptions = {
	format: 'image/png',
	margin: 10,
	width: 800,
	height: 600,
	includeStructureDimensions: true,
	includeFieldMeasurements: true
};

esdEditor.exportImage(exportOptions, onExport, onError);

function onExport(image) {
	// The export was successful...
	// The parameter "image" contains a 800 x 600 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.

	// Get the attachment positions in the exported image. Note that we must use the same
	// options that were used to create the image.
	var attachmentPositions = esdEditor.getAttachmentPositionsInExpImage(exportOptions);

	// Both the image and the positions of attachment symbols in the image are now available.
	...
}

function onError(error) {
	alert('Export failed: ' + error.message;
}