mirror of https://github.com/webbukkit/dynmap.git
Merge 1a7e702a39
into ea24554033
This commit is contained in:
commit
ce235be15e
|
@ -41,6 +41,8 @@ componentconstructors['coord'] = function(dynmap, configuration) {
|
||||||
|
|
||||||
var coord = new Coord();
|
var coord = new Coord();
|
||||||
dynmap.map.addControl(coord);
|
dynmap.map.addControl(coord);
|
||||||
|
var prev=[0,0];
|
||||||
|
var update_url=true;
|
||||||
dynmap.map.on('mousemove', function(mevent) {
|
dynmap.map.on('mousemove', function(mevent) {
|
||||||
if(!dynmap.map) return;
|
if(!dynmap.map) return;
|
||||||
var loc = dynmap.getProjection().fromLatLngToLocation(mevent.latlng, dynmap.world.sealevel+1);
|
var loc = dynmap.getProjection().fromLatLngToLocation(mevent.latlng, dynmap.world.sealevel+1);
|
||||||
|
@ -52,6 +54,32 @@ componentconstructors['coord'] = function(dynmap, configuration) {
|
||||||
coord.mcrfield.text('r.' + Math.floor(loc.x/512) + '.' + Math.floor(loc.z/512) + '.mca');
|
coord.mcrfield.text('r.' + Math.floor(loc.x/512) + '.' + Math.floor(loc.z/512) + '.mca');
|
||||||
if(configuration['show-chunk'])
|
if(configuration['show-chunk'])
|
||||||
coord.chunkfield.text('Chunk: ' + Math.floor(loc.x/16) + ',' + Math.floor(loc.z/16));
|
coord.chunkfield.text('Chunk: ' + Math.floor(loc.x/16) + ',' + Math.floor(loc.z/16));
|
||||||
|
if(update_url){
|
||||||
|
var center = dynmap.maptype.getProjection().fromLatLngToLocation(dynmap.map.getCenter(), 64);
|
||||||
|
if(
|
||||||
|
prev[0]==center.x &&
|
||||||
|
prev[1]==center.z
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
prev[0]=center.x;
|
||||||
|
prev[1]=center.y;
|
||||||
|
var url = window.location.pathname;
|
||||||
|
if(dynmap.options['round-coordinates'])
|
||||||
|
url = url + "?worldname=" + dynmap.world.name + "&mapname=" + dynmap.maptype.options.name + "&zoom=" + dynmap.map.getZoom() + "&x=" + center.x + "&y=" +
|
||||||
|
center.y + "&z=" + center.z;
|
||||||
|
else
|
||||||
|
url = url + "?worldname=" + dynmap.world.name + "&mapname=" + dynmap.maptype.options.name + "&zoom=" + dynmap.map.getZoom() + "&x=" +
|
||||||
|
Math.round(center.x) + "&y=" + Math.round(center.y) + "&z=" + Math.round(center.z);
|
||||||
|
// history api can send error because it is called too many times
|
||||||
|
try{
|
||||||
|
history.replaceState(null,"",url);
|
||||||
|
}catch(e){}
|
||||||
|
// prevent calling the api too often
|
||||||
|
update_url=false;
|
||||||
|
setTimeout(()=>{
|
||||||
|
update_url=true;
|
||||||
|
},100)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
dynmap.map.on('mouseout', function(mevent) {
|
dynmap.map.on('mouseout', function(mevent) {
|
||||||
if(!dynmap.map) return;
|
if(!dynmap.map) return;
|
||||||
|
|
Loading…
Reference in New Issue