Skip to content

Commit

Permalink
feat: using arrow keys and WASD to navigate
Browse files Browse the repository at this point in the history
  • Loading branch information
mertturunc committed Jan 17, 2025
1 parent 5b7fea8 commit 195592c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions TeletextMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,50 @@ const TeletextMap: React.FC = () => {
getMapImage()
}, [getMapImage])

// Add keyboard navigation handler
useEffect(() => {
const handleKeyPress = (e: KeyboardEvent) => {
const moveAmount = 0.01 // Adjust this value to change movement speed

switch(e.key.toLowerCase()) {
// Arrow keys and WASD
case 'arrowup':
case 'w':
setPosition(prev => ({ ...prev, lat: prev.lat + moveAmount }))
break
case 'arrowdown':
case 's':
setPosition(prev => ({ ...prev, lat: prev.lat - moveAmount }))
break
case 'arrowleft':
case 'a':
setPosition(prev => ({ ...prev, lng: prev.lng - moveAmount }))
break
case 'arrowright':
case 'd':
setPosition(prev => ({ ...prev, lng: prev.lng + moveAmount }))
break
// Zoom controls
case '+':
case '=':
setPosition(prev => ({ ...prev, zoom: Math.min(prev.zoom + 0.5, 20) }))
break
case '-':
case '_':
setPosition(prev => ({ ...prev, zoom: Math.max(prev.zoom - 0.5, 1) }))
break
}
}

// Add event listener
window.addEventListener('keydown', handleKeyPress)

// Cleanup
return () => {
window.removeEventListener('keydown', handleKeyPress)
}
}, []) // Empty dependency array since we don't use any external values

const moveMap = (dlat: number, dlng: number) => {
setPosition(prev => ({
...prev,
Expand Down

0 comments on commit 195592c

Please sign in to comment.