maps.chandlerswift.com/layers/amtrak/layer.js

27 lines
802 B
JavaScript
Raw Normal View History

2023-07-03 15:27:18 -05:00
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;