Add support for 'link' component - button to get hard link to current view

This commit is contained in:
Mike Primm 2012-01-06 03:09:53 -06:00
parent 5a0983d867
commit b66008c262
5 changed files with 93 additions and 0 deletions

View File

@ -114,6 +114,9 @@ components:
#- class: org.dynmap.ClientComponent
# type: digitalclock
- class: org.dynmap.ClientComponent
type: link
- class: org.dynmap.ClientComponent
type: timeofdayclock
showdigitalclock: true

View File

@ -888,3 +888,37 @@
.dynmap .coord-control .coord-control-value {
font-weight: bold;
}
.dynmap .dynmap-link {
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border-radius: 7px;
padding: 2px 10px 2px 2px;
background: rgba(0, 0, 0, 0.25);
}
.dynmap .dynmap-link a {
background-color: rgba(255, 255, 255, 0.75);
}
.dynmap .dynmap-link a {
background-position: 50% 50%;
background-repeat: no-repeat;
display: block;
}
.dynmap .dynmap-link a {
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
width: 19px;
height: 19px;
}
.dynmap .dynmap-link a:hover {
background-color: #fff;
}
.leaflet-big-buttons .dynmap-link a {
width: 27px;
height: 27px;
}
.dynmap .dynmap-link-button {
background-image: url(images/link.png);
margin-bottom: 5px;
}

BIN
web/css/images/link.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 649 B

48
web/js/link.js Normal file
View 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);
};

View File

@ -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() {