Zoom fit-viewport not allowing for overlays

I am using the following code to fit the diagram to the viewport:

BpmnDiagram.get(‘canvas’).zoom(‘fit-viewport’, ‘auto’);

The problem is that is does not allow space for any overlays so the user needs to scroll out, can we implement this functionality?

You can set specific zoom levels using the same canvas.zoom() API. So if you want to zoom out a bit more, you can try it like this:

  const zoom = canvas.zoom("fit-viewport");
  canvas.zoom(zoom - 0.05);

Thanks Martin, I understand this is possible. However, it does not fix the core issue as my overlays are data driven and can be different sizes. I am also trying to maximize the viewport with some large diagrams, so zooming further out in all directions even if overlays might not exist in that location is not ideal.
I now have a working solution to loop through all of the overlays and set the zoom and canvas scroll to ensure they are all fully visible, but it would be great to see a better option.

@Kieran Happy to take a contribution to improve this.

For example, we could take overlays + their sizes into account when computing the canvas bounding box. Another alternative could be to zoom + dynamically position overlays to ensure they are within the viewbox.