diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-02-04 07:22:49 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-02-04 07:22:49 +0100 |
commit | 61f47521a94168739ca031aab6eb5fe81531a024 (patch) | |
tree | fed7e994de30151e3c6a7033e4575c836cc8f340 /viewer | |
parent | 80b38d3d7ac644389d7ff75ee35a1497f5f0c3ac (diff) | |
download | MinedMap-61f47521a94168739ca031aab6eb5fe81531a024.tar MinedMap-61f47521a94168739ca031aab6eb5fe81531a024.zip |
viewer: add coordinate control
Diffstat (limited to 'viewer')
-rw-r--r-- | viewer/MinedMap.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/viewer/MinedMap.js b/viewer/MinedMap.js index b733eca..8d356a0 100644 --- a/viewer/MinedMap.js +++ b/viewer/MinedMap.js @@ -78,6 +78,25 @@ var MinedMapLayer = L.GridLayer.extend({ }); +var CoordControl = L.Control.extend({ + initialize: function () { + this.options.position = 'bottomleft'; + }, + + onAdd: function (map) { + this._container = L.DomUtil.create('div', 'leaflet-control-attribution'); + + return this._container; + }, + + update: function (x, z) { + if (!this._map) { return; } + + this._container.innerHTML = 'X: ' + x + ' Z: ' + z; + } +}); + + window.createMap = function () { var xhr = new XMLHttpRequest(); xhr.onload = function () { @@ -107,6 +126,13 @@ window.createMap = function () { }; L.control.layers({}, overlayMaps).addTo(map); + + var coordControl = new CoordControl(); + coordControl.addTo(map); + + map.on('mousemove', function(e) { + coordControl.update(Math.round(e.latlng.lng), Math.round(-e.latlng.lat)); + }); }; xhr.open('GET', 'data/info.json', true); |