Add Amtrak routes layer
This commit is contained in:
parent
010f28e6d9
commit
efe4b7cd92
8
layers/amtrak/README.md
Normal file
8
layers/amtrak/README.md
Normal 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
|
3
layers/amtrak/get_data.sh
Executable file
3
layers/amtrak/get_data.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
curl --silent --output amtrak-data.geojson https://maps.amtrak.com/services/MapDataService/stations/nationalRoute
|
26
layers/amtrak/layer.js
Normal file
26
layers/amtrak/layer.js
Normal 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 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;
|
4
main.js
4
main.js
|
@ -4,6 +4,8 @@ import TileLayer from 'ol/layer/Tile';
|
||||||
import OSM from 'ol/source/OSM';
|
import OSM from 'ol/source/OSM';
|
||||||
import {fromLonLat} from 'ol/proj.js';
|
import {fromLonLat} from 'ol/proj.js';
|
||||||
|
|
||||||
|
import amtrakLayer from './layers/amtrak/layer.js';
|
||||||
|
|
||||||
const map = new Map({
|
const map = new Map({
|
||||||
target: 'map',
|
target: 'map',
|
||||||
layers: [
|
layers: [
|
||||||
|
@ -16,3 +18,5 @@ const map = new Map({
|
||||||
zoom: 10,
|
zoom: 10,
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
map.addLayer(amtrakLayer);
|
||||||
|
|
Loading…
Reference in a new issue