@@ -70,6 +70,7 @@ const measureFps = () => {
7070requestAnimationFrame ( measureFps ) ;
7171
7272
73+ const $viewport = document . querySelector ( '#viewport' ) ;
7374const $bg = document . querySelector ( '#background' ) ;
7475const pz = panzoom ( $bg , {
7576 zoomSpeed : 0.25 ,
@@ -95,6 +96,15 @@ function setDefaultZoomParams() {
9596setDefaultZoomParams ( ) ;
9697window . addEventListener ( 'resize' , setDefaultZoomParams ) ;
9798
99+ // Center the room's starting position. Panzoom will clip this so we don't pan
100+ // out of the room.
101+ pz . moveTo (
102+ // These are the coordinates of the background within the viewport, so the
103+ // coordinate (-100, -100) means the leftmost and topmost 100 pixels of the
104+ // background image are outside of the viewport.
105+ 0.5 * $viewport . offsetWidth - document . ROOM_CONFIG . starting_position . x ,
106+ 0.5 * $viewport . offsetHeight - document . ROOM_CONFIG . starting_position . y ) ;
107+
98108// Disable zoom during pan.
99109pz . on ( 'panstart' , ( _ ) => {
100110 const scale = pz . getTransform ( ) . scale ;
@@ -857,13 +867,9 @@ document.onkeydown = function(e) {
857867 e = e || window . event ;
858868 const code = e . which || e . keyCode ;
859869
860- if ( ! ( e . ctrlKey || e . metaKey ) ) return ;
861-
862- if ( code == 187 || code == 189 ) {
870+ if ( ( e . ctrlKey || e . metaKey ) && ( code == 187 || code == 189 ) ) {
863871 e . preventDefault ( ) ;
864872 e . stopPropagation ( ) ;
865- const amount = ( code == 189 ) ? - 0.2 : 0.2 ;
866- viewport . zoomPercent ( amount , true ) ;
867873 }
868874} ;
869875
0 commit comments