I2Djs-v3
  • Introduction to I2Djs
  • Getting Started
    • Installation
    • Quick Start
    • Resources
  • Guide
    • Canvas: Create-animate
    • SVG: Create-animate
    • WebGL: Create-animate
    • Data Join-Action
    • Animation-Chaining
    • Canvas: Textures & Sprite animation
    • Canvas: Heatmap
    • WebGL: Heatmap
    • WebGL: Custom Shaders
    • Canvas: GeoWorld Map with D3 modules
    • Canvas: Clipping, Masking, Pattern
    • SVG: Clipping, Masking, Pattern
    • I2Djs + Physics Engine - MatterJs
  • API Reference
    • Layers
      • Canvas Layer
      • SVG Layer
      • WebGL Layer
    • Elements API
    • Canvas additional features
    • WebGL additional features
      • Custom Shader
      • Geometry
      • Render Target
      • Texture Object
    • Join Action
    • Animation
    • Chaining
    • Path
    • Events
    • Behaviour
      • Zoom and Pan
      • Drag
  • Examples
    • Canvas
    • SVG
    • WebGL
Powered by GitBook
On this page
  • API
  • Zoom configuration:
  • Methods inherited by context node:
  • Usage:

Was this helpful?

  1. API Reference
  2. Behaviour

Zoom and Pan

PreviousBehaviourNextDrag

Last updated 4 years ago

Was this helpful?

zooming and panning is one of the popular interactions, helps focus on the region of interest. I2Djs provides an intuitive way to define the zoom behavior on SVG, Canvas, and webGL layers. I2Djs support multiple interactions as specified below:

Panning: Click and drag, Touch.

Zoom: On the spin wheel, Pinch(2 pointer event), vertical scroll.

API

let zoomInstance = i2d.behaviour.zoom()

zoomStart: Triggered on zoom start.

zoomInstance.zoomStart(function(event){

})

zoom: Triggered continuously on zoom. It will be triggered after zoomStart till zoomEnd.

zoomInstance.zoom(function(event){

})

zoomEnd: Triggered once on zoom ends.

zoomInstance.zoomEnd(function(event){

})

Zoom configuration:

zoomInstance.scaleExtent([minScale, MaxScale]);

zoomInstance.panExtent([topLeft[x, y], bottomRight[x, y]]);

zoomInstance.zoomTarget(point[x, y]);

zoomInstance.zoomFactor(value);

zoomInstance.duration();

Methods inherited by context node:

node.zoomTo(zoomScale, point);

node.zoomBy(zoomScale, point);

node.panTo(point)

Usage:

let zoomInstance = i2d.behaviour.zoom()
zoomInstance.zoomStart(function (event) {
    node.setAttr('transform', event.transform);
});
zoomInstance.zoom(function (event) {
    node.setAttr('transform', event.transform);
});
zoomInstance.zoomEnd(function (event) {
    node.setAttr('transform', event.transform);
});

node.on('zoom', zoomInstance);

//Inherited methods:
node.zoomTo(zoomScale, point);
node.zoomBy(zoomScale, point);
node.panTo(point);