diff --git a/index.html b/index.html
index aff01fe..09542db 100644
--- a/index.html
+++ b/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();
};