Zoom In / Zoom out is not working

Hi Walter,

I am trying for zoom in and zoom out functionality but this is not working.

I created two buttons “+” and “-” for ZoomIn and ZoomOut.

var zoomInButtonClickCount = 1; // number of zooms
var scaleLevelChange = 0.25; // percent zoom

$("#zoomIn").click(function(){
	if(myDiagram.commandHandler.canIncreaseZoom())
	{
		scaleLevel = scaleLevelChange * zoomInButtonClickCount; 
		// Set scale level to number of times button clicked
		myDiagram.commandHandler.increaseZoom(scaleLevel);
		// Scale the diagram 
		myDiagram.scale = scaleLevel;
	}
});

It goes inside the condition and calculating the scale too but not able to set the scale level.

Can you please guide where I am wrong?

Take a look at CommandHandler | GoJS API and CommandHandler | GoJS API.

Is there a reason you aren’t just setting CommandHandler.zoomFactor to 1.25 and then just having your click event handler be:

function() { if (myDiagram.commandHandler.canIncreaseZoom()) myDiagram.commandHandler.increaseZoom(); }

CommandHandler.increaseZoom is supposed to modify Diagram.scale appropriately, so you don’t need to set it. Furthermore the argument is a factor, not the absolute new scale.

Thanks Walter.

It worked.