Skip to content

Commit

Permalink
Merge pull request #16 from boriskrasko/markup
Browse files Browse the repository at this point in the history
Map zoom (buttons)
  • Loading branch information
boriskrasko authored Feb 22, 2024
2 parents a310843 + 25893f0 commit b1a218b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,19 @@ basemaps.querySelectorAll('li').forEach(li => {
})

function zoom(direction) {
const step = 500;
const step = 500;
const rect = mapImage.getBoundingClientRect();
const mouseX = rect.width / 2;
const mouseY = rect.height / 2;
const offsetX = mouseX / rect.width;
const offsetY = mouseY / rect.height;
const currentWidth = mapImage.clientWidth;
const newWidth = direction === 'in' ? currentWidth + step : currentWidth - step;
mapImage.style.width = `${newWidth}px`;

const newRect = mapImage.getBoundingClientRect();
mapImage.style.left = `${parseFloat(mapImage.style.left) - (newRect.width - rect.width) * offsetX}px`;
mapImage.style.top = `${parseFloat(mapImage.style.top) - (newRect.height - rect.height) * offsetY}px`;
}

document.querySelector('.zoom-in').addEventListener('click', () => {
Expand Down

0 comments on commit b1a218b

Please sign in to comment.