Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…cape-web-client into currentroad
  • Loading branch information
steinbro committed May 5, 2024
2 parents 4ae6b19 + 59d6069 commit cb8c518
Show file tree
Hide file tree
Showing 9 changed files with 3,035 additions and 1,384 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
27 changes: 27 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Node.js CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
env/
node_modules/
TODO.md
37 changes: 37 additions & 0 deletions app/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ document.addEventListener('DOMContentLoaded', function () {
var btnNearMe = document.getElementById('btn_near_me');
var watchPositionHandler = null;
var activeMode = null;
var wakeLock = null;
const selectedColor = '#18b3c3';
const unselectedColor = '#e74c3c';
// When mode button is clicked:
Expand Down Expand Up @@ -107,12 +108,39 @@ document.addEventListener('DOMContentLoaded', function () {
// Stop here if the intent was to end the current mode
if (activeMode == newMode) {
activeMode = null;

if (wakeLock) {
// Release the Wake Lock
wakeLock.release().then(() => {
wakeLock = null;
});
}

return;
}

// Button clicked was different from current mode -- start new mode
activeMode = newMode;

// Request a Wake Lock
if ("wakeLock" in navigator && !wakeLock){
try {
wakeLock = await navigator.wakeLock.request("screen");
console.log("Wake Lock is active!");

// Listen for Wake Lock being released
// (when no active modes OR when page loses focus)
wakeLock.addEventListener('release', () => {
console.log('Wake Lock released.');
});

} catch (err) {
// The Wake Lock request has failed - usually system related, such as battery.
console.log(err);
}
}


// play mode-enter sound
audioQueue.addToQueue({ soundUrl: 'app/sounds/mode_enter.wav' });

Expand Down Expand Up @@ -167,4 +195,13 @@ document.addEventListener('DOMContentLoaded', function () {
btnNearMe.addEventListener('click', function() {
toggleMode('near_me');
});

// Reacquire Wake Lock when page regains focus
document.addEventListener("visibilitychange", async () => {
if (wakeLock !== null && document.visibilityState === "visible") {
wakeLock = await navigator.wakeLock.request("screen");
console.log("Wake Lock reacquired.")
}
});

});
4 changes: 2 additions & 2 deletions app/js/spatial/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export function createBoundingBox(latitude, longitude, radiusMeters) {

// Extract the bounding box coordinates
const bbox = turf.bbox(buffered);

return bbox;
}

// Function to convert latitude and longitude to Mercator tile coordinates
function latLonToTileCoords(latitude, longitude, zoom) {
export function latLonToTileCoords(latitude, longitude, zoom) {
const tileSize = 256; // Standard size for Mercator tiles
const scale = 1 << zoom;
const worldSize = tileSize * scale;
Expand Down
Loading

0 comments on commit cb8c518

Please sign in to comment.