Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgilbers committed Sep 26, 2024
1 parent 0a38f97 commit 0c83e24
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,17 @@ function requestSensors () {
}
}

/**
* Hande the device motion
* @param {DeviceMotionEvent} event
*/
function handleMotion (event) {
if (motionArray.length >= motionArrayLength) {
motionArray.shift()
}
motionArray.push([event.acceleration.x, event.acceleration.y, event.acceleration.z])
}

/**
* Hande the device orientation
* @param {DeviceOrientationEvent} event
Expand All @@ -399,17 +410,6 @@ function handleOrientation (event) {
}
}

/**
* Hande the device motion
* @param {DeviceMotionEvent} event
*/
function handleMotion (event) {
if (motionArray.length >= motionArrayLength) {
motionArray.shift()
}
motionArray.push([event.acceleration.x, event.acceleration.y, event.acceleration.z])
}

function endOfMapMovement (e) {
if (typeof compassSymbol !== 'undefined') {
const mapCenter = map.getCenter()
Expand Down Expand Up @@ -448,16 +448,16 @@ window.toggleCompass = () => {
}

function activateCompass () {
window.addEventListener('deviceorientation', handleOrientation)
window.addEventListener('devicemotion', handleMotion)
window.addEventListener('deviceorientation', handleOrientation)
map.touchRotate.disable()
compassSymbol.innerHTML = 'explore'
compass = true
}

function deactivateCompass () {
window.removeEventListener('deviceorientation', handleOrientation)
window.removeEventListener('devicemotion', handleMotion)
window.removeEventListener('deviceorientation', handleOrientation)
map.touchRotate.enable()
compassSymbol.innerHTML = 'near_me'
compass = false
Expand Down

0 comments on commit 0c83e24

Please sign in to comment.