An elm-ui component that supports dragging and scrolling with the mouse to pan and zoom.
This is a fork from JohanWinther/elm-pan-and-zoom. All the credit goes to the original author. This fork just adapts the view-function to integrate well with elm-ui.
The component constists of a Viewport
that contains a "content box":
╔═════════════════════════╗
║ ║
║ ┌────────────────────║╌╌┐
║ │ ║ ┊
║ │ ║ ┊
║ │ content ║ ┊
║ │ ║ ┊
║ │ ║ ┊
╚═════════════════════════╝ ┊
└╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┘
╔═══╗
║ ║ = viewport
╚═══╝
┌───┐
│ │ = content box
└───┘
The content box can be moved by dragging anywhere in the viewport with the mouse.
x = mouse pointer
╔═════════════════════════╗
║ x--> ║
║ ┌─────────┐--> ║
║ │ │--> ║
║ │ │--> ║
║ │ │--> ║
║ └─────────┘--> ║
║ ║
╚═════════════════════════╝
╔═════════════════════════╗
║ x ║
║ ┌─────────┐ ║
║ │ │ ║
║ │ │ ║
║ │ │ ║
║ └─────────┘ ║
║ ║
╚═════════════════════════╝
The content box can also be moved by dragging the box itself.
╔═════════════════════════╗
║ ║
║ ┌─────────┐----------╫----->
║ │ x-------┼--------> ║
║ │ │----------╫----->
║ │ │----------╫----->
║ └─────────┘----------╫----->
║ ║
╚═════════════════════════╝
╔═════════════════════════╗
║ ║
║ ┌──║╌╌╌╌╌╌┐
║ │ x║ ┊
║ │ ║ ┊
║ │ ║ ┊
║ └──║╌╌╌╌╌╌┘
║ ║
╚═════════════════════════╝
The content box can be scaled by scrolling the mouse wheel anywhere in the viewport.
╔═════════════════════════╗
║ ║
║ x─────────┐ ║
║ │ │ ║
║ │ │ ║
║ │ │ ║
║ └─────────┘ ║
║ ║
╚═════════════════════════╝
╔═════════════════════════╗
║ ║
║ x────────────────────║───┐
║ │ ║ ┊
║ │ ║ ┊
║ │ ║ ┊
║ │ ║ ┊
╚═════════════════════════╝ ┊
┊ ┊
┊ ┊
┊ ┊
└╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┘
When zooming by scrolling content box will always scale relative to the mouse pointer.
╔═════════════════════════╗
║ ║
║ ┌─────────┐ ║
║ │ │ ║
║ │ │ x ║
║ │ │ ║
║ └─────────┘ ║
║ ║
╚═════════════════════════╝
╔═════════════════════════╗
║ ║
║ ║
║ ┌────┐ ║
║ │ │ x ║
║ └────┘ ║
║ ║
║ ║
╚═════════════════════════╝
It is possible to programatically apply transformations with
and access the internal state with