2020-11-24 01:52:31 +00:00
|
|
|
import L, {ControlOptions} from 'leaflet';
|
2020-11-23 12:13:28 +00:00
|
|
|
|
2020-11-24 01:52:31 +00:00
|
|
|
export interface LinkControlOptions extends ControlOptions {}
|
2020-11-23 12:13:28 +00:00
|
|
|
|
2020-11-24 01:52:31 +00:00
|
|
|
export class LinkControl extends L.Control {
|
|
|
|
options: LinkControlOptions
|
|
|
|
|
|
|
|
onAdd(map) {
|
2020-11-23 12:13:28 +00:00
|
|
|
this._map = map;
|
|
|
|
this._container = L.DomUtil.create('div', 'dynmap-link');
|
|
|
|
|
|
|
|
this._linkButton = this._createButton(
|
|
|
|
'Link', 'dynmap-link-button', this._follow, this);
|
|
|
|
|
|
|
|
this._container.appendChild(this._linkButton);
|
|
|
|
return this._container;
|
2020-11-24 01:52:31 +00:00
|
|
|
}
|
2020-11-23 12:13:28 +00:00
|
|
|
|
2020-11-24 01:52:31 +00:00
|
|
|
getContainer() {
|
2020-11-23 12:13:28 +00:00
|
|
|
return this._container;
|
2020-11-24 01:52:31 +00:00
|
|
|
}
|
2020-11-23 12:13:28 +00:00
|
|
|
|
2020-11-24 01:52:31 +00:00
|
|
|
getPosition() {
|
2020-11-23 12:13:28 +00:00
|
|
|
return this.options.position;
|
2020-11-24 01:52:31 +00:00
|
|
|
}
|
2020-11-23 12:13:28 +00:00
|
|
|
|
2020-11-24 01:52:31 +00:00
|
|
|
_createButton(title, className, fn, context) {
|
|
|
|
const link = document.createElement('a');
|
2020-11-23 12:13:28 +00:00
|
|
|
link.href = '#';
|
|
|
|
link.title = title;
|
|
|
|
link.className = className;
|
|
|
|
link.onmouseover = function () {
|
|
|
|
link.href = dynmap.getLink();
|
|
|
|
};
|
|
|
|
|
|
|
|
L.DomEvent.disableClickPropagation(link);
|
|
|
|
L.DomEvent.addListener(link, 'click', L.DomEvent.preventDefault);
|
|
|
|
L.DomEvent.addListener(link, 'click', fn, context);
|
|
|
|
|
|
|
|
return link;
|
2020-11-24 01:52:31 +00:00
|
|
|
}
|
2020-11-23 12:13:28 +00:00
|
|
|
|
2020-11-24 01:52:31 +00:00
|
|
|
_follow() {
|
2020-11-23 12:13:28 +00:00
|
|
|
// var url = dynmap.getLink();
|
|
|
|
// window.location = url;
|
|
|
|
}
|
2020-11-24 01:52:31 +00:00
|
|
|
}
|
2020-11-23 12:13:28 +00:00
|
|
|
|
|
|
|
// var link = new dynmapLink();
|
|
|
|
// dynmap.map.addControl(link);
|
|
|
|
// }
|