map.js
/*
 * Handler for mouse wheel event. Zooms the map in or out.
 */
Handler for mouse wheel event. Zooms the map in or out.
Handler for mouse wheel event . Zooms the map in or out .
function mouseWheel(event) {
	event.preventDefault();
	scale = scale + (scale * (-Math.sign(event.deltaY) * wheelZoomAmount));
	scale = Math.min(Math.max(scale, 0.1), 10);
	const newWidth = mapCanvas.width * scale;
	const newHeight = mapCanvas.height * scale;
	const diffW = newWidth - viewport.width;
	const diffH = newHeight - viewport.height;
	const cursorRatioX = (event.clientX - viewport.x) / viewport.width;
	const cursorRatioY = (event.clientY - viewport.y) / viewport.height;
	viewport.x -= diffW * cursorRatioX;
	viewport.y -= diffH * cursorRatioY;
	viewport.width = newWidth;
	viewport.height = newHeight;
	draw();
}
function mouseWheel ( event ) { event . preventDefault ( ) ; scale = scale + ( scale * ( - Math . sign ( event . deltaY ) * wheelZoomAmount ) ) ; scale = Math . min ( Math . max ( scale , 0.1 ) , 10 ) ; const newWidth = mapCanvas . width * scale ; const newHeight = mapCanvas . height * scale ; const diffW = newWidth - viewport . width ; const diffH = newHeight - viewport . height ; const cursorRatioX = ( event . clientX - viewport . x ) / viewport . width ; const cursorRatioY = ( event . clientY - viewport . y ) / viewport . height ; viewport . x -= diffW * cursorRatioX ; viewport . y -= diffH * cursorRatioY ; viewport . width = newWidth ; viewport . height = newHeight ; draw ( ) ; }
Handler for mouse wheel event.
Handler for mouse wheel event .