Enable snapping for measurement tools programatically

Product: Webviewer

Product Version: 10.7

Please give a brief summary of your issue:
Enable snapping for measurement tools programatically

I’d like to enable this by default in our webviewer UI :slight_smile:

I can’t find anything in the documentation about this. Any idea?


Hello Michael,

We actually have another community post you can refer to that shows you how to enable snapping. Please make sure to turn on fullAPI.

However, we are currently aware of the issue in the UI where the “Enable snapping for measurement tools” checkbox will not update accordingly.

Best Regards,

Hello Darian

I had seen this post but it didn’t work like this when using webviewer in an angular / typescript environment because getTool returns a Tool object and not an object type with the setsnap method.

I did ultimately manage to do it with some ugly casting

      const distanceMeasurementTool : Core.Tools.DistanceMeasurementCreateTool = documentViewer.getTool('AnnotationCreateDistanceMeasurement') as Core.Tools.DistanceMeasurementCreateTool;

But this doesn’t work.

  • When enabling snapping for measurement tools in the UI you have a visual orange feedback when you hover your mouse over lines, like this (bottom right of the measure) :

When setting snapMode, it doesn’t do anything like that, plus the UI control is not updated as you said yourself.

This is definitely not the same behaviour.

Addendum : i tried using the various SnapModes with no success.

Even worse, when setting a snapMode as proposed, the UI control to enable snapMode for measurement tools doesn’t do anything anymore.

Hello Michael,

It looks like the types may not have been generated correctly in your project. Could you add a // @ts-ignore before calling setSnapMode?

      documentViewer.addEventListener('documentLoaded', async () => {
        const tool = instance.Core.documentViewer.getTool("AnnotationCreateDistanceMeasurement");
        // @ts-ignore

Best Regards,

I’m sorry but it’s like you didn’t read my answer or I was not clear…

I did manage to make it work with some type casting but it doesn’t do anything. See what I said above.
Using setSnapMode (SnapModeS.DEFAULT) programatically doesn’t achieve the same result as ticking the box to enable snapping for measurement.

Hello Michael,

Could you clarify what you mean by it doesn’t achieve the same result? Would you be able to provide a video showing the disparity?

I tried using the code on the previous post to enable the snap mode and tested it on a sample PDF without any issues.

Best Regards,

Hello Darian

There was something interfering in my code because I declared the tool too early I think.
It works and I have a ticket opened to fix the UI to match this option when activated programatically.