Add 'coord' client component - show world coords of mouse pointer
This commit is contained in:
parent
571c2acfc3
commit
f824a17704
3 changed files with 66 additions and 0 deletions
40
web/js/coord.js
Normal file
40
web/js/coord.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
componentconstructors['coord'] = function(dynmap, configuration) {
|
||||
|
||||
var Coord = L.Class.extend({
|
||||
valfield: $('<span/>'),
|
||||
|
||||
onAdd: function(map) {
|
||||
this._container = L.DomUtil.create('div', 'coord-control');
|
||||
this._map = map;
|
||||
$('<span/>').addClass('coord-control-label').text((configuration.label || 'x,y,z') + ': ').appendTo(this._container);
|
||||
$('<br/>').appendTo(this._container);
|
||||
this.valfield.addClass('coord-control-value').text('').appendTo(this._container);
|
||||
|
||||
this._update();
|
||||
},
|
||||
|
||||
getPosition: function() {
|
||||
return L.Control.Position.TOP_LEFT;
|
||||
},
|
||||
|
||||
getContainer: function() {
|
||||
return this._container;
|
||||
},
|
||||
|
||||
_update: function() {
|
||||
if (!this._map) return;
|
||||
}
|
||||
});
|
||||
|
||||
var coord = new Coord();
|
||||
dynmap.map.addControl(coord);
|
||||
dynmap.map.on('mousemove', function(mevent) {
|
||||
if(!dynmap.map) return;
|
||||
var loc = dynmap.getProjection().fromLatLngToLocation(mevent.latlng, 64);
|
||||
coord.valfield.text(Math.round(loc.x) + ',' + loc.y + ',' + Math.round(loc.z));
|
||||
});
|
||||
dynmap.map.on('mouseout', function(mevent) {
|
||||
if(!dynmap.map) return;
|
||||
coord.valfield.text('---,---,---');
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue