Add amtrak train live location layer

This commit is contained in:
Chandler Swift 2024-02-03 00:28:31 -06:00
parent fb667871b4
commit 0065c7f4f5
Signed by: chandlerswift
GPG key ID: A851D929D52FB93F
6 changed files with 68 additions and 2 deletions

View file

@ -0,0 +1,8 @@
curl 'https://maps.amtrak.com/rttl/js/RoutesList.json?dataType=json&contentType=application%2Fjson&crossDomain=true&cache=false' --compressed -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'Origin: https://www.amtrak.com' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Referer: https://www.amtrak.com/' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-site' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache'
curl 'https://maps.amtrak.com/services/MapDataService/stations/nationalRoute?routeName=' --compressed -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'Origin: https://www.amtrak.com' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Referer: https://www.amtrak.com/' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-site' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache'
view-source:https://maps.amtrak.com/rttl/js/_$$_666.js
view-source:https://maps.amtrak.com/rttl/js/mapApplication.js
view-source:https://www.amtrak.com/services/maps.trainlocation.html
https://www.amtrak.com/services/maps.trainlocation.html

View file

@ -0,0 +1,3 @@
#!/bin/sh
curl --silent --output data.geojson https://maps.amtrak.com/services/MapDataService/stations/nationalRoute

View file

@ -0,0 +1,26 @@
import VectorLayer from 'ol/layer/Vector';
import {Vector as VectorSource} from 'ol/source.js';
import GeoJSON from 'ol/format/GeoJSON.js';
import {Style, Stroke} from 'ol/style.js';
import url from './data.geojson?url'; // TODO: remove `?url`?
const colors = '0,83,126'; // from their website's cookie banner, and other places
const vectorLayer = new VectorLayer({
source: new VectorSource({
url: url,
format: new GeoJSON,
}),
style: function(feature, resolution){
return new Style({
stroke: new Stroke({
color: `rgba(${colors},${Math.min(1, Math.pow(resolution/10, 1/4))})`,
width: 10/Math.pow(resolution, 1/4),
})
});
},
});
export default vectorLayer;