dynmap/web/js/coord.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

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('---,---,---');
});
};