From 48a6712e480fe484157e753579a19d712a49f6ac Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 21 May 2021 23:59:06 +0200 Subject: Add map zoom-out button. --- public/common/client.js | 25 +++++++++++++++++++++++++ public/common/grid.css | 6 ++++++ public/images/magnifying-glass.svg | 1 + 3 files changed, 32 insertions(+) create mode 100644 public/images/magnifying-glass.svg diff --git a/public/common/client.js b/public/common/client.js index ea1c12b..cee9ea5 100644 --- a/public/common/client.js +++ b/public/common/client.js @@ -318,8 +318,33 @@ function toggle_chat() { show_chat(); } +function zoom_map() { + let grid = document.querySelector(".grid_center"); + let mapwrap = document.querySelector(".mapwrap"); + let map = document.querySelector(".map"); + map.style.transform = 'none'; + mapwrap.style.height = 'auto'; + if (mapwrap.classList.contains("fit")) { + let { width: ww, height: wh } = mapwrap.getBoundingClientRect(); + let { width: cw, height: ch } = map.getBoundingClientRect(); + let scale = ww / cw; + if (scale < 1) { + map.style.transform = "scale(" + scale + ")"; + mapwrap.style.height = (ch * scale) + "px"; + } + } +} + +window.addEventListener('resize', zoom_map); + +function toggle_zoom() { + document.querySelector(".mapwrap").classList.toggle('fit'); + zoom_map(); +} + function toggle_log() { document.querySelector(".grid_window").classList.toggle("hide_log"); + zoom_map(); } function show_action_button(sel, action, use_label = false) { diff --git a/public/common/grid.css b/public/common/grid.css index 95a2ee4..1ef92da 100644 --- a/public/common/grid.css +++ b/public/common/grid.css @@ -224,9 +224,15 @@ html, body, div { transform: scale(2.0) translate(0,-35px); } +.mapwrap.fit { + overflow: hidden; + max-width: 100%; +} + .map { margin: 0 auto; box-shadow: 0px 1px 10px rgba(0,0,0,0.5); + transform-origin: 0 0; } button { diff --git a/public/images/magnifying-glass.svg b/public/images/magnifying-glass.svg new file mode 100644 index 0000000..39cc33b --- /dev/null +++ b/public/images/magnifying-glass.svg @@ -0,0 +1 @@ + \ No newline at end of file -- cgit v1.2.3