From efe4b7cd92780a38e6231c249bb894ef64561dab Mon Sep 17 00:00:00 2001 From: Chandler Swift Date: Mon, 3 Jul 2023 15:27:18 -0500 Subject: [PATCH] Add Amtrak routes layer --- layers/amtrak/README.md | 8 ++++++++ layers/amtrak/get_data.sh | 3 +++ layers/amtrak/layer.js | 26 ++++++++++++++++++++++++++ main.js | 4 ++++ 4 files changed, 41 insertions(+) create mode 100644 layers/amtrak/README.md create mode 100755 layers/amtrak/get_data.sh create mode 100644 layers/amtrak/layer.js diff --git a/layers/amtrak/README.md b/layers/amtrak/README.md new file mode 100644 index 0000000..e941eab --- /dev/null +++ b/layers/amtrak/README.md @@ -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 diff --git a/layers/amtrak/get_data.sh b/layers/amtrak/get_data.sh new file mode 100755 index 0000000..b905eab --- /dev/null +++ b/layers/amtrak/get_data.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +curl --silent --output amtrak-data.geojson https://maps.amtrak.com/services/MapDataService/stations/nationalRoute diff --git a/layers/amtrak/layer.js b/layers/amtrak/layer.js new file mode 100644 index 0000000..20cdfa7 --- /dev/null +++ b/layers/amtrak/layer.js @@ -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 amtrakURL from '/data/amtrak-data.geojson?url'; // TODO: remove `?url`? + +const amtrak_colors = '0,83,126'; // from their website's cookie banner, and other places + +const vectorLayer = new VectorLayer({ + source: new VectorSource({ + url: amtrakURL, + format: new GeoJSON, + }), + style: function(feature, resolution){ + return new Style({ + stroke: new Stroke({ + color: `rgba(${amtrak_colors},${Math.min(1, Math.pow(resolution/10, 1/4))})`, + width: 10/Math.pow(resolution, 1/4), + }) + }); + }, +}); + +export default vectorLayer; diff --git a/main.js b/main.js index 0f8fb94..d1e15c9 100644 --- a/main.js +++ b/main.js @@ -4,6 +4,8 @@ import TileLayer from 'ol/layer/Tile'; import OSM from 'ol/source/OSM'; import {fromLonLat} from 'ol/proj.js'; +import amtrakLayer from './layers/amtrak/layer.js'; + const map = new Map({ target: 'map', layers: [ @@ -16,3 +18,5 @@ const map = new Map({ zoom: 10, }) }); + +map.addLayer(amtrakLayer);