Skip to content

Commit bd1e33c

Browse files
cryptobenchclaude
andcommitted
Fix map coordinate display scaling
Added SCALE factor (256px/32 blocks = 8) to correctly convert between Leaflet tile-pixel coordinates and world block coordinates. Mouse position and player markers now display accurate world coordinates. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3c8c987 commit bd1e33c

File tree

1 file changed

+6
-5
lines changed
  • src/main/resources/web/js

1 file changed

+6
-5
lines changed

src/main/resources/web/js/map.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// Config - 1 tile = 1 chunk = 32 blocks
55
const CHUNK_SIZE = 32;
66
const TILE_SIZE = 256;
7+
const SCALE = TILE_SIZE / CHUNK_SIZE; // 8 - Leaflet units per block
78

89
// State
910
let map = null;
@@ -40,9 +41,9 @@
4041
updateTileLayer();
4142

4243
map.on('mousemove', function(e) {
43-
// In CRS.Simple with our setup: lat = -Z, lng = X
44-
const x = Math.round(e.latlng.lng);
45-
const z = Math.round(-e.latlng.lat);
44+
// Convert Leaflet coords to world coords (divide by scale factor)
45+
const x = Math.round(e.latlng.lng / SCALE);
46+
const z = Math.round(-e.latlng.lat / SCALE);
4647
document.getElementById('coords-display').textContent = `X: ${x}, Z: ${z}`;
4748
});
4849

@@ -71,8 +72,8 @@
7172
// Convert world coords to LatLng
7273
function worldToLatLng(x, z) {
7374
// X -> lng, Z -> -lat (north is up, Z increases south)
74-
// Scale by chunk size since tiles represent chunks
75-
return L.latLng(-z, x);
75+
// Multiply by SCALE since Leaflet uses tile-pixel coords (256px per 32-block chunk)
76+
return L.latLng(-z * SCALE, x * SCALE);
7677
}
7778

7879
async function loadWorlds() {

0 commit comments

Comments
 (0)