Skip to content

Commit

Permalink
WIP also (iOs s**t)
Browse files Browse the repository at this point in the history
  • Loading branch information
pakb committed Jun 26, 2024
1 parent b64b05f commit dffa454
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/modules/map/components/openlayers/CompassButton.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
<script setup>
import { onMounted, onUnmounted, ref } from 'vue'
import { ref } from 'vue'
import { useStore } from 'vuex'
const autoRotate = ref(false)
const store = useStore()
onMounted(() => {
window.addEventListener('deviceorientation', handleOrientation)
})
onUnmounted(() => {
window.removeEventListener('deviceorientation', handleOrientation)
})
function handleOrientation(event) {
console.error(autoRotate.value, event.alpha, (event.alpha / 180) * Math.PI)
if (autoRotate.value) {
Expand All @@ -21,6 +14,17 @@ function handleOrientation(event) {
function rotate() {
autoRotate.value = !autoRotate.value
if (autoRotate.value) {
if (typeof DeviceMotionEvent.requestPermission === 'function') {
DeviceMotionEvent.requestPermission().then(() => {
window.addEventListener('deviceorientation', handleOrientation)
})
} else {
window.addEventListener('deviceorientation', handleOrientation)
}
} else {
window.removeEventListener('deviceorientation', handleOrientation)
}
}
</script>

Expand Down

0 comments on commit dffa454

Please sign in to comment.