Skip to content

Commit

Permalink
feature: link control on screen (#2069)
Browse files Browse the repository at this point in the history
* Update link.js

* Update measure.js
  • Loading branch information
dahlalex authored Nov 12, 2024
1 parent 87b12e6 commit 5944326
Showing 1 changed file with 46 additions and 12 deletions.
58 changes: 46 additions & 12 deletions src/controls/link.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,67 @@
import { Component } from '../ui';
import { Component, Element as El, Button, dom } from '../ui';

const Link = function Link(options = {}) {
const {
icon = '#ic_launch_24px',
placement = ['menu'],
target = '_blank',
url,
title
} = options;
let mapMenu;
let menuItem;
let viewer;
let mapTools;
let screenButtonContainer;
let screenButton;

return Component({
name: 'link',
onAdd(evt) {
viewer = evt.target;
mapMenu = viewer.getControlByName('mapmenu');
menuItem = mapMenu.MenuItem({
click() {
mapMenu.close();
window.open(url);
},
icon,
title
});
this.addComponent(menuItem);
if (placement.indexOf('screen') > -1) {
mapTools = `${viewer.getMain().getMapTools().getId()}`;
screenButtonContainer = El({
tagName: 'div',
cls: 'flex column'
});
screenButton = Button({
cls: 'o-link padding-small icon-smaller round light box-shadow',
click() {
window.open(url, target);
},
icon,
tooltipText: title,
tooltipPlacement: 'east'
});
this.addComponent(screenButton);
}
if (placement.indexOf('menu') > -1) {
mapMenu = viewer.getControlByName('mapmenu');
menuItem = mapMenu.MenuItem({
click() {
mapMenu.close();
window.open(url, target);
},
icon,
title
});
this.addComponent(menuItem);
}
this.render();
},
render() {
mapMenu.appendMenuItem(menuItem);
if (placement.indexOf('screen') > -1) {
let htmlString = `${screenButtonContainer.render()}`;
let el = dom.html(htmlString);
document.getElementById(mapTools).appendChild(el);
htmlString = screenButton.render();
el = dom.html(htmlString);
document.getElementById(screenButtonContainer.getId()).appendChild(el);
}
if (placement.indexOf('menu') > -1) {
mapMenu.appendMenuItem(menuItem);
}
this.dispatch('render');
}
});
Expand Down

0 comments on commit 5944326

Please sign in to comment.