From b66008c26254b33f46af8586a4bc4b58dcf027a4 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Fri, 6 Jan 2012 03:09:53 -0600 Subject: [PATCH] Add support for 'link' component - button to get hard link to current view --- src/main/resources/configuration.txt | 3 ++ web/css/dynmap_style.css | 34 +++++++++++++++++++ web/css/images/link.png | Bin 0 -> 649 bytes web/js/link.js | 48 +++++++++++++++++++++++++++ web/js/map.js | 8 +++++ 5 files changed, 93 insertions(+) create mode 100644 web/css/images/link.png create mode 100644 web/js/link.js diff --git a/src/main/resources/configuration.txt b/src/main/resources/configuration.txt index b811cf5c..4f8d8d0a 100644 --- a/src/main/resources/configuration.txt +++ b/src/main/resources/configuration.txt @@ -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 diff --git a/web/css/dynmap_style.css b/web/css/dynmap_style.css index 98e7382c..94978192 100644 --- a/web/css/dynmap_style.css +++ b/web/css/dynmap_style.css @@ -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; + } diff --git a/web/css/images/link.png b/web/css/images/link.png new file mode 100644 index 0000000000000000000000000000000000000000..c4f00cb2231006331f76e8fb34fe98ba3e6c4c5a GIT binary patch literal 649 zcmV;40(Sk0P)R-wVQ6jZWcdI0SI7HLUn+ckeHpfG*^&WNl8M*$>e_m+%~e1e$TbFH z(ca$P8S6G|`k$7O^&jK{CVU1k0`c?bFBpFR`o)l$lXnKleSPl2rS#vw|1$jj^9QU3 zuK|C7fi{2PLWYLgYKAv2UoylcB>fKv2xQp4Z3_cGzu;Pe0a#X1_5bVFum6KX!v1gG zy8ZvEHS7P!CnWywn=ol7P+AV;1xBO*o3?uOnoLGUMh1|?@87=}8tSSU5)xAxUcPwB zpslOV@ZSJml#C3+_wPS|_&dRXX88q- z<2Uc#FtD(3lrLGb_|3`F=ejkuv>3K*-o&7#twS)X7?&1GCf1H)a#g?Xt!HIMLl0ThjLv**n3J9+X%Fi7wZFolVUi|^~|Xai}!M<@(n=>QZp jqDXS@32BBI01#jRVaY0la%Xjb00000NkvXXu0mjfT~I+< literal 0 HcmV?d00001 diff --git a/web/js/link.js b/web/js/link.js new file mode 100644 index 00000000..12c72aed --- /dev/null +++ b/web/js/link.js @@ -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); +}; diff --git a/web/js/map.js b/web/js/map.js index 553b5c7b..55c05762 100644 --- a/web/js/map.js +++ b/web/js/map.js @@ -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() {