From 7934000962eb163d0463044a98ebb4e77616e78c Mon Sep 17 00:00:00 2001 From: dahlalex Date: Wed, 6 Nov 2024 10:12:02 +0100 Subject: [PATCH 1/2] update: external url control --- index.json | 4 +- package-lock.json | 12 +++--- .../externalurl/externalurlSeveralButtons.js | 39 ++++++++++++++++--- .../externalurl/externalurlSingleButton.js | 2 + 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/index.json b/index.json index d4b6c9283..7c2138b9c 100644 --- a/index.json +++ b/index.json @@ -40,7 +40,7 @@ "name": "legend", "options": { "labelOpacitySlider": "Opacity", - "useGroupIndication" : true + "useGroupIndication": true } }, { @@ -258,4 +258,4 @@ ] ] } -} +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 0ba3da8eb..0b3a0e1db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origo", - "version": "2.10.0-dev", + "version": "2.9.1-dev", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "origo", - "version": "2.10.0-dev", + "version": "2.9.1-dev", "license": "BSD-2-Clause", "dependencies": { "@glidejs/glide": "^3.6.2", @@ -17,7 +17,7 @@ "elm-pep": "^1.0.6", "html2canvas": "^1.4.1", "jspdf": "^2.5.2", - "ol": "^10.2.0", + "ol": "^10.2.1", "ol-mapbox-style": "12.3.5", "pepjs": "^0.5.3", "proj4": "^2.12.1" @@ -6572,9 +6572,9 @@ "dev": true }, "node_modules/ol": { - "version": "10.2.0", - "resolved": "https://registry.npmjs.org/ol/-/ol-10.2.0.tgz", - "integrity": "sha512-yYFNV8LzN3uOP9qDecMdq07IKlD5P3KfbT+pfOje/XlsnMNLXOb3ZjCZN86wtbew8aq+RfdJ+XylVI8MZsp4Vw==", + "version": "10.2.1", + "resolved": "https://registry.npmjs.org/ol/-/ol-10.2.1.tgz", + "integrity": "sha512-2bB/y2vEnmzjqynP0NA7Cp8k86No3Psn63Dueicep3E3i09axWRVIG5IS/bylEAGfWQx0QXD/uljkyFoY60Wig==", "dependencies": { "@types/rbush": "3.0.3", "color-rgba": "^3.0.0", diff --git a/src/controls/externalurl/externalurlSeveralButtons.js b/src/controls/externalurl/externalurlSeveralButtons.js index 54a59600a..dd6369c33 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,33 @@ const externalurlSeveralButtons = function externalurlSeveralButtons(options = { let target; const buttons = []; const subButtons = []; + const direction = options.direction; + 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 +48,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 +64,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 +81,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,6 +97,8 @@ 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'); } 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'); From 4bde79f4da344b05167fedcee0b7ededd47e2e52 Mon Sep 17 00:00:00 2001 From: dahlalex Date: Mon, 18 Nov 2024 17:35:26 +0100 Subject: [PATCH 2/2] Update externalurlSeveralButtons.js --- src/controls/externalurl/externalurlSeveralButtons.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controls/externalurl/externalurlSeveralButtons.js b/src/controls/externalurl/externalurlSeveralButtons.js index dd6369c33..31c3f466c 100644 --- a/src/controls/externalurl/externalurlSeveralButtons.js +++ b/src/controls/externalurl/externalurlSeveralButtons.js @@ -15,6 +15,7 @@ const externalurlSeveralButtons = function externalurlSeveralButtons(options = { const buttons = []; const subButtons = []; const direction = options.direction; + const linkTarget = options.target || '_blank'; let containerElementcls; let subButtoncls; let subButtontooltipPlacement; @@ -100,7 +101,7 @@ const externalurlSeveralButtons = function externalurlSeveralButtons(options = { } else if (link.method === 'none') { replacedUrl = link.url; } - window.open(replacedUrl, '_blank'); + window.open(replacedUrl, linkTarget); } }); buttons.push(subButton);