<div #graphicsContainer id="graphicsContainer" class="col-xs-12 componentContents" style="text-align:center; overflow:hidden;" (panstart)="onPanStart($event)" (panmove)="onPanMove($event)" (pinchstart)="onPinchStart($event)" (pinchmove)="onPinch($event)" [style.background-color]="bgColor"> <div id="grab" [style.marginLeft.px]="x" [style.marginTop.px]="y" [style.transform]="'scale(' + scale + ',' + scale + ')'"> <canvas id="theCanvas" width="1000" height="500"></canvas> </div> <graphics-help></graphics-help></div>
startWidth: number; startHeight: number; newWidth: number; newHeight: number;
/** * onPinchStart * Event Listener for pinchstart - hammer.js * @param event */ onPinchStart(event: any): void { event.preventDefault(); this.startScale = this.scale; this.startHeight = this.newHeight; this.startWidth = this.newWidth; }
/** * onPinch * Event Listener for pinchmove - hammer.js * @param event */ onPinch(event: any): void { event.preventDefault(); this.scale = this.startScale * event.scale; paper.view.scale(this.scale, [0,0]); console.log(this.scale); this.newHeight = this.startHeight * event.scale; this.newWidth = this.startWidth * event.scale; console.log(this.newWidth + " x " + this.newHeight); paper.view.viewSize.width = this.newWidth; paper.view.viewSize.height = this.newHeight; }
Here's a relatively compact solution (codepen):