-
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.
Merge pull request #36 from sidetrackedmind/try-pyodide-version
Merge beta game
- Loading branch information
Showing
7 changed files
with
565 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
function decodePolyline(encoded) { | ||
const len = encoded.length; | ||
let index = 0; | ||
let lat = 0; | ||
let lng = 0; | ||
const decoded = []; | ||
|
||
while (index < len) { | ||
let b; | ||
let shift = 0; | ||
let result = 0; | ||
|
||
do { | ||
b = encoded.charCodeAt(index++) - 63; | ||
result |= (b & 0x1f) << shift; | ||
shift += 5; | ||
} while (b >= 0x20); | ||
|
||
const dlat = ((result & 1) ? ~(result >> 1) : (result >> 1)); | ||
lat += dlat; | ||
|
||
shift = 0; | ||
result = 0; | ||
|
||
do { | ||
b = encoded.charCodeAt(index++) - 63; | ||
result |= (b & 0x1f) << shift; | ||
shift += 5; | ||
} while (b >= 0x20); | ||
|
||
const dlng = ((result & 1) ? ~(result >> 1) : (result >> 1)); | ||
lng += dlng; | ||
|
||
decoded.push([lat / 1e5, lng / 1e5]); | ||
} | ||
|
||
return decoded; | ||
} | ||
|
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,26 @@ | ||
// Description: This file contains the function to get nearby routes from the Trimet API. | ||
|
||
function getNearbyRoutes(fromPlace) { | ||
// fromPlace is a string with the format "lat,lon" | ||
const baseUrl = "https://developer.trimet.org/ws/v1/stops"; | ||
|
||
const params = new URLSearchParams({ | ||
json: true, | ||
appId: "8CBD14D520C6026CC7EEE56A9", | ||
showRoutes: true, | ||
meters: 1200, | ||
ll: fromPlace | ||
}); | ||
const routeNumbers = new Set(); | ||
var xhReq = new XMLHttpRequest(); | ||
xhReq.open("GET", `${baseUrl}?${params}`, false); | ||
xhReq.send(null); | ||
var raw_response = JSON.parse(xhReq.responseText); | ||
raw_response.resultSet.location.forEach(loc => { | ||
loc.route.forEach(route => { | ||
routeNumbers.add(route.route); | ||
// console.log(route.route); | ||
}); | ||
}); | ||
return routeNumbers; | ||
} |
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,37 @@ | ||
// Description: This script is used to get the trip plan from Trimet API. | ||
|
||
function getTrimetPlan(fromPlace, toPlace, maxWalkDistance = 1200, walkSpeed = 1.7, numItineraries = 1) { | ||
const baseUrl = "https://maps.trimet.org/otp_mod/plan"; | ||
|
||
// 805 meters = 1/2 mile. 1.7 m/s | ||
|
||
const now = new Date(); | ||
|
||
const year = now.getFullYear(); | ||
const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed | ||
const day = String(now.getDate()).padStart(2, '0'); | ||
|
||
const hours = String(now.getHours()).padStart(2, '0'); | ||
const minutes = String(now.getMinutes()).padStart(2, '0'); | ||
|
||
const date = `${year}-${month}-${day}`; | ||
const time = `${hours}:${minutes}`; | ||
|
||
const params = new URLSearchParams({ | ||
fromPlace, | ||
toPlace, | ||
date, | ||
time, | ||
mode: "WALK,BUS,TRAM,RAIL,GONDOLA", | ||
maxWalkDistance, | ||
walkSpeed, | ||
numItineraries, | ||
}); | ||
|
||
var xhReq = new XMLHttpRequest(); | ||
xhReq.open("GET", `${baseUrl}?${params}`, false); | ||
xhReq.send(null); | ||
var raw_response = JSON.parse(xhReq.responseText); | ||
return raw_response; | ||
|
||
} |
Oops, something went wrong.