Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: external url control with regular links #2071

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"name": "legend",
"options": {
"labelOpacitySlider": "Opacity",
"useGroupIndication" : true
"useGroupIndication": true
}
},
{
Expand Down Expand Up @@ -258,4 +258,4 @@
]
]
}
}
}
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 35 additions & 7 deletions src/controls/externalurl/externalurlSeveralButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,19 +14,44 @@ 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');
});
document.getElementById(externalUrlMainButton.getId()).classList.remove('tooltip');
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');
});
Expand All @@ -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',
Expand All @@ -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();
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/controls/externalurl/externalurlSingleButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading