diff --git a/DynmapCore/src/main/resources/extracted/web/js/coord.js b/DynmapCore/src/main/resources/extracted/web/js/coord.js index 7ab346e2..271fcefd 100644 --- a/DynmapCore/src/main/resources/extracted/web/js/coord.js +++ b/DynmapCore/src/main/resources/extracted/web/js/coord.js @@ -41,6 +41,8 @@ componentconstructors['coord'] = function(dynmap, configuration) { var coord = new Coord(); dynmap.map.addControl(coord); + var prev=[0,0]; + var update_url=true; dynmap.map.on('mousemove', function(mevent) { if(!dynmap.map) return; 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'); if(configuration['show-chunk']) 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) { if(!dynmap.map) return;