For those cases when you need to implement something GoogleMaps-like
Working on some project I had to implement a intuitive navigation on the canvas. This library provides exactly that. Use it like this:
<!DOCTYPE html><html><body>
<canvas id="canvas" width="500" height="500" style="border:1px solid #d3d3d3;"></canvas>
<script src="scroll.js"></script>
<script>
function draw(options){
options.ctx.beginPath();
options.ctx.arc(95, 50, 40, 0, 2 * Math.PI);
options.ctx.stroke();
}
new CanvasDragZoom(document.getElementById('canvas'), draw);
</script></body></html>
In other words:
-
Add
<canvas>
element to HTML -
Include scroll.js script
-
define a
draw
function -
create new
CanvasDragZoom
object, passing it the<canvas>
element anddraw
function.
The draw
function should accept a single options
argument, which is a JSON object with various key-value pairs, most important of which is a ctx
key, which is this canvas'es 2d context.
In other words, the thing that you draw on.
And you will get something like this: