Zoom to a specific element


I am trying to zoom and center on a specific element. I have tried the solutions from previous posts like:

Neither of which has worked for me, the view does not appear to change when the zoom function is called. Here is my code:

viewer = new BpmnModeler(options);
viewer.importXML(toImport, (err) => {
    const canvas = viewer.get('canvas');
    const elementRegistry = viewer.get('elementRegistry');
    const element = elementRegistry.get('MyTaskId');
    canvas.zoom(1.0, element);
    // OR
    canvas.zoom(1.0, {x : element.x, y : element.y});

Any help would be appreciated.


Have you had a look at how this functionality is implemented in diagram-js SearchPad?


I did see that, and I ended up creating me own function that did something similar. Thanks!