Browse Source

Make WASD movement relative to map rotation

- W now moves toward top of screen (map bearing direction)
- S moves toward bottom of screen
- A/D move left/right relative to current view
- Works for both on-screen buttons and keyboard WASD
- Uses destinationPoint() for accurate geographic movement

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
master
HikeMap User 4 weeks ago
parent
commit
12e2a53702
  1. 55
      index.html

55
index.html

@ -6826,21 +6826,30 @@
updateStatus('Test mode enabled via keyboard', 'info');
}
// Move in the specified direction
// Move in the specified direction, accounting for map rotation
const mapBearing = map.getBearing();
let moveBearing;
switch (key) {
case 'w':
testPosition.lat += GPS_TEST_STEP;
moveBearing = mapBearing; // Forward
break;
case 'd':
moveBearing = mapBearing + 90; // Right
break;
case 's':
testPosition.lat -= GPS_TEST_STEP;
moveBearing = mapBearing + 180; // Backward
break;
case 'a':
testPosition.lng -= GPS_TEST_STEP;
break;
case 'd':
testPosition.lng += GPS_TEST_STEP;
moveBearing = mapBearing + 270; // Left
break;
}
moveBearing = ((moveBearing % 360) + 360) % 360;
const stepMeters = GPS_TEST_STEP * 111000;
const currentLngLat = [testPosition.lng, testPosition.lat];
const newLngLat = destinationPoint(currentLngLat, stepMeters, moveBearing);
testPosition.lat = newLngLat[1];
testPosition.lng = newLngLat[0];
e.preventDefault();
simulateGpsPosition();
@ -6900,22 +6909,40 @@
updateStatus('Test mode enabled via controls', 'info');
}
// Move in the specified direction
// Move in the specified direction, accounting for map rotation
// Get current map bearing (0 = north up, 90 = east up, etc.)
const mapBearing = map.getBearing();
// Calculate movement bearing based on key pressed
// W = forward (map bearing), D = right (+90), S = back (+180), A = left (+270)
let moveBearing;
switch (dir) {
case 'w':
testPosition.lat += GPS_TEST_STEP;
moveBearing = mapBearing; // Forward (top of screen)
break;
case 'd':
moveBearing = mapBearing + 90; // Right
break;
case 's':
testPosition.lat -= GPS_TEST_STEP;
moveBearing = mapBearing + 180; // Backward (bottom of screen)
break;
case 'a':
testPosition.lng -= GPS_TEST_STEP;
break;
case 'd':
testPosition.lng += GPS_TEST_STEP;
moveBearing = mapBearing + 270; // Left
break;
}
// Normalize bearing to 0-360
moveBearing = ((moveBearing % 360) + 360) % 360;
// Use destinationPoint to calculate new position
// GPS_TEST_STEP is in degrees, convert to approximate meters (1 degree ≈ 111000m)
const stepMeters = GPS_TEST_STEP * 111000;
const currentLngLat = [testPosition.lng, testPosition.lat];
const newLngLat = destinationPoint(currentLngLat, stepMeters, moveBearing);
testPosition.lat = newLngLat[1];
testPosition.lng = newLngLat[0];
simulateGpsPosition();
};

Loading…
Cancel
Save