File size: 2,294 Bytes
36ddefa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
componentconstructors['coord'] = function(dynmap, configuration) {

	var Coord = L.Control.extend({
		valfield: $('<span/>'),
		mcrfield: $('<span/>'),
		chunkfield: $('<span/>'),

		onAdd: function(map) {
			if(configuration.hidey) 
				this._container = L.DomUtil.create('div', 'coord-control coord-control-noy');
			else
				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(configuration.hidey ? '---,---' : '---,---,---').appendTo(this._container);
			if(configuration['show-mcr']) {
				$('<br/>').appendTo(this._container);
				this.mcrfield.addClass('coord-control-value').text('--------').appendTo(this._container);
			}
			if(configuration['show-chunk']) {
				$('<br/>').appendTo(this._container);
				this.chunkfield.addClass('coord-control-value').text('Chunk: ---,---').appendTo(this._container);
			}
			this._update();
			return this.getContainer();
		},

		getPosition: function() {
			return 'topleft';
		},

		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, dynmap.world.sealevel+1);
		if(configuration.hidey)
			coord.valfield.text(Math.round(loc.x) + ',' + Math.round(loc.z));
		else
			coord.valfield.text(Math.round(loc.x) + ',' + loc.y + ',' + Math.round(loc.z));
		if(configuration['show-mcr'])
			coord.mcrfield.text('r.' + Math.floor(loc.x/512) + '.' + Math.floor(loc.z/512) + '.mca');
		if(configuration['show-chunk'])
			coord.chunkfield.text('Chunk: ' + Math.floor(loc.x/16) + ',' + Math.floor(loc.z/16));
	});
	dynmap.map.on('mouseout', function(mevent) {
		if(!dynmap.map) return;
		if(configuration.hidey)
			coord.valfield.text('---,---');
		else
			coord.valfield.text('---,---,---');
		if(configuration['show-mcr'])
			coord.mcrfield.text('--------');
		if(configuration['show-chunk'])
			coord.chunkfield.text('Chunk: ---,---');
	});
};