Skip to content

Commit da1cf10

Browse files
feat: move to ROOM_CONFIG.starting_position on page load
1 parent 8f35864 commit da1cf10

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

public/app.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const measureFps = () => {
7070
requestAnimationFrame(measureFps);
7171

7272

73+
const $viewport = document.querySelector('#viewport');
7374
const $bg = document.querySelector('#background');
7475
const pz = panzoom($bg, {
7576
zoomSpeed: 0.25,
@@ -95,6 +96,15 @@ function setDefaultZoomParams() {
9596
setDefaultZoomParams();
9697
window.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.
99109
pz.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

Comments
 (0)