Add support for 'link' component - button to get hard link to current view
This commit is contained in:
parent
5a0983d867
commit
b66008c262
5 changed files with 93 additions and 0 deletions
48
web/js/link.js
Normal file
48
web/js/link.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
componentconstructors['link'] = function(dynmap, configuration) {
|
||||
|
||||
var dynmapLink = L.Class.extend({
|
||||
options: { position: L.Control.Position.BOTTOM_RIGHT },
|
||||
|
||||
onAdd: function(map) {
|
||||
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);
|
||||
},
|
||||
|
||||
getContainer: function() {
|
||||
return this._container;
|
||||
},
|
||||
|
||||
getPosition: function() {
|
||||
return this.options.position;
|
||||
},
|
||||
|
||||
_createButton: function(title, className, fn, context) {
|
||||
var link = document.createElement('a');
|
||||
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;
|
||||
},
|
||||
|
||||
_follow: function() {
|
||||
var url = dynmap.getLink();
|
||||
window.location = url;
|
||||
}
|
||||
});
|
||||
|
||||
var link = new dynmapLink();
|
||||
dynmap.map.addControl(link);
|
||||
};
|
||||
|
|
@ -829,6 +829,14 @@ DynMap.prototype = {
|
|||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
getLink: function() {
|
||||
var me = this;
|
||||
var url = window.location.pathname;
|
||||
var center = me.maptype.getProjection().fromLatLngToLocation(me.map.getCenter(), 64);
|
||||
url = url + "?worldname=" + me.world.name + "&mapname=" + me.maptype.options.name + "&zoom=" + me.map.getZoom() + "&x=" + center.x + "&y=" +
|
||||
center.y + "&z=" + center.z;
|
||||
return url;
|
||||
}
|
||||
// TODO: Enable hash-links.
|
||||
/* updateLink: function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue