From 85b125b35c5b5489ec153fd29324965eb1b3ef85 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Thu, 18 Jan 2024 22:04:07 +0100 Subject: Improve handling of -

blah blah blah

diff --git a/main.js b/main.js index e288d28..5298b1c 100644 --- a/main.js +++ b/main.js @@ -201,8 +201,40 @@ const container = document.getElementById('map-control-container'); map.addControl(control); })(); -/* layer selection button and legend */ const menu = document.getElementById('map-menu'); +const TRAILING_ZEROES = /\.?0*$/; + +/* "open in new tab" button */ +if (window.location !== window.parent.location) { + const div = document.createElement('div'); + menu.appendChild(div); + div.id = 'newtab-button'; + div.classList.add('ol-unselectable', 'ol-control'); + + const btn = document.createElement('button'); + div.appendChild(btn); + btn.type = 'button'; + btn.setAttribute('aria-expanded', 'false'); + btn.title = 'Öppna karta i ny flik'; + btn.classList.add('btn', 'btn-light'); + + const i = document.createElement('i'); + btn.appendChild(i); + i.classList.add('bi', 'bi-box-arrow-up-right'); + + btn.onclick = function(event) { + const coordinates = view.getCenter(); + const url = new URL(window.location.href); + const searchParams = new URLSearchParams(url.hash.substring(1)); + searchParams.set('x', coordinates[0].toFixed(2).replace(TRAILING_ZEROES, '')); + searchParams.set('y', coordinates[1].toFixed(2).replace(TRAILING_ZEROES, '')); + searchParams.set('z', view.getZoom().toFixed(3).replace(TRAILING_ZEROES, '')); + url.hash = '#' + searchParams.toString(); + return window.open(url.href, '_blank'); + }; +} + +/* layer selection button and legend */ (function() { const btn = (function() { const div = document.createElement('div'); @@ -418,18 +450,10 @@ const menu = document.getElementById('map-menu'); /* we're all set, show the control container now */ container.setAttribute('aria-hidden', 'false'); -const TRAILING_ZEROES = /\.?0*$/; map.on('singleclick', function(event) { const size = map.getSize(); - if (window.location !== window.parent.location && (size[0] < 576 || size[1] < 576)) { - const coordinates = view.getCenter(); - const url = new URL(window.location.href); - const searchParams = new URLSearchParams(url.hash.substring(1)); - searchParams.set('x', coordinates[0].toFixed(2).replace(TRAILING_ZEROES, '')); - searchParams.set('y', coordinates[1].toFixed(2).replace(TRAILING_ZEROES, '')); - searchParams.set('z', view.getZoom().toFixed(3).replace(TRAILING_ZEROES, '')); - url.hash = '#' + searchParams.toString(); - return window.open(url.href, '_blank'); + if (size[0] < 576 || size[1] < 576) { + return; } }); -- cgit v1.2.3