Add 'coord' client component - show world coords of mouse pointer

This commit is contained in:
Mike Primm 2011-09-11 17:48:04 -05:00
parent 8c4315be40
commit ba98145086
3 changed files with 66 additions and 0 deletions

View File

@ -77,6 +77,11 @@ components:
type: timeofdayclock
showdigitalclock: true
#showweather: true
# Mouse pointer world coordinate display
- class: org.dynmap.ClientComponent
type: coord
label: "Location"
#- class: org.dynmap.ClientComponent
# type: logo
# text: "Dynmap"

View File

@ -779,3 +779,24 @@
left: -8px;
z-index: 18;
}
.dynmap .coord-control {
color: #000;
border: 1px solid rgba(128,128,128,0.6);
background-color: #bbb;
border-style: solid;
padding: 2px;
width: 80px;
-moz-border-radius: 5px;
border-radius: 5px;
}
.dynmap .coord-control .coord-control-label {
}
.dynmap .coord-control .coord-control-value {
font-weight: bold;
}

40
web/js/coord.js Normal file
View 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('---,---,---');
});
};