From 857c527e3167274b443c5153e86b7a91680b972d Mon Sep 17 00:00:00 2001 From: Alex Dahl <96343158+dahlalex@users.noreply.github.com> Date: Mon, 18 Nov 2024 17:43:05 +0100 Subject: [PATCH] feature: external url control with regular links (#2071) * update: external url control * Update externalurlSeveralButtons.js --- .../externalurl/externalurlSeveralButtons.js | 42 +++++++++++++++---- .../externalurl/externalurlSingleButton.js | 2 + 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/controls/externalurl/externalurlSeveralButtons.js b/src/controls/externalurl/externalurlSeveralButtons.js index 54a59600a..31c3f466c 100644 --- a/src/controls/externalurl/externalurlSeveralButtons.js +++ b/src/controls/externalurl/externalurlSeveralButtons.js @@ -5,6 +5,7 @@ import replacer from '../../utils/replacer'; const externalurlSeveralButtons = function externalurlSeveralButtons(options = {}) { const mainbuttonTooltipText = options.tooltipText || 'Visa kartan i en extern karttjänst'; const links = options.links; + const hasValidMethod = links.some(link => link.method !== 'none'); let map; let isMainButtonActive = false; let viewer; @@ -13,11 +14,34 @@ const externalurlSeveralButtons = function externalurlSeveralButtons(options = { let target; const buttons = []; const subButtons = []; + const direction = options.direction; + const linkTarget = options.target || '_blank'; + let containerElementcls; + let subButtoncls; + let subButtontooltipPlacement; + switch (direction) { + case 'horizontal': + { + containerElementcls = 'flex row'; + subButtoncls = 'margin-left-small'; + subButtontooltipPlacement = 'south'; + break; + } + default: + { + containerElementcls = 'flex column'; + subButtoncls = 'margin-top-small'; + subButtontooltipPlacement = 'east'; + break; + } + } function toggleMainButton() { if (!isMainButtonActive) { document.getElementById(externalUrlMainButton.getId()).classList.add('active'); - viewer.centerMarker.show(); + if (hasValidMethod) { + viewer.centerMarker.show(); + } subButtons.forEach((button) => { document.getElementById(button.getId()).classList.remove('hidden'); }); @@ -25,7 +49,9 @@ const externalurlSeveralButtons = function externalurlSeveralButtons(options = { isMainButtonActive = true; } else { document.getElementById(externalUrlMainButton.getId()).classList.remove('active'); - viewer.centerMarker.hide(); + if (hasValidMethod) { + viewer.centerMarker.hide(); + } subButtons.forEach((button) => { document.getElementById(button.getId()).classList.add('hidden'); }); @@ -39,11 +65,11 @@ const externalurlSeveralButtons = function externalurlSeveralButtons(options = { onInit() { containerElement = El({ tagName: 'div', - cls: 'flex column' + cls: containerElementcls }); externalUrlMainButton = Button({ - cls: 'o-measure padding-small margin-bottom-smaller icon-smaller round light box-shadow', + cls: 'o-measure padding-small icon-smaller round light box-shadow', icon: '#ic_baseline_link_24px', tooltipText: mainbuttonTooltipText, tooltipPlacement: 'east', @@ -56,10 +82,10 @@ const externalurlSeveralButtons = function externalurlSeveralButtons(options = { const tooltipText = link.tooltipText; const buttonImage = link.buttonImage || '#fa-external-link'; const subButton = Button({ - cls: 'o-measure-length padding-small margin-bottom-smaller icon-smaller round light box-shadow hidden', + cls: `o-measure-length padding-small ${subButtoncls} icon-smaller round light box-shadow hidden`, icon: buttonImage, tooltipText, - tooltipPlacement: 'east', + tooltipPlacement: subButtontooltipPlacement, click() { const mapView = map.getView(); const center = mapView.getCenter(); @@ -72,8 +98,10 @@ const externalurlSeveralButtons = function externalurlSeveralButtons(options = { } else if (link.method === 'LatLon') { const centerLonlat = toLonLat(transformedCenter); replacedUrl = replacer.replace(link.url, { LON: centerLonlat[0], LAT: centerLonlat[1] }); + } else if (link.method === 'none') { + replacedUrl = link.url; } - window.open(replacedUrl, '_blank'); + window.open(replacedUrl, linkTarget); } }); buttons.push(subButton); diff --git a/src/controls/externalurl/externalurlSingleButton.js b/src/controls/externalurl/externalurlSingleButton.js index 2aa39b5eb..2d41e7c59 100644 --- a/src/controls/externalurl/externalurlSingleButton.js +++ b/src/controls/externalurl/externalurlSingleButton.js @@ -33,6 +33,8 @@ const ExternalurlSingleButton = function ExternalurlSingleButton(options = {}) { } else if (method === 'LatLon') { const centerLonlat = toLonLat(transformedCenter); replacedUrl = replacer.replace(url, { LON: centerLonlat[0], LAT: centerLonlat[1] }); + } else if (method === 'none') { + replacedUrl = url; } window.open(replacedUrl, '_blank');