Compare
Create visual file comparisons from two source files using the SDK compare interface.
Use viewer.compare.compare({ backgroundUrl, overlayUrl }) to create a visual comparison from two file sources.
Compare commands are available after the viewer is mounted and Canvas is ready. In SDK 2.2.2, await the returned Promise<ComparisonResult> to receive the generated comparison result and its outputFileUrl. viewer.compare.save({ outputName }) remains deprecated compatibility behavior and is not part of new-integration workflows.
Because comparison calls report completion asynchronously, subscribe to the terminal compare event channels before executing a compare action:
viewer.compare.compare({ backgroundUrl, overlayUrl })returnsPromise<ComparisonResult>and resolves after a payload-bearingcomparisonCompletefollowed byprogressEnd.- The promise rejects on comparison errors, timeout, disconnect, or invalid input.
- Use
progressStart,comparisonComplete,comparisonError, andprogressEndfor observable UI state. Do not use documentfileReadyevents as compare completion.
Execute visual diff generation by passing background and overlay URLs:
- Canvas loads the background and overlay files, builds the comparison overlay, opens the generated file, and emits
comparisonCompletefollowed byprogressEnd. The returned promise resolves withComparisonResultafter that lifecycle.
If files reside in the Canvas file base directory, you can query using file names directly:
Use viewer.compare.align({ backgroundUrl, overlayUrl, alignArray }) with up to two verified point objects when the host already has alignment data. Omit alignArray when the operator should select matching points in Canvas.
Interactive alignment can emit an initial comparisonComplete without a result while Canvas waits for point selection. The later payload-bearing event identifies the generated aligned comparison.
Supported compare configuration payloads and shapes:
The SDK performs validation before triggering the Canvas comparing commands:
- Background source (
backgroundUrlorbackgroundFileName) is required. - Overlay source (
overlayUrloroverlayFileName) is required. - Background and overlay values must be different.
dpimust be a positive finite number if provided.backgroundColor,overlayColor, andequalColormust be valid hex orrgb(...)colors.outputNamemust be a non-empty string if provided.alignArray, when provided, must contain no more than two point objects.
Complete integration code setup for Vanilla HTML/JS environments:
Broker message mapping for compare workflows:
viewer.compare.compare({ backgroundUrl, overlayUrl })maps tocompare.viewer.compare.on("comparisonComplete", handleComparisonComplete)listens tocomparisonComplete.viewer.compare.on("comparisonError", handleComparisonError)listens tocomparisonError.viewer.compare.on("progressStart", handleProgressStart)andviewer.compare.on("progressEnd", handleProgressEnd)report Canvas activity.
