# Zoom fit-viewport not allowing for overlays

**URL:** <https://forum.bpmn.io/t/zoom-fit-viewport-not-allowing-for-overlays/9580>\
**Category:** Developers\
**Created:** [July 28, 2023, 7:18am UTC](https://forum.bpmn.io/t/zoom-fit-viewport-not-allowing-for-overlays/9580 "2023-07-28T07:18:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kieran](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/k/3d9bf3/32.png) [@Kieran](https://forum.bpmn.io/u/Kieran)\
**Post date:** [July 28, 2023, 7:18am UTC](https://forum.bpmn.io/t/zoom-fit-viewport-not-allowing-for-overlays/9580/1 "2023-07-28T07:18:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Martin](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@Martin](https://forum.bpmn.io/u/Martin)\
**Post date:** [July 28, 2023, 9:15am UTC](https://forum.bpmn.io/t/zoom-fit-viewport-not-allowing-for-overlays/9580/2 "2023-07-28T09:15:29Z")

</div>

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:

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

```

> **[clever-tree-6vyx2n - CodeSandbox](https://codesandbox.io/s/clever-tree-6vyx2n?file=%2Fsrc%2Findex.js:565-657)**
>
> clever-tree-6vyx2n using bpmn-js

---

<div class="post-metadata">

**Author:** ![Kieran](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/k/3d9bf3/32.png) [@Kieran](https://forum.bpmn.io/u/Kieran)\
**Post date:** [July 30, 2023, 11:37pm UTC](https://forum.bpmn.io/t/zoom-fit-viewport-not-allowing-for-overlays/9580/3 "2023-07-30T23:37:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [August 22, 2023, 7:55am UTC](https://forum.bpmn.io/t/zoom-fit-viewport-not-allowing-for-overlays/9580/4 "2023-08-22T07:55:17Z")

</div>

> [@Kieran](#):
>
> 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.

@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.

---

<div class="post-metadata">

**Author:** ![barmac](https://forum.bpmn.io/user_avatar/forum.bpmn.io/barmac/32/974_2.png) [@barmac](https://forum.bpmn.io/u/barmac)\
**Post date:** [July 9, 2025, 10:11am UTC](https://forum.bpmn.io/t/zoom-fit-viewport-not-allowing-for-overlays/9580/6 "2025-07-09T10:11:59Z")

</div>

Closed on July 9, 2025, 10:11am UTC

Closing old topics.
