From 61f47521a94168739ca031aab6eb5fe81531a024 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 4 Feb 2015 07:22:49 +0100 Subject: viewer: add coordinate control --- viewer/MinedMap.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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); -- cgit v1.2.3