Zoom to selected node using zoomSlider extension

I want to zoom to the selected node when I doing zoom using zoom in(+) and zoom out(-) button or the slider.

What do you want to do when there are multiple nodes that are selected? I’ll assume you only care about the first Part that is selected. And that when there is nothing selected the zooming behavior is normal.

I think this gets the results that you are asking for:

  $(go.Diagram, "myDiagramDiv",
    {
      "ChangedSelection": e => {
        const part = e.diagram.selection.first();
        if (!part) {
          e.diagram.zoomPoint = new go.Point(NaN, NaN);
        }
      },
      "ViewportBoundsChanged": e => {
        const part = e.diagram.selection.first();
        if (part) {
          e.diagram.zoomPoint = e.diagram.transformDocToView(part.location);
        }
      },
      . . .
    })

Note that control-mouse-wheel zooming still behaves the same way – it also sets Diagram.zoomPoint to keep the document point where the mouse is at the same point in the viewport.

Thanks it worked.@walter