-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a19f48
commit 94402b1
Showing
5 changed files
with
63 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
export function checkAll() { | ||
checkNotificationPermission(); | ||
checkLocationPermission(); | ||
} | ||
|
||
function checkNotificationPermission() { | ||
const notificationStatus = document.getElementById('notification'); | ||
|
||
if (Notification.permission === 'granted') { | ||
notificationStatus.innerHTML = `<span class="success">Notifications ✅</span>`; | ||
} else if (Notification.permission === 'denied') { | ||
notificationStatus.innerHTML = `<span class="failure">Notifications ⛔</span>`; | ||
} else { | ||
notificationStatus.innerHTML = `<span class="failure">Notifications❓</span>`; | ||
} | ||
} | ||
|
||
function checkLocationPermission() { | ||
const locationText = document.getElementById('location'); | ||
|
||
if ('geolocation' in navigator) { | ||
navigator.geolocation.getCurrentPosition( | ||
() => { | ||
locationText.innerHTML = `<span class="success">Location ✅</span>`; | ||
}, e => { | ||
if (e.code === e.PERMISSION_DENIED) { | ||
locationText.innerHTML = `<span class="failure">Location ⛔</span>`; | ||
} else if (e.code === e.TIMEOUT) { | ||
locationText.innerHTML = `<span class="failure">Location ⏳</span>`; | ||
} else { | ||
locationText.innerHTML = `<span class="failure">Location ❓</span>`; | ||
} | ||
}, { | ||
timeout: 5 * 1000 | ||
} | ||
); | ||
} else { | ||
locationText.innerHTML = `<span class="failure">Location ❌</span>`; | ||
} | ||
} | ||
|
||
checkAll(); | ||
|
||
document.getElementById('enabler').addEventListener('click', () => { | ||
checkAll(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
<link rel="manifest" href="manifest.json"> | ||
<link rel="stylesheet" href="./css/style.css"> | ||
<script src="main.js" type="module" defer></script> | ||
<script src="./js/checker.js" defer></script> | ||
<script src="./js/modal.js" defer></script> | ||
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" /> | ||
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script> | ||
|
@@ -15,7 +16,7 @@ | |
<script>0</script> | ||
<header> | ||
<h1>Soteria</h1> | ||
<a href="#" id="enabler"><span id="refresher">↻ </span><span id="location">Location... </span><span id="notification">Notification... </span></a> | ||
<a href="#" id="enabler"><span id="refresher">↻</span> | <span id="location">Location...</span> | <span id="notification">Notification...</span></a> | ||
<h2 style="margin: 0;"> | ||
<div class="map-link"> | ||
<a href="./index.html">Return to floormap...</a> | ||
|
@@ -26,6 +27,7 @@ <h2 style="margin: 0;"> | |
Local map is recommended if you are unfamiliar with the building or are just in the surrounding area. If you are able to, it is highly encouraged to use the floormap.<br><br> | ||
Permissions key:<br> | ||
✅ - Success<br> | ||
⏳ - Timed out<br> | ||
❓ - Failed to retrieve<br> | ||
⛔ - Access to service denied<br> | ||
❌ - Not supported by your browser | ||
|
@@ -37,9 +39,6 @@ <h2 style="margin: 0;"> | |
<div id="map"></div> | ||
<a style="height: 4.5vh"></a> | ||
<script type="module"> | ||
import {checkNotificationPermission} from "./main.js"; | ||
checkNotificationPermission(); | ||
|
||
import { requestLocationPermission } from "./js/location.js"; | ||
// TODO: change to real | ||
const threat_x = 39.15294936019142; | ||
|
@@ -66,15 +65,14 @@ <h2 style="margin: 0;"> | |
map = L.map('map').setView([threat_x, threat_y], 14); | ||
} else { | ||
// TODO: change when done with demo code | ||
user_x = 39.149978876760755; | ||
user_y = -77.2059241960242; | ||
// user_x = 39.149978876760755; | ||
// user_y = -77.2059241960242; | ||
const midpoint_x = (user_x + threat_x) / 2; | ||
const midpoint_y = (user_y + threat_y) / 2; | ||
const d = Math.sqrt(Math.pow(user_x - threat_x, 2) + Math.pow(user_y - threat_y, 2)); | ||
const zoom = 73769.37975 / d * Math.exp(-4667.97275 * d) | ||
+ 11.83199 * Math.exp(-0.08104 * d); // https://julius.ai/s/84c7b6a6-35e9-4d5b-9661-41660ff7f2a1 | ||
map = L.map('map').setView([midpoint_x, midpoint_y], zoom); | ||
console.log(d, zoom); | ||
|
||
const userMarker = L.marker([user_x, user_y], {icon: bluePin}).addTo(map); | ||
userMarker.bindPopup('<b>Current Location</b>'); | ||
|