Overlapped Annotations doesn't have measurements in it (getContents() is undefined)

I have used this -

const tool = this.viewerInstance.docViewer.getTool(‘AnnotationCreateAreaMeasurement’);
tool.setAllowCreationOverAnnotation(true);
tool.setStyles(() => ({
Scale: [[1, ‘m’], [10, ‘m’]],
Precision: 0.01,
Opacity: 0.65,
FillColor: new this.viewerInstance.Annotations.Color(204, 251, 255)
}));

Here I am not getting the annotation.getContents(). Its undefined and also scale and precision is undefined. I want it to work same as other non overlapped annotations. I want to get the measured value (… sq. meter) of a overlapped annotation(small top annotation in fig.) as an independent annotation with all the scale and precision data.

A small code snippet to solve this would be appreciable.

image

Hey there,

I cannot reproduce this issue. Are you just creating the annotations in the UI or are you creating them programmatically?

Can you share your code that you are using the get the contents of the annotations as well.

Thanks,
Logan

I am creating the annotations in the UI using the setToolMode(tool). Check this -

const tool = this.viewerInstance.docViewer.getTool(‘AnnotationCreateAreaMeasurement’);
tool.setAllowCreationOverAnnotation(true);
tool.setStyles(() => ({
Scale: [[1, ‘m’], [10, ‘m’]],
Precision: 0.01,
Opacity: 0.65,
FillColor: new this.viewerInstance.Annotations.Color(204, 251, 255)
}));
this.viewerInstance.docViewer.setToolMode(tool);

If I create annotations over another annotation (filled - area), then I am unable to get the measured content like (… sq. m ) of that drawn annotation which I had drawn over the annotation

Hi,

Can you share your code that you are using the get the contents of the annotations as well.

I cannot reproduce your issue so it would be useful for you to send us the code you are using to get the contents.

Thanks!
Logan

public handleAnnotationChanged() {
    let annotationsArray: Array<ViewerAnnotation>;
    this.viewerInstance.annotManager.on(AnnotationManagerConstants.ANNOTATION_CHANGED, (annotations, action, {imported}) => {
      if (imported) {
        return;
      }
      if (action === AnnotationManagerConstants.ACTION_ADD || (action === AnnotationManagerConstants.ACTION_UPDATE &&
**        WorkAreaComponent.highlightingAnnotationFlag === false) ||**
**        (action === AnnotationManagerConstants.ACTION_DELETE && this.annotationDeleted === false)) {**
**        if (annotations[0].ToolName === Constants.STAMP || annotations[0].ToolName === Constants.STAMP_2**
**          || annotations[0].ToolName === Constants.POLYLINE**
**          || annotations[0].ToolName === Constants.POLYGON**
**          || annotations[0].ToolName === Constants.CLOUD || annotations[0].ToolName === Constants.POLYCLOUD) {**
**          annotationsArray = [];**
**          annotations.forEach(annotation => {**
**            this.viewerInstance.annotManager.exportAnnotations({annotList: [annotation]}).then(xfdf => {**
**              annotationsArray.push(new ViewerAnnotation(**
**                annotation.Id,**
**                annotation.ToolName,**
**                **annotation.getContents()** || '1',**
**                action,**
**                xfdf));**
**            });**
**          });**
          this.annotationChanged.emit(annotationsArray);
        }
      }
    });
  }

Hi,

In the future, please wrap codeblocks with triple backticks as it makes it much easier for us to read.

Hi,

I still cannot reproduce your issue, however it looks like you have a timing issue in your code that might be causing the issue.

exportAnnotations is async but annotations.forEach is syncronous, meaning you are calling this.annotationChanged.emit(annotationsArray); before all the promises are resolved.

You need to wait for all the exportAnnotations promises to resolve before you can call this.annotationChanged.emit(annotationsArray);.

You could update your code to something like this:

const promises = annotations.map(annotation => {
  return this.viewerInstance.annotManager.exportAnnotations({annotList: [annotation]}).then(xfdf => {
    annotationsArray.push(new ViewerAnnotation(
      annotation.Id,
      annotation.ToolName,
      annotation.getContents() || '1',
      action,
      xfdf));
  });
});
Promise.all(promises).then(() => {
   this.annotationChanged.emit(annotationsArray);
})

Let me know if this helps,
Thanks,
Logan

Thanks, but it didn’t helped me either.

Here is that overlapped annotation’s xfdf. It doesn’t contain scale, precision and getContents(). All are undefined.

Here is the non-overlapped annotation’s xfdf. It contains all the necessary information that we need.

.

Original Fig. (Triangle one was the overlapped annotation and square one was the non-overlapped annotation)
image

Hi,

I am still unable to reproduce your issue. One other thing I see with your code is that you’re only checking the type of first annotation in the array, but then looping over all of them and trying to call getContents etc. If an annotation that is not a measurement annotation is in that array, getContents() etc would be expected to be null.

Can you make sure all annotations in the annotations array are actually what you expect?

Thanks,
Logan

Yes, I have checked it properly. Please see the above attached xfdf datas of the two annotations. In that one annotation has all the necessary data like scale precision and sq.m. while other annotation doesn’t have all these scale and precisions and sq.m…
Above both annotations have same ToolName.

Still unable to get embedded/ overlapped annotation’s proper xfdf data.

Hi there,

I talked to a few members of the team and was informed that this was a known bug, but will be fixed in version 7.1 (which will be released today).

Could you please upgrade to version 7.1 when it’s released? We will announce it in #announcements.

Thanks!