Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public zoom(ratio: number, center?: Point): void {
const group: Group = this.get('group')
let matrix: Matrix = clone(group.getMatrix())
const minZoom: number = this.get('minZoom')
const maxZoom: number = this.get('maxZoom')
if (!matrix) {
matrix = mat3.create();
}
if(center) {
mat3.translate(matrix, matrix, [ -center.x, -center.y ])
mat3.scale(matrix, matrix, [ ratio, ratio ])
mat3.translate(matrix, matrix, [ center.x, center.y ])
} else {
mat3.scale(matrix, matrix, [ ratio, ratio ])
}
if (minZoom && matrix[0] < minZoom) {
return;
}
if (maxZoom && matrix[0] > maxZoom) {
return;
}
group.setMatrix(matrix);
this.emit('viewportchange', { action: 'zoom', matrix });
this.autoPaint();
}