title: PaperJS zoom and pan
body: <p>I have successfully implemented a zooming feature based on <a href="https://matthiasberth.com/tech/stable-zoom-and-pan-in-paperjs" rel="nofollow noreferrer">this example</a></p>
  
  <pre><code> zoom: function(delta, point){
      if (!delta) return;
  
      var
          oldZoom = paper.view.zoom,
          oldCenter = paper.view.center,
          viewPos = paper.view.viewToProject(point);
          newZoom = delta &gt; 0 ? oldZoom * 1.05 : oldZoom / 1.05;
  
      if (!this.allowedZoom(newZoom)) return;
  
      var
          zoomScale = oldZoom / newZoom,
          centerAdjust = viewPos.subtract(oldCenter),
          offset = viewPos.subtract(centerAdjust.multiply(zoomScale)).subtract(oldCenter);
  
      paper.view.center = view.center.add(offset);
  },
  
  allowedZoom: function(zoom){
      zoom = Math.max(zoom, this.settings.minZoom);
      zoom = Math.min(zoom, this.settings.maxZoom);
  
      if (zoom !== paper.view.zoom)
      {
          paper.view.zoom = zoom;
          return zoom;
      }
      return null;
  }
  </code></pre>
  
  <p>however this does not take into account the position of the view when you zoom out back to the original <code>scale = 1</code>. What I mean is I would like the view to stick to the canvas edge. </p>
  
  <p>Here's a screenshot<a href="https://i.stack.imgur.com/2Vh9i.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2Vh9i.jpg" alt="enter image description here"></a></p>