aboutsummaryrefslogtreecommitdiffstats
path: root/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'main.js')
-rw-r--r--main.js46
1 files changed, 35 insertions, 11 deletions
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;
}
});